Tom La Bone
2007-Nov-06 00:59 UTC
[R] Bootstrap CI of Slope in a Weighted Simple Linear Regression
Greetings, I would like to use the "boot" function to generate a bootstrap confidence interval for the slope in a SLR that has a zero intercept. My attempt to do this is shown below. Is this the correct implementation of the boot function to solve this problem? In particular, should I be doing anything with the residuals in the "bs" function (e.g., using weighted residuals)? Thanks for the help. X <- c(0.875691867,0.871198003,0.814833892,0.788439976,0.738949275, 0.662589259,0.625487458,0.596570413,0.573693499,0.541569432,0.490628528, 0.440835275,0.397729163,0.358838088,0.323749892,0.24980067,0.213632079, 0.159989195,0.127709133,0.109218152,0.104276109,0.086467125,0.075718558, 0.059271067,0.05441905,0.049097803,0.044388138,0.014282204,0.004744354) Y <- c(1.710091172,1.719901584,1.677683515,1.586374357,1.492977191,1.327498848, 1.301327304,1.25174086,1.149220115,1.130543366,0.974774745,0.912550499,0.752369319, 0.745150543,0.639280298,0.478799628,0.433639966,0.346051447,0.280818024,0.230285038, 0.201046915,0.179974417,0.163766453,0.102048289,0.111175621,0.100711353,0.072401066, 0.023761328,0.013927331) W <- 1/X fit <- lm(Y ~ X - 1,weights=W) Y.hat <- predict(fit) r <- resid(fit) data.df <- as.data.frame(cbind(X,Y,W)) bs <- function(data, indices) { Y.b <- Y.hat + r[indices] fit.b <- lm(Y.b ~ X - 1,weights=W) return(coef(fit.b))} results <- boot(data=data.df, statistic=bs,R=1000) boot.ci(results, type="perc", index=1) -- View this message in context: http://www.nabble.com/Bootstrap-CI-of-Slope-in-a-Weighted-Simple-Linear-Regression-tf4755456.html#a13598953 Sent from the R help mailing list archive at Nabble.com.
Maybe Matching Threads
- Iterative estimation of linear regression model
- [patch 2/9] Guest page hinting: unused / free pages on s390.
- [patch 2/9] Guest page hinting: unused / free pages on s390.
- interpretation of coefficients in survreg AND obtaining the hazard function
- interpretation of coefficients in survreg AND obtaining the hazard function for an individual given a set of predictors