In the ‘plm’ package blog (2), we’ve gotten regression outputs for both fixed and random effect models. One common question after getting regression output is to figure out which model should be chosen using Hausman test. The fixed effect output is names as “grun.fe” and the random effect output is names as “grun.re”. The function of Hausman test is phtest().
- Hausman test
phtest(grun.fe, grun.re)
The null hypothesis of Hausman Test is that the preferred model is random effects, and the alternative hypothesis is that the model is fixed effects. If p-value is less than 0.05, reject null hypothesis. In this example, p-value is greater than 0.05, so we choose random effects model.
- Test of individual and/or time effects
This is used only after running the pooled OLS model. To test the presence of individual and time effects in the Grunfeld example, we will firstly run a pooled OLS regression
olsmodel <- plm(inv ~ value + capital, data = Grunfeld, model = “pooling”)
#please notice that in this regression, we don’t define panel data but use the original dataset directly because it’s not a panel data analysis
plmtest(olsmodel, effect = “twoways”, type = “ghm”)
Or we could combine the two steps above together, and write syntax as following.
plmtest(inv ~ value + capital, data = Grunfeld, effect = “twoways”, type = “ghm”)