Skip to content

multi-level imputation error #293

Closed
Closed

Description

@bryorsnef

Hi there,

I'm trying to set up a multi-level imputation, but am hitting an error that looks like a bug. The model involves imputation of subject and item level variables (i.e. 2 sets of level 2 variables), and therefore two random intercepts - one for the subject factor, and one for the item factor. When I try to set things up with impute.2l.lmer, I get this error:

Error in str2lang(x) : :1:105: unexpected ')'
1: dv._lmer~1+subid+itemid+cwwt+cagtb+hub_connections+tdiff+rdiff+freq.diff+phonsimdiff+rt+(1+subid+itemid|)

Where the formula seems mangled - the subid and itemid should go on the other side of the |. As well, it seems like subid and itemid are also being included as fixed effects, even though they are coded as 2 for the imputed variable in the predictor matrix.

Activity

  1. stefvanbuuren commented on Dec 9, 2020

    @stefvanbuuren
    Member

    Sorry I can't do magic. Please provide a reproducible example in a really simplified case.

  2. bryorsnef commented on Dec 9, 2020

    @bryorsnef
    Author

    Appologies for not posting right away with an example - I was hoping this was a known issue or if I broke something obvious. I'm waiting for confirmation from a collaborator that I can share the original data, because I'm having issues reproducing the issue on my own.

  3. gerkovink commented on Dec 9, 2020

    @gerkovink
    Member

    There is a pipe symbol | in your code. I believe the language interpreter reads this as a conditional and expects some input, but instead finds a closing parenthesis ). I believe your error will disappear if you adjust the following part in your code:

    (1+subid+itemid|)

    All the best,

    Gerko

  4. gerkovink commented on Dec 9, 2020

    @gerkovink
    Member

    I can't even reprex your error because the above code breaks the reprex()

    > reprex()
    Rendering reprex...
    Error: callr subprocess failed: <text>:24:43: unexpected ')'
    23: imp <- mice(boys, m = 3, maxit = 2) # proof of concept
    24: with(imp, lmer(age ~ hgt + (1 + bmi + tv |)
                                                  ^
    Type .Last.error.trace to see where the error occured

    But in mice the following code also breaks, which proves my point.

    > imp <- mice(boys, m = 3, maxit = 2) # proof of concept
    
     iter imp variable
      1   1  hgt  wgt  bmi  hc  gen  phb  tv  reg
      1   2  hgt  wgt  bmi  hc  gen  phb  tv  reg
      1   3  hgt  wgt  bmi  hc  gen  phb  tv  reg
      2   1  hgt  wgt  bmi  hc  gen  phb  tv  reg
      2   2  hgt  wgt  bmi  hc  gen  phb  tv  reg
      2   3  hgt  wgt  bmi  hc  gen  phb  tv  reg
    > with(imp, lmer(age ~ hgt + (1 + bmi + tv|)))
    Error: unexpected ')' in "with(imp, lmer(age ~ hgt + (1 + bmi + tv|)"
  5. bryorsnef commented on Dec 9, 2020

    @bryorsnef
    Author

    Thanks for the help. The error isn't happening in the analysis step though, it's happening when I call mice() to do the imputation step. I don't explicitly state an lmer formula anywhere. I've been searching around for any resources on multi-level imputation in mice or other packages or functions to use. I see the mice.impute.ml.lmer in miceadds, but I'm having a hell of a time getting that set up. I'd like to stick to an FCS approach because the analyses I want to do eventually involve random slopes, so joint modelling seems less appealing. But finding clear guidance with good documentation hasn't been easy. Any suggestions on good tutorials or resources for multi-level imputation would be helpful.

  6. stefvanbuuren commented on Dec 10, 2020

    @stefvanbuuren
    Member

    @gerkovink Thanks, R expects a variable name after |. It does not make sense to leave it empty. @bryorsnef did you already try specify your class variable?

  7. gerkovink commented on Dec 15, 2020

    @gerkovink
    Member

    finding clear guidance with good documentation hasn't been easy. Any suggestions on good tutorials or resources for multi-level imputation would be helpful.

    Have a look at the Multilevel Imputation Vignette

    Can't help you any further without a proper reprex since the error seems to be dependent on your imputation specification.

    All the best,

    Gerko

  8. gerkovink commented on Dec 23, 2020

    @gerkovink
    Member

    Closing as the issue is not reproducible.

  9. locked and limited conversation to collaborators on Apr 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions