in the ANOVA table (p. 459) is to use bootstrapping. There are two ways of doing this:
sample cases with replacement, so that some points are left off the graph while others appear more than
once in the dataframe;
calculate the residuals from the fitted regression model, and randomize which fitted y values get which
residuals
regdat <- read.table("c:\\temp\\regdat.txt",header=T)
attach(regdat)
names(regdat)
plot(explanatory,response,pch=21,col="green",bg="red")
model <- lm(response~explanatory)
abline(model,col="blue")
model
b.boot <- numeric(10000)
for (i in 1:10000){
indices <- sample(1:35,replace=T)
xv <- explanatory[indices]
yv <- response[indices]
model <- lm(yv~xv)
b.boot[i] <- coef(model)[2]
}
hist(b.boot,main="",col="green")
quantile(b.boot,c(0.025,0.975))
library(boot)
reg.boot <- function(regdat, index){
xv <- explanatory[index]
yv <- response[index]
model <- lm(yv~xv)
coef(model)
}
reg.model <- boot(regdat,reg.boot,R=10000)
boot.ci(reg.model,index=2)
model <- lm(response~explanatory)
fit <- fitted(model)
res <- resid(model)
residual.boot <- function(res, index){
y <- fit+res[index]
model <- lm(y~explanatory)
coef(model) }
res.model <- boot(res,residual.boot,R=10000)
boot.ci(res.model,index=2)