我试图根据两个观察结果做一个简单的回归:
> x=c(1,2)
> y=c(3,5)
> fit <- lm(y ~ x)
> Prediction <- predict(fit, newdata=c(3,4))
Error in eval(predvars, data, env) :
numeric 'envir' arg not of length one
> summary(fit)
Call:
lm(formula = y ~ x)
Residuals:
ALL 2 residuals are 0: no residual degrees of freedom!
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 1 NA NA NA
x 2 NA NA NA
Residual standard error: NaN on 0 degrees of freedom
Multiple R-squared: 1, Adjusted R-squared: NaN
F-statistic: NaN on 1 and 0 DF, p-value: NA
我知道我不应该在我的模型中得到任何残差,但为什么我不能预测x的未来值?
答案 0 :(得分:2)
我认为newdata需要采用list()
形式。
predict(fit, newdata=list(x=c(3,4)))