[R] BIG difficulties in Using boot.ci (bot package)

Nordlund, Dan (DSHS/RDA) NordlDJ at dshs.wa.gov
Mon Apr 13 23:36:08 CEST 2015


That is probably the number one reason for requesting a reproducible example when writing to R-help. In the proce3ss of working that out, you often solve your own problem.

Best of luck with your bootstrapping,

Dan

Daniel J. Nordlund, PhD
Research and Data Analysis Division
Services & Enterprise Support Administration
Washington State Department of Social and Health Services


> -----Original Message-----
> From: R-help [mailto:r-help-bounces at r-project.org] On Behalf Of varin
> sacha
> Sent: Monday, April 13, 2015 11:55 AM
> To: Daniel Nordlund; r-help at r-project.org
> Subject: Re: [R] BIG difficulties in Using boot.ci (bot package)
> 
> Hi Daniel,
> 
> Sorry for that, once more.... ;=(
> 
> Here is the reproducible code and this time IT WORKS FINALLY !!!
> 
> GDP.LOG <-c(14,12,13,15.5,16,17,16.5,13.5,12.5,12)
> Quality.score <-c(12,11,13,14,15,16,12,10,9,9)
> Competitivness.score=c(8,6,7,5,6.5,7,8,4.5,6,7)
> df=data.frame(GDP.LOG,Quality.score,Competitivness.score)
> 
> fit <- lm(formula = GDP.LOG ~ Quality.score + Competitivness.score)
> install.packages("boot")
> library(boot)
> bs=function(formula,data,indices){
> d=data[indices,]
> fit=lm(formula,data=d)
> (coef(fit))
> }
> results=boot(data=df,statistic=bs, R=2000,formula= GDP.LOG ~
> Quality.score + Competitivness.score)
> boot.ci(results,type="bca",index=1)
> boot.ci(results,type="bca",index=2)
> boot.ci(results,type="bca",index=3)
> 
> Best,
> S
> 
> 
> 
> ----- Mail original -----
> De : Daniel Nordlund <djnordlund at frontier.com>
> À : r-help at r-project.org
> Cc :
> Envoyé le : Lundi 13 avril 2015 19h26
> Objet : Re: [R] BIG difficulties in Using boot.ci (bot package)
> 
> On 4/13/2015 9:06 AM, varin sacha wrote:
> > Hi Michael,
> >
> > Thanks for your response. About the data frame not necessary. I
> correct the code according to your comments. I still get the following
> warnings :
> > [1] "All values of t are equal to  5.75620151906917 \n Cannot
> calculate confidence intervals"
> > NULL
> >
> > I have found this on the Net :
> > "Note that boot.ci just gives a warning and returns NA values, if all
> values are equal. There is no error and if you can work with NAs, there
> is no need for the if condition.
> > The boot package assumes that the bootstrap
> > statistic has all ways the same dimension.
> > Whenever you have a statistic with less dimensions you get an NA
> > or 0 or whatever you want".
> >
> > The reproducible code :
> >
> > GDP.LOG <-c(14,12,13,15.5,16,17,16.5,13.5,12.5,12)
> > Quality.score <-c(12,11,13,14,15,16,12,10,9,9)
> > Competitivness.score=c(8,6,7,5,6.5,7,8,4.5,6,7)
> > fit <- lm(formula = GDP.LOG ~ Quality.score + Competitivness.score)
> > install.packages("boot")
> > library(boot)
> > bs=function(formula,data,indices){
> > d=data[indices,]
> > fit=lm(formula,data=d)
> > (coef(fit))
> > }
> > results=boot(data=Dataset,statistic=bs, R=2000,formula= GDP.LOG ~
> Quality.score + Competitivness.score)
> > boot.ci(results,type="bca",index=1)
> > boot.ci(results,type="bca",index=2)
> > boot.ci(results,type="bca",index=3)
> >
> > How is it possible to avoid that warning ?
> >
> > Best,
> > S
> >
> >
> >
> 
> The first problem is that this is not reproducible code.  This is what
> I
> get when I run your code on my computer:
> 
> > GDP.LOG <-c(14,12,13,15.5,16,17,16.5,13.5,12.5,12)
> > Quality.score <-c(12,11,13,14,15,16,12,10,9,9)
> > Competitivness.score=c(8,6,7,5,6.5,7,8,4.5,6,7)
> > fit <- lm(formula = GDP.LOG ~ Quality.score + Competitivness.score)
> > #####install.packages("boot")
> > library(boot)
> > bs=function(formula,data,indices){
> + d=data[indices,]
> + fit=lm(formula,data=d)
> + (coef(fit))
> + }
> > results=boot(data=Dataset,statistic=bs, R=2000,formula= GDP.LOG ~
> Quality.score + Competitivness.score)
> Error in NROW(data) : object 'Dataset' not found
> > boot.ci(results,type="bca",index=1)
> Error in boot.ci(results, type = "bca", index = 1) :
>    object 'results' not found
> > boot.ci(results,type="bca",index=2)
> Error in boot.ci(results, type = "bca", index = 2) :
>    object 'results' not found
> > boot.ci(results,type="bca",index=3)
> Error in boot.ci(results, type = "bca", index = 3) :
>    object 'results' not found
> >
> 
> 
> A reproducible example means that when I run your code on my machine, I
> get the same results / warnings / errors that you get.  I got something
> different.
> 
> 
> Dan
> 
> --
> Daniel Nordlund
> Bothell, WA USA
> 
> 
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.
> 
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.


More information about the R-help mailing list