使用R进行线性预测:如何访问预测参数? [英] Doing linear prediction with R: How to access the predicted parameter(s)?
本文介绍了使用R进行线性预测:如何访问预测参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是R
的新手,我正在尝试进行线性预测.这是一些简单的数据:
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))
说我是否要预测year=12
的值.这就是我正在做的(使用不同的命令进行实验):
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
一些查询:
-
例如,如果我发出命令
lma$coefficients
,则会向我返回两个值的向量.如何只选择截距值?
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?
使用predict.lm(lma, newyear)
可以获得很多输出,但是无法理解预测值在哪里.有人可以澄清一下吗?
I get lots of output with predict.lm(lma, newyear)
but cannot understand where the predicted value is. Can someone please clarify?
非常感谢...
推荐答案
拦截:
lma$coefficients[1]
预测,试试这个:
test.frame <- data.frame(year=12, value=0)
predict.lm(lma, test.frame)
这篇关于使用R进行线性预测:如何访问预测参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文