jthaman / ciTools

An R Package for Quick Uncertainty Intervals
GNU General Public License v3.0
106 stars 9 forks source link

Rank-deficient models in lme4 produce errors #21

Open matthewravery opened 6 years ago

matthewravery commented 6 years ago

Warning message produced by lme4::lmer

fixed-effect model matrix is rank deficient so dropping 7 columns / coefficients.

Result with add_ci/add_pi

Error in X %*% vcovBetaHat : non-conformable arguments

Likely what is happening is that lmer is taking your specified model, noticing that the covariance matrix won't properly invert, and is thus dropping some columns so that it behaves better. When ciTools tries to do the same thing, it attempts to use the original, un-reduced matrix and thus produces the above error.

jthaman commented 6 years ago

Good catch! Some thoughts:

  1. I'm surprised lmer doesn't throw an error if the model matrix is not full rank.
  2. I wonder how lmer chooses which columns to drop.
  3. Can you provide a small reproducible example?
jthaman commented 6 years ago

I have opened a new branch that addresses this bug. But now I'm wondering if we need to implement similar fixes for lm, glm, etc. 41f3c65d6e257c68dbb68d55cb4eaad3701342a1