以下代码回答了Cross Validated The question there also about test (joint) hypothesis in routine中的一个类似问题。plm
将代码应用于您的问题应该很简单。
library(plm) # Use plm
library(car) # Use F-test in command linearHypothesis
library(tidyverse)
data(egsingle, package = 'mlmRev')
dta <- egsingle %>% mutate(Female = recode(female, .default = 0L, `Female` = 1L))
plm1 <- plm(math ~ Female * (year), data = dta, index = c('childid', 'year', 'schoolid'), model = 'within')
# Output from `summary(plm1)` --- I deleted a few lines to save space.
# Coefficients:
# Estimate Std. Error t-value Pr(>|t|)
# year-1.5 0.8842 0.1008 8.77 <2e-16 ***
# year-0.5 1.8821 0.1007 18.70 <2e-16 ***
# year0.5 2.5626 0.1011 25.36 <2e-16 ***
# year1.5 3.1680 0.1016 31.18 <2e-16 ***
# year2.5 3.9841 0.1022 38.98 <2e-16 ***
# Female:year-1.5 -0.0918 0.1248 -0.74 0.46
# Female:year-0.5 -0.0773 0.1246 -0.62 0.53
# Female:year0.5 -0.0517 0.1255 -0.41 0.68
# Female:year1.5 -0.1265 0.1265 -1.00 0.32
# Female:year2.5 -0.1465 0.1275 -1.15 0.25
# ---
xnames <- names(coef(plm1)) # a vector of all independent variables' names in 'plm1'
# Use 'grepl' to construct a vector of logic value that is TRUE if the variable
# name starts with 'Female:' at the beginning. This is generic, to pick up
# every variable that starts with 'year' at the beginning, just write
# 'grepl('^year+', xnames)'.
picked <- grepl('^Female:+', xnames)
linearHypothesis(plm1, xnames[picked])
# Hypothesis:
# Female:year - 1.5 = 0
# Female:year - 0.5 = 0
# Female:year0.5 = 0
# Female:year1.5 = 0
# Female:year2.5 = 0
#
# Model 1: restricted model
# Model 2: math ~ Female * (year)
#
# Res.Df Df Chisq Pr(>Chisq)
# 1 5504
# 2 5499 5 6.15 0.29