Skip to content

fisher.test() not compatible with D2() #508

Open
@stefvanbuuren

Description

@stefvanbuuren

Function fisher.test() does not produce estimate and std.error components in the return value. D2() relies on pool(), and hence fails. Would be useful to have a work-around.

require(mice)
#> Loading required package: mice
#> 
#> Attaching package: 'mice'
#> The following object is masked from 'package:stats':
#> 
#>     filter
#> The following objects are masked from 'package:base':
#> 
#>     cbind, rbind
data <- nhanes2
data$chl <- cut(data$chl, breaks = 2)
imp <- mice(data, print = FALSE)
fit <- with(imp, fisher.test(xtabs(~ hyp + chl)))
names(fit$analyses[[1]])
#> [1] "p.value"     "conf.int"    "estimate"    "null.value"  "alternative"
#> [6] "method"      "data.name"
D2(fit, fit0 = NULL, use = "wald")
#> Error in `summarize()`:
#> ! Problem while computing `ubar = mean(.data$std.error^2)`.
#> Caused by error in `.data$std.error`:
#> ! Column `std.error` not found in `.data`.

#> Backtrace:
#>      ▆
#>   1. ├─mice::D2(fit, fit0 = NULL, use = "wald")
#>   2. │ └─mice::pool(fit1)
#>   3. │   └─mice:::pool.fitlist(getfit(object), dfcom = dfcom, rule = rule)
#>   4. │     └─w %>% group_by(!!!syms(grp)) %>% ...
#>   5. ├─dplyr::summarize(...)
#>   6. ├─dplyr:::summarise.data.frame(...)
#>   7. │ └─dplyr:::summarise_cols(.data, dplyr_quosures(...), caller_env = caller_env())
#>   8. │   ├─base::withCallingHandlers(...)
#>   9. │   └─dplyr:::map(quosures, summarise_eval_one, mask = mask)
#>  10. │     └─base::lapply(.x, .f, ...)
#>  11. │       └─dplyr (local) FUN(X[[i]], ...)
#>  12. │         └─mask$eval_all_summarise(quo)
#>  13. ├─base::mean(.data$std.error^2)
#>  14. ├─std.error
#>  15. ├─rlang:::`$.rlang_data_pronoun`(.data, std.error)
#>  16. │ └─rlang:::data_pronoun_get(...)
#>  17. └─rlang:::abort_data_pronoun(x, call = y)
#>  18.   └─rlang::abort(msg, "rlang_error_data_pronoun_not_found", call = call)

Created on 2022-10-25 with reprex v2.0.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions