# 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 ? – Robert Long Oct 6 '20 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? – Ele_456 Oct 6 '20 at 14:35
• No, you apply your function to each imputed dataset and then average the results. I have posted an answer with details. – Robert Long Oct 6 '20 at 15:24

• 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.