0
votes


I would like to probe an interaction in a moderation analysis between a categorical predictor and a continuous variable in a multiple imputed data set. I would like to look at the effect of different levels of the continuous moderator (-1SD, Mean, +1SD).

I know that this is possible in SPSS with the PROCESS macro, but unfortunately, it cannot handle multiple imputed data. The interaction package can't handle it either. Does anyone have any ideas on how to solve this problem?

I have imputed the data with the mice package, with m = 50.

My model looks like this:

lm(outcome ~ group * continuous_moderator)

Here is a reproducible example, using the windspeed dataset integrated in mice:

data <- mice::windspeed
data$group <- sample(c(0:1), replace = T, size = 433)

imp_data <- mice(data,
                 m=50,
                 maxit=20,
                 meth='cart',
                 seed=12345)

model1 <- with(imp_data,
               lm(RochePt ~ group * Clones))

Thanks in advance for all your help and tips.

1

1 Answers

1
votes

You can do this using [the marginaleffects package.] (Disclaimer: I am the author.) See this vignette for details:

https://vincentarelbundock.github.io/marginaleffects/articles/multiple_imputation.html

The quick illustration below uses the by argument which is available in the dev version (should be out on CRAN in the next couple weeks). Install it:

library(remotes)
install_github("vincentarelbundock/marginaleffects")

Then,

library(mice)
library(marginaleffects)

data <- mice::windspeed

# {marginaleffects} reserves the name "group", so I "group_id" instead
data$group_id <- sample(c(0:1), replace = T, size = 433)

fit <- function(x) {
    mod <- lm(RochePt ~ group_id * Clones, data = x)
    out <- comparisons(mod, variables = "Clones", by = "group_id")
    # see vignette linked above for why we need the next line.
    out$term <- out$group_id
    return(out)
}

imp_data <- mice(data,
    m = 5,
    maxit = 20,
    meth = "cart",
    seed = 12345,
    printFlag = FALSE)
imp_data <- complete(imp_data, "all")

mod <- lapply(imp_data, fit)

mice::pool(mod)
#> Class: mipo    m = 5 
#>   term m  estimate        ubar b           t dfcom       df riv lambda
#> 1    1 5 0.9394599 0.002593162 0 0.002593162   433 430.9702   0      0
#> 2    0 5 1.0443336 0.003134239 0 0.003134239   433 430.9702   0      0
#>           fmi
#> 1 0.004608611
#> 2 0.004608611