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

Unable to plot interaction of plm output, jtools error message #97

Open
soominoh1 opened this issue Nov 23, 2020 · 4 comments
Open

Unable to plot interaction of plm output, jtools error message #97

soominoh1 opened this issue Nov 23, 2020 · 4 comments

Comments

@soominoh1
Copy link

Hello. I'm trying to plot the interaction of a plm output, but it keeps giving me the following error. I've tried uninstalling and reinstalling R and the packages therein, but to no avail. I googled the error and there seems to be another person who has the same issue (StackOverflow post). Would you be so kind as to help figure out what is happening? Your help is much appreciated. Thank you!

Model run & error:

plm(data = data, formula = y ~ x1 + x2 + x1*x2, model = "within", index = c("grp", "year")))

Error: ~does not appear to be a one- or two-sided formula.
y does not appear to be a one- or two-sided formula.
x1 + x2 + x1 * x2 does not appear to be a one- or two-sided formula.
Backtrace:

interactions::interact_plot(...)
jtools::get_data(model, warn = TRUE, ...)
jtools:::get_lhs(formula)

@soominoh1 soominoh1 added the bug label Nov 23, 2020
@jacob-long
Copy link
Owner

Well I am going to fix the thing that gives the error seen here, but that unfortunately does not get us plotted predictions. As best as I can tell, the predict.plm() function is rather half-baked and people are consistently getting errors trying to use it with within models. Two other packages that do similar things to this one, prediction and ggeffects, report the same issues and neither have resolved the problem.

Going to paste some links here in case I (or someone else) decide to revisit:
leeper/prediction#19
strengejacke/ggeffects#121
https://stackoverflow.com/questions/31954045/r-plotting-panel-model-predictions-using-plm-pglm
https://stackoverflow.com/questions/64892622/plotting-interaction-terms-from-fixed-effects-models-plm
https://stackoverflow.com/questions/71366468/predict-on-test-data-using-plm-package-in-r-and-calculate-rmse-for-test-data

I suspect the solution here is to define a prediction function for plm models within jtools, but that's not something I'm willing to do right now. I don't understand plm (or the generation of model predictions in general) well enough to be confident that I would produce accurate outputs.

@jacob-long jacob-long added the external-bug bug, but problem originates in another package/library label Apr 8, 2022
jacob-long added a commit that referenced this issue Apr 8, 2022
@tappek
Copy link

tappek commented Apr 17, 2022

There is now support for predict for plm's within models in the development version available here: https://github.com/ycroissant/plm

As the within case is special, one likely wants to input a pdata.frame and not a plain data frame; the help page ?predict.plm has the details.

@jacob-long
Copy link
Owner

Thank you @tappek for letting me know! I'll give some thought to the best way to implement.

@jacob-long jacob-long reopened this Apr 19, 2022
@jacob-long jacob-long added enhancement and removed bug external-bug bug, but problem originates in another package/library labels Apr 19, 2022
@tappek
Copy link

tappek commented Aug 20, 2022

For models produced by plm::plm(), there is a predict method available since plm CRAN release version 2.6-2.

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

No branches or pull requests

3 participants