Chi square tests following multiple imputation #620
franzepsy
started this conversation in
Impute, analyse and pool
Replies: 2 comments 2 replies
-
If you want to obtain estimates on each imputed dataset, you can use functional programming (or a for loop, if you're more comfortable with that). Here a small reprex: # setup
library(mice)
#> Warning: package 'mice' was built under R version 4.3.1
#>
#> Attaching package: 'mice'
#> The following object is masked from 'package:stats':
#>
#> filter
#> The following objects are masked from 'package:base':
#>
#> cbind, rbind
# incomplete data
dat <- nhanes
dat$age <- as.factor(dat$age)
dat$hyp <- as.factor(dat$hyp)
chisq.test(x = dat$age, y = dat$hyp)
#> Warning in chisq.test(x = dat$age, y = dat$hyp): Chi-squared approximation may
#> be incorrect
#>
#> Pearson's Chi-squared test
#>
#> data: dat$age and dat$hyp
#> X-squared = 4.7731, df = 2, p-value = 0.09195
# imputed data
imp <- mice(dat, print = FALSE)
compl <- complete(imp, "all")
purrr::map(compl, ~{
chisq.test(x = .x$age, y = .x$hyp)
})
#> Warning in chisq.test(x = .x$age, y = .x$hyp): Chi-squared approximation may be
#> incorrect
#> Warning in chisq.test(x = .x$age, y = .x$hyp): Chi-squared approximation may be
#> incorrect
#> Warning in chisq.test(x = .x$age, y = .x$hyp): Chi-squared approximation may be
#> incorrect
#> Warning in chisq.test(x = .x$age, y = .x$hyp): Chi-squared approximation may be
#> incorrect
#> Warning in chisq.test(x = .x$age, y = .x$hyp): Chi-squared approximation may be
#> incorrect
#> $`1`
#>
#> Pearson's Chi-squared test
#>
#> data: .x$age and .x$hyp
#> X-squared = 8.2916, df = 2, p-value = 0.01583
#>
#>
#> $`2`
#>
#> Pearson's Chi-squared test
#>
#> data: .x$age and .x$hyp
#> X-squared = 9.0561, df = 2, p-value = 0.0108
#>
#>
#> $`3`
#>
#> Pearson's Chi-squared test
#>
#> data: .x$age and .x$hyp
#> X-squared = 5.9524, df = 2, p-value = 0.05099
#>
#>
#> $`4`
#>
#> Pearson's Chi-squared test
#>
#> data: .x$age and .x$hyp
#> X-squared = 3.3351, df = 2, p-value = 0.1887
#>
#>
#> $`5`
#>
#> Pearson's Chi-squared test
#>
#> data: .x$age and .x$hyp
#> X-squared = 9.8828, df = 2, p-value = 0.007144 Created on 2024-02-01 with reprex v2.0.2 |
Beta Was this translation helpful? Give feedback.
1 reply
-
There is no automatic way to do this, but a small edit to the above example solves the pooling step:
Then you can just map or loop over the 20 variables you're describing. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have conducted multiple imputation with 'mice' and now need to conduct chi square tests (factor with 2 levels x factor with 4 levels) in each of the (32) multiply imputed datasets and pool the results.
I am aware of the formula:
dk <- c(24.957, 18.051, 18.812, 17.362, 21.234, 18.615, 19.84)
dk.comb <- miceadds::micombine.chisquare(dk=dk, df=4 )
But how can I obtain the chi square results for each of the 32 imputed datasets, to then pool them together? In short, is there a formula to obtain dk?
Thank you!
Beta Was this translation helpful? Give feedback.
All reactions