使用 R 进行线性预测:如何访问预测参数?
我是 R
的新手,我正在尝试进行线性预测。以下是一些简单的数据:
test.frame<-data.frame(year=8:11, value= c(12050,15292,23907,33991))
假设我想预测 year=12
的值。这就是我正在做的事情(使用不同的命令进行实验):
lma=lm(test.frame$value~test.frame$year) # let's get a linear fit
summary(lma) # let's see some parameters
attributes(lma) # let's see what parameters we can call
lma$coefficients # I get the intercept and gradient
predict(lm(test.frame$value~test.frame$year))
newyear <- 12 # new value for year
predict.lm(lma, newyear) # predicted value for the new year
一些查询:
例如,如果我发出命令
lma$coefficients
,则会将两个值的向量返回给我。如何仅选择截距值?我使用
predict.lm(lma, newyear)
获得大量输出,但无法理解预测值在哪里。有人可以澄清一下吗?
多谢...
I am new to R
and I am trying to do linear prediction. Here is some simple data:
test.frame<-data.frame(year=8:11, value= c(12050,15292,23907,33991))
Say if I want to predict the value for year=12
. This is what I am doing (experimenting with different commands):
lma=lm(test.frame$value~test.frame$year) # let's get a linear fit
summary(lma) # let's see some parameters
attributes(lma) # let's see what parameters we can call
lma$coefficients # I get the intercept and gradient
predict(lm(test.frame$value~test.frame$year))
newyear <- 12 # new value for year
predict.lm(lma, newyear) # predicted value for the new year
Some queries:
if I issue the command
lma$coefficients
for instance, a vector of two values is returned to me. How to pick only the intercept value?I get lots of output with
predict.lm(lma, newyear)
but cannot understand where the predicted value is. Can someone please clarify?
Thanks a lot...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
拦截:
预测,试试这个:
intercept:
Predict, try this: