ycroissant / plm

Panel Data Econometrics with R
GNU General Public License v2.0
49 stars 13 forks source link

How to predict, using plm()? #19

Closed OleksiyAnokhin closed 2 years ago

OleksiyAnokhin commented 2 years ago

Hi team, thanks for a great package? I check all possible resources, but do not see how to used predict() or prediction() with plm.

Currently I am trying:

predictions <- predict(plmFit1, panel_df_test)

and get

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

tappek commented 2 years ago

Hi, seems like you were trying to predict using a within model. That case what not implemented - until now in the development version (commits: b81d759332114e3cafa663fc9217da9f0b8c99e4, 93a51bdf7cdf711d75cf6aa994dd82da9ec25e48, 4c44fef2a5fb0f0c23cae32d549069c66ec4c405, cd48d6fff8a620d596a11527572f559b0fc70ce8) .

Be aware that the within case is somewhat special, more so with out-of-sample prediction. The help page ?predict.plm has the details and examples.

Feedback is welcome!

To install the development version from GitHub:

# install.packages("remotes") # remove '#' if pkg 'remotes' is not installed
remotes::install_github("ycroissant/plm")
tappek commented 2 years ago

Some reference asking for predict for plm objects/fixed effects models (partly copied from https://github.com/jacob-long/jtools/issues/97#issuecomment-1092403373):

https://github.com/leeper/prediction/issues/1 https://github.com/leeper/prediction/issues/19 https://github.com/strengejacke/ggeffects/issues/121 https://github.com/strengejacke/sjPlot/issues/594 https://github.com/jacob-long/jtools/issues/97 https://github.com/tidymodels/broom/issues/73 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 https://stackoverflow.com/questions/71894726/how-can-effects-from-fixed-effects-model-in-plm-be-plotted-in-r https://stackoverflow.com/q/65702581/4640346 https://stackoverflow.com/questions/70150063/how-can-i-use-predict-to-a-plm-regression-model https://stackoverflow.com/questions/14427781/how-to-deal-with-na-in-a-panel-data-regression https://stackoverflow.com/a/73127507/4640346 https://stats.stackexchange.com/questions/137923/prediction-with-plm-method https://stats.stackexchange.com/questions/147350/computing-the-predicted-value-from-a-panel-data-model-with-the-plm-r-package?rq=1

tappek commented 2 years ago

Closing this because it is solved.

tappek commented 2 years ago

On CRAN as plm 2.6-2 as of 2022-08-16