1

So i'm trying to find the 95% confidence band for the regression line when Xh=28, but I'm not sure how to get it work in R. the X represent ACT score and Y represent GPA. here's my script so far

attach(GPA1)
plot(GPA ~ ACT,
 xlab="ACT scores", ylab="GPA",
 main="GPA vs. ACT scores")
abline(score$coef,col="red")
score<-lm(GPA~ACT)
GPA.clim <- predict(score, new<-data.frame(ACT=28),se.fit=TRUE,interval="confidence")
GPA.clim
GPA.clim<-predict(score,interval="confidence")
GPA.clim
GPA.plim<-predict(score,interval="predict")

GPA plim

I'm not sure how to use a metline in this case for both the prediction band and confidence band at x=28.

april510
  • 21
  • 2
  • 3
  • 1
    **What result do you get with what you've tried?** You haven't supplied any data, so your calls to print aren't informative to the reader. – alexwhitworth Oct 09 '15 at 16:40
  • Is this link of any use to you, http://stackoverflow.com/questions/15180008/how-to-calculate-the-95-confidence-interval-for-the-slope-in-a-linear-regressio ? – DarrenRhodes Oct 09 '15 at 16:56

1 Answers1

0
    #Here is some code for it to work
    #first create a data frame with the only value being a act score of 28              
    #and name it act28, and in this case gpafit is lm(GPA ~ ACT). 

You have to make sure to calculate W values which are twice the f-distribution and square root it

    ci.wh <- function(gpafit, act28, alpha = 0.05)
    {
    df    <- 118
    W     <- sqrt( 2 * qf(1 - alpha, 2, df) )                #2.43
    ci    <- predict(gpafit, act28, se.fit = TRUE)   
    x <- cbind(
   'x'   = act28,
   's'   = ci$se.fit,
   '  fit' = ci$fit,
   'lwr' = ci$fit - W * ci$se.fit,
   'upr' = ci$fit + W * ci$se.fit)

   return(x)
  }
       ci.wh(gpafit, act28, alpha=0.05)
Maxwell Chandler
  • 626
  • 8
  • 18