Skip to content

Bug? A minimal working example for bcajack2(Blist) #4

@t-pollington

Description

@t-pollington

Dear @bnaras,

I'm having trouble writing an MWE for bcajack2(). This was for my own benefit but also was planning to do a pull request to update the bcajack2() example as it doesn't really show off its specific functionality i.e. being able to do separate \hat{theta}* bootstrap calculations elsewhere and then get a 95% BCa CI, which is the use case I am most interested in. I'm in the middle of writing paper where I hope to do just this and would love to use your bcaboot package and cite it too!

From reading the function code I believe the error emanates from the internal function qbca2() which provides vl0$lims. On line 98 log(Yi) will produce -Inf when Yi[i] = 0; could this be the cause? Since I noticed when not using the Blist format on line 165 that Y gets values from table() which would not include values not present within a range i.e. table(c(1,2,4)) doesn't include a zero for 3 and therefore later doesn't throw the same error as Blist sees?

data(diabetes, package = "bcaboot")
Xy <- cbind(diabetes$x, diabetes$y)
rfun <- function(Xy) {
  y <- Xy[, 11]
  X <- Xy[, 1:10]
  summary(lm(y~X) )$adj.r.squared
}

# letting bcajack2 perform the bootstrapping
set.seed(1234)
bcaboot::bcajack2(x = Xy, B = 1000, func = rfun, m = 40, verbose = FALSE)
#> $call
#> bcaboot::bcajack2(x = Xy, B = 1000, func = rfun, m = 40, verbose = FALSE)
#> 
#> $lims
#>             bca      jacksd       std   pct
#> 0.025 0.4289798 0.003371377 0.4462564 0.002
#> 0.05  0.4374506 0.006440959 0.4559517 0.006
#> 0.1   0.4533929 0.004038199 0.4671297 0.018
#> 0.16  0.4621266 0.003321927 0.4759630 0.037
#> 0.5   0.4950141 0.001790731 0.5065603 0.219
#> 0.84  0.5255210 0.002355254 0.5371577 0.586
#> 0.9   0.5357038 0.002870023 0.5459909 0.692
#> 0.95  0.5459683 0.002031757 0.5571690 0.804
#> 0.975 0.5540292 0.003463861 0.5668642 0.877
#> 
#> $stats
#>         theta       sdboot          z0             a      sdjack
#> est 0.5065603 0.0307678772 -0.38532047 -0.0109424195 0.031399281
#> jsd 0.0000000 0.0007431751  0.03769735  0.0007008304 0.000282446
#> 
#> $B.mean
#> [1] 1000.0000000    0.5189562
#> 
#> $ustats
#>      ustat        sdu 
#> 0.49416441 0.03171256 
#> 
#> attr(,"class")
#> [1] "bcaboot"

# giving backjack2 the precomputed bootstrap estimates----
set.seed(1234)
inds = matrix(NA, nrow = 1000, ncol = nrow(Xy))
inds = t(apply(inds, MARGIN = 1, function(inds) sample(1:nrow(Xy), replace = TRUE))) # get bootstrap indices to feed into estimator rfun()
tt = vector(mode = "numeric", length = 1000)
tt = apply(inds, MARGIN = 1, function(inds) rfun(Xy[inds,])) # get \hat{theta}*
Y = t(apply(inds, MARGIN = 1, tabulate, nbins = nrow(Xy)))

Blist = list(Y = Y, 
             tt = tt, 
             t0 = rfun(Xy)) # original estimate \hat{theta}
bcaboot::bcajack2(Blist) # "argument "B" is missing, with no default" which contradicts https://github.com/bnaras/bcaboot/blob/master/man/bcajack2.Rd line 114
#> Error in bcaboot::bcajack2(Blist): argument "B" is missing, with no default
bcaboot::bcajack2(B = Blist) # bca $lims are all NA
#> $call
#> bcaboot::bcajack2(B = Blist)
#> 
#> $lims
#>       bca jacksd       std pct
#> 0.025  NA    NaN 0.4430264  NA
#> 0.05   NA    NaN 0.4532409  NA
#> 0.1    NA    NaN 0.4650177  NA
#> 0.16   NA    NaN 0.4743241  NA
#> 0.5    NA    NaN 0.5065603  NA
#> 0.84   NA    NaN 0.5387965  NA
#> 0.9    NA    NaN 0.5481029  NA
#> 0.95   NA    NaN 0.5598797  NA
#> 0.975  NA    NaN 0.5700943  NA
#> 
#> $stats
#>         theta       sdboot          z0   a sdjack
#> est 0.5065603 0.0324158820 -0.20701262  NA     NA
#> jsd 0.0000000 0.0007799418  0.03852254 NaN    NaN
#> 
#> $B.mean
#> [1] 1000.0000000    0.5137792
#> 
#> $ustats
#>     ustat       sdu 
#> 0.4993414        NA 
#> 
#> attr(,"class")
#> [1] "bcaboot"
bcaboot::bcajack2(B = Blist, m = 40) # still NA
#> $call
#> bcaboot::bcajack2(B = Blist, m = 40)
#> 
#> $lims
#>       bca jacksd       std pct
#> 0.025  NA    NaN 0.4430264  NA
#> 0.05   NA    NaN 0.4532409  NA
#> 0.1    NA    NaN 0.4650177  NA
#> 0.16   NA    NaN 0.4743241  NA
#> 0.5    NA    NaN 0.5065603  NA
#> 0.84   NA    NaN 0.5387965  NA
#> 0.9    NA    NaN 0.5481029  NA
#> 0.95   NA    NaN 0.5598797  NA
#> 0.975  NA    NaN 0.5700943  NA
#> 
#> $stats
#>         theta      sdboot          z0   a sdjack
#> est 0.5065603 0.032415882 -0.20701262  NA     NA
#> jsd 0.0000000 0.000791282  0.03863627 NaN    NaN
#> 
#> $B.mean
#> [1] 1000.0000000    0.5137792
#> 
#> $ustats
#>     ustat       sdu 
#> 0.4993414        NA 
#> 
#> attr(,"class")
#> [1] "bcaboot"

Created on 2021-08-26 by the reprex package (v2.0.1)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions