Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

boot.tidy conf.method "norm" fails for anything that does not have exactly 2 results #1212

Closed
yjml opened this issue Aug 30, 2024 · 2 comments

Comments

@yjml
Copy link

yjml commented Aug 30, 2024

As per title, tidy.boot(..., conf.method = "norm") will error on any boot object that does not have exactly two results, since apparently that was hardcoded

ci.tab <- cbind(ci.list[[1]][ci.pos][[1]][2:3], ci.list[[2]][ci.pos][[1]][2:3])

Additionally, the rows/columns of the 2x2 confidence interval matrix are also incorrectly transposed, i.e. in the example below, the result should be (-0.0901, 0.2716) and (-0.294, 0.0794). Should be a rbind and not a cbind I believe?

library(boot)
library(broom)

set.seed(123)
d = data.frame(v1 = rnorm(100), v2=rnorm(100))
boot1 = function(d, i) {
  d = d[i,]
  c(mean(d$v1), mean(d$v2), cor(d$v1, d$v2))
}
boot2 = function(d, i) {
  d = d[i,]
  c(mean(d$v1), mean(d$v2))
}
boot3 = function(d, i) {
  d = d[i,]
  c(mean(d$v1))
}

r1 = boot(d, boot1, 1000)
r2 = boot(d, boot2, 1000)
r3 = boot(d, boot3, 1000)

tidy(r1, conf.int = T, conf.method = "norm")
#> Error in data.frame(..., check.names = FALSE): arguments imply differing number of rows: 3, 2
tidy(r2, conf.int = T, conf.method = "norm")
#> # A tibble: 2 x 5
#>   statistic      bias std.error conf.low conf.high
#>       <dbl>     <dbl>     <dbl>    <dbl>     <dbl>
#> 1    0.0904 -0.000358    0.0923  -0.0901   -0.294 
#> 2   -0.108  -0.000230    0.0953   0.272     0.0794
tidy(r3, conf.int = T, conf.method = "norm")
#> Error in ci.list[[2]]: subscript out of bounds

### Other methods work correctly ###
tidy(r1, conf.int = T, conf.method = "basic")
#> # A tibble: 3 x 5
#>   statistic      bias std.error conf.low conf.high
#>       <dbl>     <dbl>     <dbl>    <dbl>     <dbl>
#> 1    0.0904  0.00188     0.0889  -0.0906    0.264 
#> 2   -0.108  -0.000687    0.0983  -0.304     0.0864
#> 3   -0.0495  0.000840    0.0964  -0.248     0.137
tidy(r2, conf.int = T, conf.method = "basic")
#> # A tibble: 2 x 5
#>   statistic      bias std.error conf.low conf.high
#>       <dbl>     <dbl>     <dbl>    <dbl>     <dbl>
#> 1    0.0904 -0.000358    0.0923  -0.0932    0.282 
#> 2   -0.108  -0.000230    0.0953  -0.290     0.0826
tidy(r3, conf.int = T, conf.method = "basic")
#> # A tibble: 1 x 5
#>   statistic    bias std.error conf.low conf.high
#>       <dbl>   <dbl>     <dbl>    <dbl>     <dbl>
#> 1    0.0904 0.00119    0.0913  -0.0951     0.269
@simonpcouch
Copy link
Collaborator

Just noting that I've seen this! Related to #655. Will revisit next time I'm making a sweep through broom issues. :)

Copy link

This issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with a reprex: https://reprex.tidyverse.org) and link to this issue.

@github-actions github-actions bot locked and limited conversation to collaborators Oct 11, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants