Tuesday, November 29, 2011

R Confidence Intervals and Regions in a linear model

  • for a linear model: \( mm = \beta_0 + \beta_1 x_1 + \beta_2 x_2 + ... + \beta_n x_n \) you can get the confidence intervals of the parameters \( \beta_0 ... \beta_n \)
data(trees)                  ## load the data
mm <- with(trees, lm(Volume ~ Girth + Height)) ## linear model
confint(mm)                  ## get the confidence intervals
2.5 %      97.5 %
(Intercept) -75.68226247 -40.2930554
Girth         4.16683899   5.2494820
Height        0.07264863   0.6058538
[1] "org_babel_R_eoe"
  • the package ellipse provides a command to construct a 2-dimensional confidence region, here we will compute the ellipse for Girth and Height
library(ellipse)
plot(ellipse(mm,c(2,3)),type="l",xlim=c(0,5.5))
points(0,0)
points(coef(mm)[ 2],coef(mm)[ 3],pch=18)
abline(v=confint(mm)[2,],lty=2)
abline(h=confint(mm)[3,],lty=2)


  • we see: (0,0) lies outside the ellipse so we can reject \( H_0 \)
  • the two abline commands produce the lines indicating the one-way confidence intervals, if they were tangential to the ellipse, the CIs would be jointly correct

No comments :

Post a Comment