Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

margins() fails when design matrix is rank deficient #71

Closed
leeper opened this issue Aug 9, 2017 · 4 comments

Comments

Projects
None yet
3 participants
@leeper
Copy link
Owner

commented Aug 9, 2017

Reproducible example:

mtcars$wt2 <- mtcars$wt
m <- lm(mpg ~ wt + wt2, data = mtcars)
m
## 
## Call:
## lm(formula = mpg ~ wt + wt2, data = mtcars)
## 
## Coefficients:
## (Intercept)           wt          wt2  
##      37.285       -5.344           NA
prediction(m)
## Average prediction for 32 observations: 20.0906
## Warning message:
## In predict.lm(model, newdata = out[[i]], type = type, se.fit = TRUE,  :
##   prediction from a rank-deficient fit may be misleading
margins(m)
## Error in jacobian %*% vcov : non-conformable arguments
## In addition: There were 20 warnings (use warnings() to see them)

This can occur when some factor levels are colinear. Presumably the solution is either to fail with a more informative error, or to recognize what terms are being dropped from the model and not attempt to estimate the marginal effects thereof.

@leeper leeper changed the title margins fail when design matrix is rank deficient margins() fails when design matrix is rank deficient Aug 9, 2017

@hbahamonde

This comment has been minimized.

Copy link

commented Nov 16, 2017

I get this error also when estimating a model with interactions and lags, using the plm package.

Error:
Error in crossprod(beta, t(X)) : non-conformable arguments.

@leeper

This comment has been minimized.

Copy link
Owner Author

commented Jan 25, 2018

Closing this for now as I think the issue is fixed for lm/glm. {plm} remains an ongoing source of frustration, which I'll need to resolve separately.

@leeper leeper closed this Jan 25, 2018

@sanseveroj

This comment has been minimized.

Copy link

commented May 12, 2019

Hi I was just wondering if the plm package issues got resolved as I am experiencing this issue.

@leeper

This comment has been minimized.

Copy link
Owner Author

commented May 12, 2019

No, unfortunately not

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.