Convert coefficients from log odds to marginal effects with imputed data in R

Viewed 199

I am using multiple imputation on missing data and then using the pool_mi function to get coefficients. Since my data is clustered I also had to calculate cluster robust SE my regression model using the lm.cluster function. However the output for the coefficients is in log odds form I believe. How can I convert the coefficients to be marginal effects? Or if that is not possible to be in probabilities? I've tried to follow this posts (linked here) but can't figure it out since my situation is a bit more complicated... Below is the example code for what I have done with the function and images of the output. Thank you!

library(mitools)
library(miceadds)
data(data.ma05)
dat <- data.ma05

# imputation of the dataset: use six imputations
resp <- dat[, - c(1:2) ]
imp <- mice::mice( resp, method="norm", maxit=3, m=6 )
datlist <- miceadds::mids2datlist( imp )

# linear regression with cluster robust standard errors
mod <- lapply(  datlist, FUN=function(data){
            miceadds::lm.cluster( data=data, formula=denote ~ migrant+ misei,
                    cluster=dat$idclass )
            }  )
# extract parameters and covariance matrix
betas <- lapply( mod, FUN=function(rr){ coef(rr) } )
vars <- lapply( mod, FUN=function(rr){ vcov(rr) } )
# conduct statistical inference
summary( miceadds::pool_mi( qhat=betas, u=vars ) )

enter image description here

1 Answers

Loop through the datlist using for loop to calculate cluster robust SE of you regression model using the lm_robust function. In assigning mod using lapply by default takes a closure type object that is not subsettable:

library(estimatr)
mod <- vector('list', length(datlist))
for(i in seq_along(datlist)){
  for(j in seq_along(datlist[[i]])){
    mod[[i]]<- lm_robust( data=datlist[[i]], formula=denote ~ migrant+ misei,
                          cluster=dat$idclass )
  }
}

Now use the margins function to find the marginal effects:

library(margins)
mod_margins <- list()
for(i in seq_along(mod)){
  mod_margins[[i]] <- margins::marginal_effects(mod[[i]])
}

# For single model in `mod`:
mar_cl <- margins::margins(mod[[1]])
mar_cl

Output:

migrant    misei
   0.5186 -0.01396
Related