Skip to content

BIG difficulties in Using boot.ci (bot package)

8 messages · varin sacha, Adams, Jean, Michael Dewey +2 more

#
Dear R-Experts, 

I am trying to compute the BCa nonparametric bootstrap on regression coefficients. 

Here is the reproducible example :  

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) 
confint(fit, level=.95) 
confint.default(fit, level=.95) 
confint(fit,level=.95,type="bca") 

I am not sure but I think that I can not get the nonparametric BCa bootstrap with the confint function. As you can see, I have tried the argument type="bca", I don?t get any error message, but the results don?t change, the results are exactly the same as confint(fit,level=.95). 
As I have understood, the default argument uses normal quantiles and the method for linear models uses T-quantiles instead. 
So, I have checked the boot package and the boot.ci function to calculate the BCa bootstrap on the regression coefficients, but I don?t really understand how to compute the code. 
So, any help from you would be highly appreciated. 

Best,
S
2 days later
#
S,

There is no mention of a type="bca" argument on the ?confint help file.

You can look here for an example of using the boot.ci() function in the
boot package:

http://www.statmethods.net/advstats/bootstrapping.html

?Jean?
On Fri, Apr 10, 2015 at 11:01 AM, varin sacha <varinsacha at yahoo.fr> wrote:

            

  
  
#
Hi Jean,

Many thanks, I got it but there is still a problem. When trying to bootstrap the confidence intervals, I get these messages. 
 

boot.ci(results,type="bca",index=1) 
[1] "All values of t are equal to  5.75620151906917 \n Cannot calculate confidence intervals"
NULL
[1] "All values of t are equal to  0.618293471234648 \n Cannot calculate confidence intervals"
NULL
[1] "All values of t are equal to  0.148068842921784 \n Cannot calculate confidence intervals"
NULL


Here is the reproducible example :

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=Dataset) 
return(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 to solve that problem ?

Best,
S.



________________________________
De : "Adams, Jean" <jvadams at usgs.gov>

Cc : "r-help at r-project.org" <r-help at r-project.org> 
Envoy? le : Lundi 13 avril 2015 14h22
Objet : Re: [R] BIG difficulties in Using boot.ci (bot package)



S,

There is no mention of a type="bca" argument on the ?confint help file.

You can look here for an example of using the boot.ci() function in the boot package: 
http://www.statmethods.net/advstats/bootstrapping.html
Dear R-Experts,
#
See in line
On 13/04/2015 14:38, varin sacha wrote:
Did you mean at this point to put these into a data frame?
In the code you sent there does not seem to be an object called Dataset.
Did you mean data = d?
You do not need to say return( ) at the end, just coef(fit) would work.

  
    
  
#
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



----- Mail original -----
De : Michael Dewey <lists at dewey.myzen.co.uk>
? : varin sacha <varinsacha at yahoo.fr>; "Adams, Jean" <jvadams at usgs.gov>
Cc : "r-help at r-project.org" <r-help at r-project.org>
Envoy? le : Lundi 13 avril 2015 16h00
Objet : Re: [R] BIG difficulties in Using boot.ci (bot package)

See in line
On 13/04/2015 14:38, varin sacha wrote:
Did you mean at this point to put these into a data frame?
In the code you sent there does not seem to be an object called Dataset.
Did you mean data = d?
You do not need to say return( ) at the end, just coef(fit) would work.

  
    
  
#
On 4/13/2015 9:06 AM, varin sacha wrote:
The first problem is that this is not reproducible code.  This is what I 
get when I run your code on my computer:
+ d=data[indices,]
+ fit=lm(formula,data=d)
+ (coef(fit))
+ }
Error in NROW(data) : object 'Dataset' not found
Error in boot.ci(results, type = "bca", index = 1) :
   object 'results' not found
Error in boot.ci(results, type = "bca", index = 2) :
   object 'results' not found
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
#
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:
The first problem is that this is not reproducible code.  This is what I 
get when I run your code on my computer:
+ d=data[indices,]
+ fit=lm(formula,data=d)
+ (coef(fit))
+ }
Error in NROW(data) : object 'Dataset' not found
Error in boot.ci(results, type = "bca", index = 1) :
   object 'results' not found
Error in boot.ci(results, type = "bca", index = 2) :
   object 'results' not found
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
#
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