r - pool.compare generates non-comformable arguments error -


alternate title: model matrix , set of coefficients show different numbers of variables

i using mice package r analyses. wanted compare 2 models (held in mira objects) using pool.compare(), keep getting following error:

error in model.matrix(formula, data) %*% coefs : non-conformable arguments

the binary operator %*% indicates matrix multiplication in r.

the expression model.matrix(formula, data) produces "the design matrix regression-like model specified formula , data" (from r documentation model.matrix {stats}).

in error message, coefs drawn est1$qbar, est1 mipo object, , qbar element "the average of complete data estimates. multiple imputation estimate." (from documentation mipo-class {mice}).

in case

  • est1$qbar numeric vector of length 36
  • data data.frame 918 observations of 82 variables
  • formula class 'formula' containing formula model
  • model.matrix(formula, data) matrix dimension 918 x 48.

how can resolve/prevent error?

as happens, found answer own question while writing question.

the clue estimates categorical variables in est1.qbar exist if level of variables present in data. of variables factor variables not every level represented. caused warning "contrasts dropped factor variable name due missing levels", foolishly ignored.

on other hand, looking @ dimnames(model.matrix.temp)[[2]] shows model matrix has 1 column each level of each factor variable, regardless of whether level of variable present in data. so, although contrasts missing factor levels dropped in terms of estimating coefficients, factor levels still appear in model matrix. means model matrix has more columns length of est1.qbar (the vector of estimated coefficients), matrix multiplication not going work.

the answer here fix factor variables there no unused levels. can done factor() function (as explained here). unfortunately, needs done on original dataset, prior imputation.


Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -