简体   繁体   中英

Plotting interaction terms from fixed effects models (plm)

I'm trying to plot interaction effects from a fixed effects model. For some reason, I always get the same error message: Error in crossprod(beta, t(X)): non-conformable arguments

First I thought this was only my data (maybe multicollinearity) but the same problem happens when using data included with the plm package. Here's an example:

library(plm)
library(sjPlot)

data("Grunfeld", package="plm")
grun.fe <- plm(inv~value+capital, data = Grunfeld, model = "within")

plot_model(grun.fe, type = "pred", terms = c("value","capital")) 

In fact, if I want to do any sort of prediction with any estimated fixed effects model (for example using predict ), I get the same error message. Random effects and pooled panel models work fine, it's only with fixed effects.

I wonder if this is to do with the way plm stores the fixed effects result matrix but couldn't find any help from the plm manual. The same task runs fine in Stata using xtreg for example with margins and marginsplot. Any help would be much appreciated!

For models produced by plm::plm() , there is a predict method available since plm version 2.6-2 as on CRAN. Thus, your code now works. The prediction of FE models is better when a pdata.frame is used (compared to a plain data.frame) as the prediction then can be based using the effects per individual/time. The help page ?predict.plm has examples for what that means and further explains the warning given by the code (see below).

The author of sjPlot could adjust plot_model for plm objects to use pdata.frames in predict (since the new plm version).

library(plm)
library(sjPlot)

data("Grunfeld", package="plm")
grun.fe <- plm(inv~value+capital, data = Grunfeld, model = "within")

plot_model(grun.fe, type = "pred", terms = c("value","capital")) 
#> Warning in predict.plm(model, newdata = fitfram, type = pr.type, level =
#> level, : Data supplied in argument 'newdata' is not a pdata.frame; weighted mean
#> of fixed effects as in original model used for prediction, see ?predict.plm.
#> Could not compute variance-covariance matrix of predictions. No confidence intervals are returned.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM