[R] 95% confidence interval of the coefficients from a bootstrap analysis

baconbeach baconbeach at gmail.com
Tue May 1 05:05:24 CEST 2012


Thanks again for your swift response!!

With your last line, I get 

> rowMeans(sapply(stor.confint, colMeans)) 
    2.5 %    97.5 % 
0.3256882 0.4604677 

I need the values (2.5% and 97.5%) for each variable of my model. I don't
think this what I am getting.

This is what my script looks like now, after your help:

N = length (data_Pb[,1])
B = 10000
stor.r2 = rep(0,B)
stor.coeffs <- vector("list", B) 
stor.confint <- vector("list", B) 

for (i in 1:B){
idx = sample(1:N, replace=T)
newdata = data_Pb[idx,]
L_NPRI_25k <- log(newdata$NPRI_25k+1)
data_Pb.boot = lm(newdata$Log_Level ~   
    newdata$Ind_5k + newdata$MineP_50k + 
  newdata$NPRI_10k + L_NPRI_25k )

stor.r2[i] = summary(data_Pb.boot)$r.squared
stor.coeffs [[i]] <- coef(data_Pb.boot) 
stor.confint[[i]] <- confint(data_Pb.boot) 
}

hist(stor.r2, xlab="R-squared",main="Distribution of R-squared - Lead
(log)")
summary(stor.r2)
rowMeans(sapply(stor.confint, colMeans)) 
rowMeans(sapply(stor.coeffs, colMeans))


Thanks 

Steeve

--
View this message in context: http://r.789695.n4.nabble.com/95-confidence-interval-of-the-coefficients-from-a-bootstrap-analysis-tp4599692p4599994.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list