John Sorkin
2009-Dec-30 12:18 UTC
[R] boot function returns the same results every time - there appears to be not resampling of the original data.
R 2.8.1 windows XP I am trying to learn how to use the boot function to perform a bootstrap of a regression. I have written a short trial program, shown below. Clearly I have done something wrong as the output of each of the 100 bootstrap values for the regression are exactly the same - there does not appear to be any bootstrap respampling!. What have I done wrong? # Define function to be run. Function will return # beta coefficeint for x. fitter<-function(d) { fit1<-lm(y~x,data=d) print(names(fit1)) print(summary(fit1)) summary(fit1)$coefficients[2,1] } # Define dataframe x<-1:10 y<-x+rnorm(10) d<-data.frame(x,y) #Run boot strap boot(d,fitter,R=100,sim="parametric") John David Sorkin M.D., Ph.D. Chief, Biostatistics and Informatics 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 (Phone) 410-605-7119 (Fax) 410-605-7913 (Please call phone number above prior to faxing) Confidentiality Statement: This email message, including any attachments, is for th...{{dropped:6}}
Prof Brian Ripley
2009-Dec-30 13:55 UTC
[R] boot function returns the same results every time - there appears to be not resampling of the original data.
On Wed, 30 Dec 2009, John Sorkin wrote:> R 2.8.1Rather old: have you updated package boot since?> windows XP > > I am trying to learn how to use the boot function to perform a > bootstrap of a regression. I have written a short trial program, > shown below. Clearly I have done something wrong as the output of > each of the 100 bootstrap values for the regression are exactly the > same - there does not appear to be any bootstrap respampling!. What > have I done wrong?First, sim="parametric" does not give 'bootstrap respampling', so I wonder if you have consulted the book for which this is support software? You will find it hard to use boot without a clear grasp of the underlying concepts. For bootstrapping a regression (and why you almost certainly do not want to do that) see the examples in MASS. You clearly missed the following on the help page: For the parametric bootstrap it is necessary for the user to specify how the resampling is to be conducted. The best way of accomplishing this is to specify the function ?ran.gen? which will return a simulated data set from the observed data set and a set of parameter estimates specified in ?mle?. The default ran.gen() function just returns the data ....> > > # Define function to be run. Function will return > # beta coefficeint for x. > fitter<-function(d) > { > fit1<-lm(y~x,data=d) > print(names(fit1)) > print(summary(fit1)) > summary(fit1)$coefficients[2,1] > } > > # Define dataframe > x<-1:10 > y<-x+rnorm(10) > d<-data.frame(x,y) > > > #Run boot strap > boot(d,fitter,R=100,sim="parametric") > > > > John David Sorkin M.D., Ph.D. > Chief, Biostatistics and Informatics > 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 > (Phone) 410-605-7119 > (Fax) 410-605-7913 (Please call phone number above prior to faxing) > > Confidentiality Statement: > This email message, including any attachments, is for th...{{dropped:6}} > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >-- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595