I think I am doing something wrong when I try to bootstrap R square obtained from lm. My code is included below. No matter how many times I run the simulation, I always get exactly the same result, the bias and std.error are always zero. I would think that these values should be non-zero. I would appreciate any suggestions as to what I am doing wrong, or perhaps what I fail to understand. R 2.1.0 Patched Win 2k. Thanks, John>detefun3<-function (d,w)summary(lm(d$sg120~d$fg120adj,data=d))$r.square> boot(delete,deletefun3,R=200)ORDINARY NONPARAMETRIC BOOTSTRAP Call: boot(data = delete, statistic = deletefun3, R = 200) Bootstrap Statistics : original bias std. error t1* 0.3028048 0 0>John Sorkin M.D., Ph.D. Chief, Biostatistics and Informatics Baltimore VA Medical Center GRECC and University of Maryland School of Medicine Claude Pepper OAIC University of Maryland School of Medicine Division of Gerontology Baltimore VA Medical Center 10 North Greene Street GRECC (BT/18/GR) Baltimore, MD 21201-1524 410-605-7119 - NOTE NEW EMAIL ADDRESS: jsorkin@grecc.umaryland.edu [[alternative HTML version deleted]]
Your function does not meet the requirement for boot(). Here's an example:> x <- runif(100) > y <- x + rnorm(100, sd=0.1) > dat <- data.frame(x, y) > rm(x,y) > rsq <- function(data, idx) summary(lm(y~x, data=dat[idx,]))$r.squared > rsq.boot <- boot(dat, rsq, R=200) > rsq.bootORDINARY NONPARAMETRIC BOOTSTRAP Call: boot(data = dat, statistic = rsq, R = 200) Bootstrap Statistics : original bias std. error t1* 0.8964966 0.0002857293 0.01841738 HTH, Andy> From: John Sorkin > > I think I am doing something wrong when I try to bootstrap R square > obtained from lm. My code is included below. No matter how > many times I > run the simulation, I always get exactly the same result, the bias and > std.error are always zero. I would think that these values should be > non-zero. I would appreciate any suggestions as to what I am doing > wrong, or perhaps what I fail to understand. > R 2.1.0 Patched Win 2k. > Thanks, > John > > > >detefun3<-function (d,w) > summary(lm(d$sg120~d$fg120adj,data=d))$r.square > > boot(delete,deletefun3,R=200) > > ORDINARY NONPARAMETRIC BOOTSTRAP > > Call: > boot(data = delete, statistic = deletefun3, R = 200) > > Bootstrap Statistics : > original bias std. error > t1* 0.3028048 0 0 > > > > John Sorkin M.D., Ph.D. > Chief, Biostatistics and Informatics > Baltimore VA Medical Center GRECC and > University of Maryland School of Medicine Claude Pepper OAIC > > University of Maryland School of Medicine > Division of Gerontology > Baltimore VA Medical Center > 10 North Greene Street > GRECC (BT/18/GR) > Baltimore, MD 21201-1524 > > 410-605-7119 > -- NOTE NEW EMAIL ADDRESS: > jsorkin at grecc.umaryland.edu > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html > > >
Your function never uses the argument w. This argument is used to define the bootstrap sample as described in the help for boot. You have choices about how to do this for linear models. If you want to do case resampling then you function should be detefun3<-function (d,i) { d <- d[i,] summary(lm(d$sg120~d$fg120adj,data=d))$r.square } Why you would want to bootstrap R-squared or whether that is a good idea, I am not so sure. Angelo On Wed, 1 Jun 2005, John Sorkin wrote:> I think I am doing something wrong when I try to bootstrap R square > obtained from lm. My code is included below. No matter how many times I > run the simulation, I always get exactly the same result, the bias and > std.error are always zero. I would think that these values should be > non-zero. I would appreciate any suggestions as to what I am doing > wrong, or perhaps what I fail to understand. > R 2.1.0 Patched Win 2k. > Thanks, > John > > > >detefun3<-function (d,w) > summary(lm(d$sg120~d$fg120adj,data=d))$r.square > > boot(delete,deletefun3,R=200) > > ORDINARY NONPARAMETRIC BOOTSTRAP > > Call: > boot(data = delete, statistic = deletefun3, R = 200) > > Bootstrap Statistics : > original bias std. error > t1* 0.3028048 0 0 > > > > John Sorkin M.D., Ph.D. > Chief, Biostatistics and Informatics > Baltimore VA Medical Center GRECC and > University of Maryland School of Medicine Claude Pepper OAIC > > University of Maryland School of Medicine > Division of Gerontology > Baltimore VA Medical Center > 10 North Greene Street > GRECC (BT/18/GR) > Baltimore, MD 21201-1524 > > 410-605-7119 > -- NOTE NEW EMAIL ADDRESS: > jsorkin at grecc.umaryland.edu > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html >-- ------------------------------------------------------------------ | Angelo J. Canty Email: cantya at mcmaster.ca | | Mathematics and Statistics Phone: (905) 525-9140 x 27079 | | McMaster University Fax : (905) 522-0935 | | 1280 Main St. W. | | Hamilton ON L8S 4K1 |