[英]Linear regression of 2 observations in R
我正在嘗試基於兩個觀察結果進行簡單的回歸:
> 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的未來值?
我認為newdata必須采用list()
形式。
predict(fit, newdata=list(x=c(3,4)))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.