Skip to content
Prev 174817 / 398506 Next

confidence interval or error of x intercept of a linear

I wanted to send out a quick thanks to all that replied to my query about estimating the confidence interval around the x-intercept of a linear regression.  The method I was able to implement in the most straightforward way was taken from Section 3.2 of Draper and Smith (1998). Applied Regression Analysis. The code follows - its not the most fancy code, but it gets the job done.  I will see if I can work out the other suggestions that were made and see how they all turn out.  

xInterceptCI <- function(x, alpha = 0.05, ...) {
  intercept <- coef(x)[1]              
  slope <- coef(x)[2]                  
  meanX <- mean(x$model[,2])           
  n <- length(x$model[,2])             
  tstar <- qt(alpha/2, n-2)            
  sxx <- sum(x$model[,2]^2) - sum(x$model[,2])^2 / n
  SSresidual <- (1-cor(x$model[,1], x$model[,2])^2) * 
                (sum(x$model[,1]^2)-sum(x$model[,1])^2/n)
  S <- sqrt(SSresidual/(n-2))
  SEslope <- S / sqrt(sxx)
  Xintercept <- - intercept / slope
  y0 <- 0
  g <- (tstar / (slope/SEslope))^2
  left <- (Xintercept - meanX) * g
  bottom <- 1 - g
  Right <- (tstar * S / slope) * sqrt( ((Xintercept - meanX)^2/sxx) + bottom/n)
  lower <- Xintercept + (left + Right) / bottom
  upper <- Xintercept + (left - Right) / bottom
  return(c(lower,upper))
}
On Tue, 24 Mar 2009 17:16:41 +0100, Peter Dalgaard <P.Dalgaard at biostat.ku.dk> wrote:
--
==========
==========
Kevin J Emerson
Bradshaw-Holzapfel Lab
Center for Ecology and Evolutionary Biology
1210 University of Oregon
Eugene, Oregon 97403
kemerson at uoregon.edu