leeper / prediction

Tidy, Type-Safe 'prediction()' Methods
https://cran.r-project.org/package=prediction
Other
89 stars 14 forks source link

plm: within model #19

Open ghost opened 7 years ago

ghost commented 7 years ago
library(prediction)
library(plm)
example(plm)
pred1 <- prediction(wi)
# Error in crossprod(beta, t(X)) : non-conformable arguments

This is probably due to the within model having no intercept.

ghost commented 7 years ago

Please also note that predict() on plm models gives you the fitted values of the (quasi-)demeaned model. My guess is, you want the fitted values of the "overall" model (likewise, residuals() gives you the residuals of the (quasi-)demeaned model). There is an experimental, non-exported function plm:::fitted_exp.plm() for that in the development version of plm.

ghost commented 6 years ago

To handle the default case (use data from model estimation), you could introduce a find_data.plm method that returns NULL as this circumvents the else-branch in predict.plm which seems to be buggy for within models.

jayur commented 5 years ago

Hello,

I'm having the same problem with the prediction on the plm within model. Please let me know if this is a bug in the package or if you have any suggestions for me.

Appreciate your help!

Thanks, Jayashree

tappek commented 2 years ago

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.

tappek commented 1 year ago

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