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

Model Support Request: plm::plm() models #140

Closed
ddsjoberg opened this issue Jan 2, 2022 · 3 comments · Fixed by #141
Closed

Model Support Request: plm::plm() models #140

ddsjoberg opened this issue Jan 2, 2022 · 3 comments · Fixed by #141

Comments

@ddsjoberg
Copy link
Collaborator

This stackoverflow post is asking about support for plm::plm() models.
https://stackoverflow.com/questions/70560374

I've never used that package/model before. I'll see if I can submit a PR with support for the models tonight.

library(broom.helpers)
data("Grunfeld", package = "plm")

model <- plm::plm(inv ~ value + capital, data = Grunfeld, model = "within", index = c("firm", "year"))
model
#> 
#> Model Formula: inv ~ value + capital
#> 
#> Coefficients:
#>   value capital 
#> 0.11012 0.31007

broom::tidy(model)
#> # A tibble: 2 x 5
#>   term    estimate std.error statistic  p.value
#>   <chr>      <dbl>     <dbl>     <dbl>    <dbl>
#> 1 value      0.110    0.0119      9.29 3.92e-17
#> 2 capital    0.310    0.0174     17.9  2.22e-42

tidy_plus_plus(model)
#> Error: Tibble columns must have compatible sizes.
#> * Size 2: Existing data.
#> * Size 3: Column `variable`.
#> i Only values of size one are recycled.

Created on 2022-01-02 by the reprex package (v2.0.1)

@ddsjoberg
Copy link
Collaborator Author

UPDATE: The issue root is that the plm() function does not return an intercept. I was able to add model_identify_variables.plm() that fixed the issue with the missing intercept. But I got stuck with a missing reference row. When you get a chance, can you take a look?

@larmarange
Copy link
Owner

larmarange commented Jan 3, 2022 via email

@larmarange
Copy link
Owner

OK, I have identified the issue. By default, plm:::model.matrix.plm() removes constant columns (i.e. the intercept) resulting in a bug when assigning variable (because the assign attribute was not updated accordingly).

model_get_model_matrix.plm <- function(model, ...) {
  stats::model.matrix(model, cstcovar.rm = "none", ...)
}

should be enough to fix the bug

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants