[R] plotting confidence intervals

Jim Lemon jim at bitwrit.com.au
Wed Jul 15 12:36:03 CEST 2009


Erin Hodgess wrote:
> Hi R People:
>
> If I have a fitted values from a model, how do I plot the
> (1-alpha)100% confidence intervals along with the fitted values,
> please?
>
> Also, if the intervals are "shaded" gray, that would be nice too, please?
>
> I check confint, but that doesn't seem to do what I want.
>
>   
Hi Erin,
Probably the simplest way is to plot points with "error bars" as in the 
following example:

coefficients<-rnorm(5)+4
plot(coefficients,main="Coefficient 
plot",xaxt="n",ylim=c(0,6),xlab="Coefficients")
axis(1,at=1:5,labels=paste("Coef",1:5,sep=""))
dispersion(1:5,coefficients,abs(rnorm(5)),col="lightgray")

The dispersion function in the plotrix package is just one way to 
illustrate confidence intervals.

Jim




More information about the R-help mailing list