[R] bootstrap confidence bands

Johannes Hüsing johannes at huesing.name
Fri Aug 29 08:15:57 CEST 2008


This is an attempt to an answer to Geertja van der Heijden's question, 
which seems not to have been answered yet.

Your attempt was:

 >drought <- read.table("D:/drought080525.txt", header=T)

 >regres <- function(x, indices) {
 >x <- x[indices,]
 >coef(lm(x$AGB ~ x$days, weights=x$weights))
 >}

and what you need are the confidence bands for the regression line.

How about generating fitted values out of bootstrap samples the 
following way
(untested!):

days <- seq(from=min(x$days), to=max(x$days), length=200)
days.df <- as.data.frame(days)

regres <- function(x, indices) {
   x <- x[indices,]
   predict(lm(x$AGB ~ x$days), newdata=days.df)
}

predvals <- boot(drought, regres, R=10000, stype="i")

You can then plot the results of boot.ci as lines.



More information about the R-help mailing list