R中具有置信区间图的线性回归预测

时间:2019-11-06 09:57:33

标签: r

说示例数据

library("robustbase")
data(education)

我创建回归模型

model=lm(Y~X1+X2+X3,data=education)

现在我需要得到带有置信区间的预测值的图。 即,我想要这样的情节: enter image description here

如何创建它?

model=lm(Y~X1+X2+X3,data=education)
plot(model, which = 1)

我的结果不需要。

1 个答案:

答案 0 :(得分:1)

您可以将lattice软件包与mosaic软件包一起使用,例如

library("lattice")
library(mosaic)
library(robustbase)

data(education)
mylm=lm(Y~X1+X2+X3,data=education)
pred <- predict(mylm, data=education)
df <- data.frame(Observed=education$Y, Predicted=pred)

xyplot(Predicted ~ Observed, data = df, pch = 19,  panel=panel.lmbands,
                  band.lty = c(conf =2, pred = 1))

enter image description here