Matlines无效,为什么?线性回归

时间:2019-06-19 00:10:08

标签: r graph linear-regression

我必须为线性回归和价值产生置信度。

我使用abline绘制回归线,但不幸的是,matline应当绘制置信度走廊并没有这样做。为什么?

model_temp=lm(value~temp,data=Data)
data_X = seq(min(value), max(value),by=((max(value)-min(value)))/(length(value) - 1))

interval_regression= predict(model_temp, newdata = data.frame(value = data_X), interval = "confidence", level = 0.95)
interval_value = predict(model_temp, newdata = data.frame(value = data_X), interval = "prediction", level = 0.95)


plot(temp, value,xlab="Temp", ylab="Value", main="Model 1") 

abline(model_temp,col="black") 

matlines(interval_regression, col="red")
matlines(data_X, interval_value,col="green")


> print(temp)
 [1] 14 28 19 14 19 16 10 11 22 17 17 18 19 11 21 28 25 22 26 16 25 21 20 27 23 20 18 20 27 18 18 16
[33] 18 18 18 22 22 24 16 23 20 16 23 22 18 19 16 23 16 18 24
> print(model_temp)

Call:
lm(formula =  value~ temp, data = Data)

Coefficients:
(Intercept)  temp
    0.01406      0.21914  

> print(value)
 [1] 3.5 5.9 4.0 2.9 3.5 3.5 2.2 1.6 4.6 4.3 4.1 4.3 4.2 2.9 4.7 5.9 6.1 5.3 5.4 3.5 5.9 4.1 4.4 5.6
[25] 6.0 4.9 5.2 3.7 6.6 3.0 4.0 3.4 3.8 4.0 3.8 5.0 4.1 4.6 3.1 5.2 4.4 3.6 5.2 4.6 3.8 5.0 3.7 4.6
[49] 3.5 3.8 5.3
> dput(head(data_X))
c(1.6, 1.7, 1.8, 1.9, 2, 2.1)

0 个答案:

没有答案