23
$\begingroup$

I have a vector of numbers that I've uploaded here (.../code/MyData.Rdata) using dput.

I would like to get the bca ci so I've written this code:

my.mean <- function(dat, idx){
 return (mean(dat[idx], na.rm = TRUE))
} 

boot.out<-boot(data=my.data, statistic = my.mean, R=1000)

But when I run the following I get this:

> boot.ci(boot.out)
Error in bca.ci(boot.out, conf, index[1L], L = L, t = t.o, t0 = t0.o,  : 
estimated adjustment 'a' is NA
In addition: Warning message:
In boot.ci(boot.out) : bootstrap variances needed for studentized intervals

Can someone help me figure out what is causing this error? Thank you for your help!

$\endgroup$
2
  • 4
    $\begingroup$ I have tried with R=10000 instead of R=1000 (and specifying type='bca' instead of type='all' since this is what you really want) and it works. So my conclusion would be that what is causing this error is not enough bootstrap replications... but I cannot say more... $\endgroup$
    – ocram
    Commented Sep 24, 2012 at 18:56
  • $\begingroup$ It worked for me once I set L value manually. L value should be set to be around 0.25 to 0.5 times 'R'. $\endgroup$ Commented Feb 27 at 13:55

1 Answer 1

34
$\begingroup$

As you can see from your error message, boot.ci calls bca.ci. Because the boot.out object doesn't supply L, the empirical influence values for the statistic you're calculating on the data, bca.ci tries to calculate them using the empinf function, and then (as Michael says) it uses them to calculate the acceleration constant:

L <- empinf(boot.out, index = index, t = t.o, ...)
a <- sum(L^3)/(6 * sum(L^2)^1.5)

But with a small number of replications, empinf sometimes fails and returns a vector of NA values. The result is that you have no values for L, a can't be calculated, and you get your error. As ocram says, increasing the number of boostrap replications will fix this. Even doubling R to 2000 should probably do it.

Addition I by @cdalitz: Unfortunately, empinf also fails in other situations, but fortunately it offers an alternative implementation by setting the option type="jack". In our experiments (tested, among others, with the median of an exponential distribution as the statistic of interest), this alternative option worked in all cases, even when the default implementation failed. When both worked, the results were almost indistinguishable. You can thus obtain results with

ci <- boot.ci(boot.out, conf=0.95, type = "bca",
              L =empinf(boot.out, index=1L, type="jack"))

Addition II by @cdalitz: I have submitted a bugfix to the maintainer of the boot package, and it has been merged into boot since version 1.3-31 from 2024-08-28.

$\endgroup$
3
  • 2
    $\begingroup$ +1 @Kieran Thanks! I am glad that my guess had some validity. You have the right answer from your knowledge of the R programs involved. so my answer is no longer needed. Someone either did not like me guessing or thought my answer should be a comment. For all those reasons it makes sense for me to delete it now. $\endgroup$ Commented Sep 24, 2012 at 21:46
  • 9
    $\begingroup$ For other who suffer the problem: According to stat.ethz.ch/pipermail/r-help/2011-February/269006.html the number of repetitions must be larger than the number of data rows. I was mildly suprsed that so many repetitions are necessary... $\endgroup$
    – BurninLeo
    Commented Oct 11, 2015 at 8:56
  • 1
    $\begingroup$ @BurninLeo As I have run into the same problem that made me scratch my head for some time, I have just filed a bug report for boot.ci(): bugs.r-project.org/show_bug.cgi?id=18647 $\endgroup$
    – cdalitz
    Commented Jan 4 at 13:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.