d-max
d-max

Reputation: 177

linear regression predictions with confidence interval plot in R

Say example data

library("robustbase")
data(education)

I create regression model

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

Now i need get plot where predicted values with confidence interval. I.e., I want such plot: enter image description here

How can I create it?

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

It is not needed for me result.

Upvotes: 2

Views: 1612

Answers (1)

UseR10085
UseR10085

Reputation: 8136

You can use lattice package with mosaic package for that, like

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

Upvotes: 1

Related Questions