簡體   English   中英

R 中的置信區間 plot 的線性回歸預測

[英]linear regression predictions with confidence interval plot in R

說示例數據

library("robustbase")
data(education)

我創建回歸 model

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

現在我需要得到 plot 預測值與置信區間。 即,我想要這樣的 plot: 在此處輸入圖像描述

我怎樣才能創建它?

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

我不需要結果。

您可以使用lattice package 和mosaic package ,例如

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))

在此處輸入圖像描述

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM