amices / mice

Multivariate Imputation by Chained Equations
https://amices.org/mice/
GNU General Public License v2.0
428 stars 107 forks source link

How to perform sensitivity analysis on imputed categorical variable? #528

Closed zasdzcc closed 1 year ago

zasdzcc commented 1 year ago

I can generate the following code for reproducibility. dat is the data used for analysis.

id1=rep(1:10,2)
    trt=c(rep(1,10),rep(0,10))
    outcome=rnorm(20)
    set.seed(1005)
    missing=c()
    for(i in outcome){
      if(rbinom(1,1,0.8*abs(i/max(abs(outcome))))==1){
        missing=c(missing,which(outcome==i))
      }
    }
    missing
    trt[missing]=NA
    dat=data.frame(id=id1,trt=as.factor(trt),outcome=outcome)
    a1=mice::mice(dat,method=c('','logreg',''))

Suppose I am done with analysis. Now I want to conduct sensitivity analysis on MAR. trt is the only variable with missing entries. How do I perform delta shifted sensitivity analysis? The imputation uses logistic regression on trt variable to predict imputed value. I want to perform delta shifted sensitivity analysis similar to https://www.gerkovink.com/miceVignettes/Sensitivity_analysis/Sensitivity_analysis.html. However, the only way to perform shifted sensitivity analysis here is to somehow access the logistic regression formula and modify it with offset. I have tried the following, but it seems to be wrong.

    forms_a1=a1$formulas
    forms_a1$trt=as.formula(trt~outcome+offset(2))

    mice::mice(dat,method=c('','logreg',''),formulas = forms_a1)

However, mice gives the following output.

   iter imp variable
      1   1  trtError in model.frame.default(formula, data = data, na.action = na.pass) : 
      variable lengths differ (found for 'offset(2)')

Thanks.

stefvanbuuren commented 1 year ago

I suggest you take a look at mice.impute.mnar.logreg() that implements NARFCS.

zasdzcc commented 1 year ago

Member

Thanks a lot. I will check corresponding mnar methods.