jwb133 / smcfcs

R package implementing Substantive Model Compatible Fully Conditional Specification Multiple Imputation
11 stars 7 forks source link

Specifying interactions #4

Closed ekstroem closed 9 years ago

ekstroem commented 9 years ago

I was wondering about the best way to specify interactions with multiple levels.

I have the following situation:

I want to fit a model with an interaction between x and g.

Now what is the proper way to specify the interaction? In the example with ex_lininter the following code is used, where x1x2 is already defined in the data frame as the product of x1 and x2.

 #impute missing x1 and x2, where they interact in substantive model
  imps <- smcfcs(ex_lininter, smtype="lm", smformula="y~x1+x2+x1x2",
                 method=c("","norm","logreg","x1*x2"))

I can manually code dummy variables to things up and running like the example above but then I seem to miss the 3 levels of my factor when I impute the missing values in the g variable. Running the following code works, but here the "artificial" construction of the interaction in the data frame is skipped and the improvement gained by including the interaction in the imputation is lost.

imps <- smcfcs(minidata, smtype="lm", 
        smformula="y ~ x + g + x*g",
        method=c("", "", "mlogit"))
jwb133 commented 9 years ago

Thanks Claus. For this situation it is sufficient (and indeed simpler) to not generate the interaction variable in the data frame, but simply to use the code as in your second block:

imps <- smcfcs(minidata, smtype="lm", 
        smformula="y ~ x + g + x*g",
        method=c("", "", "mlogit"))

If you were however, to go down the dummy variable approach, this should work. g would be imputed using mlogit, the dummies would be imputed passively based on g, and the interactions would similarly be imputed passively (by specifying the appropriate expressions in the method argument).

I will modify the interaction example in the package to show the simpler approach.

Thanks!