从数据/系数创建 lm 对象
有谁知道可以在给定数据集和系数的情况下创建 lm 对象的函数?
我对此很感兴趣,因为我开始使用贝叶斯模型平均 (BMA),并且我希望能够根据 bicreg 的结果创建 lm 对象。我想访问所有不错的通用 lm 函数,例如诊断绘图、预测、cv.lm 等。
如果您非常确定这样的函数不存在,那么了解这一点也非常有帮助!
library(BMA)
mtcars_y <- mtcars[, 1] #mpg
mtcars_x <- as.matrix(mtcars[,-1])
res <- bicreg(mtcars_x, mtcars_y)
summary(res)
res$postmean # bma coefficients
# The approximate form of the function
# I'm looking for
lmObject <- magicFunction(data=mtcars, coefficients=res$postmean)
Does anyone know of a function that can create an lm object given a dataset and coefficients?
I'm interested in this because I started playing with Bayesian model averaging (BMA) and I'd like to be able to create an lm object out of the results of bicreg. I'd like to have access to all of the nice generic lm functions like diagnostic plotting, predict, cv.lm etc.
If you are pretty sure such a function doesn't exist that's also very helpful to know!
library(BMA)
mtcars_y <- mtcars[, 1] #mpg
mtcars_x <- as.matrix(mtcars[,-1])
res <- bicreg(mtcars_x, mtcars_y)
summary(res)
res$postmean # bma coefficients
# The approximate form of the function
# I'm looking for
lmObject <- magicFunction(data=mtcars, coefficients=res$postmean)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
据我所知,没有任何函数可以做到这一点。当然可以制作一个。 magicFunction 需要做的就是创建一个包含元素的列表:
然后将其设为 lm 对象
让我说一下,我认为这是一个坏主意。谁说您应用的通用函数将适用于 bicreg 对象。例如,您如何解释 AIC(fakeModel)?
您最好创建自己的函数来进行诊断和预测。
There is no function that I am aware of that does this. One could of course be made. All that your magicFunction would need to do is create a list with elements:
then make it an lm object
Let me just say that I think that this is a bad idea though. Whose to say that the generic function that you apply will be applicable to a bicreg object. For example, how would you interpret AIC(fakeModel)?
You are better off creating your own functions to do diagnostics and prediction.
看来您可以像往常一样计算
lm
对象,然后通过修改lm()
结果的$coefficients
属性来修改系数。有关更多详细信息,请参阅此问题和结果:
http:// /tolstoy.newcastle.edu.au/R/e2/help/07/08/24294.html
不确定它是否符合你想要做的事情,但......
It seems you can compute your
lm
object as usual, and then modify the coefficients afterwards by modifying the$coefficients
attribute of yourlm()
result.See this question and results for more details :
http://tolstoy.newcastle.edu.au/R/e2/help/07/08/24294.html
Not sure it corresponds to what you want to do, though...