prediction icon indicating copy to clipboard operation
prediction copied to clipboard

plm: within model

Open ghost opened this issue 7 years ago • 5 comments

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 avatar May 08 '17 11:05 ghost

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 avatar May 08 '17 12:05 ghost

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.

ghost avatar Mar 01 '18 12:03 ghost

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

jayur avatar Oct 21 '18 01:10 jayur

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 avatar Apr 17 '22 16:04 tappek

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

tappek avatar Aug 19 '22 11:08 tappek