# Margins after mice?

I would like to apply the margins function to imputed data (I used mice), but it seems not possible. Do you know if a function exists that calculates marginal effects with imputed data?

Thank you!

Edit: I have modified my code as follows: is it correct? Thank you!

ddply(data_pooled, "imp", function(x){
logregress <-  glm(y ~ var1 + var2 + var3, family = binomial(link="logit"), data=data_pooled)

margin_mod <- margins(logregress, type="response")
})

margin_summary <- summary(MIcombine(margin_mod))

• Can you give some more information about what exactly you are doing ? Why can't you just apply the function to each imputation and pool the results ? Oct 6, 2020 at 14:15
• Thank you @RobertLong for the input, I didn't know that was possible. Let me see if I've understood you: should I use the imputed dataset in the long format (with raw and imputed data) to run the regression and then margins? Oct 6, 2020 at 14:35
• No, you apply your function to each imputed dataset and then average the results. I have posted an answer with details. Oct 6, 2020 at 15:24

## 1 Answer

The general approach to analysis of missing data using multiple imputation is

• create several complete datasets, let's say $$m$$, using whatever multiple imputation alogorithm you choose

• perform the final analysis model (eg a regression model) on each complete dataset. That is, you would run $$m$$ models.

• pool the results of the analyses. With a linear regression model you would simply average all the estimates of interest to find the pooled estimate. For standard errors, the typical approach is to use Rubin's rules, which incorporate uncertainty both within, and between, imputations. If the sampling distribution of the estimate of interest does not follow a normal distribution, then other methods can be employed. See this question and answer for further details: Applying Rubin's rule for combining multiply imputed datasets

• I have modified my question with the code I wrote following your suggestion, can you please check it as I am not sure it is correct? Thank you so much! Oct 7, 2020 at 9:16
• I think so, but I'm not completely sure. Please note that questions about software or coding are off topic here - you could ask a follow-on question on stackoverflow. Oct 7, 2020 at 9:53
• @Ele_456 does this answer your question ? If so, please consider marking it as the accepted answer, and if not, please let us know why. Oct 15, 2020 at 19:05