R

比較重複測量 FE 模型中的組,具有嵌套誤差分量,使用 plm 估計

  • June 16, 2018

我已經估計了一些重複測量的固定效應模型,具有嵌套的誤差分量,基於分組變量,即非嵌套模型,使用plm. 我現在有興趣

  1. 測試完整模型是否顯著不同,即在哪裡是和的完整Females模型是和的完整Males模型
  2. 隨後測試兩組之間選定的回歸係數,即在哪裡是女性在 的回歸係數year1.5,並且是男性的回歸係數year1.5

我將使用以下工作示例來說明情況,

首先,需要一些包,

# install.packages(c("plm","texreg","tidyverse","lmtest"), dependencies = TRUE)
library(plm); library(lmtest); require(tidyverse)

二、一些資料準備,

data(egsingle, package = "mlmRev")
dta <-  egsingle %>% mutate(Female = recode(female,.default = 0L,`Female` = 1L))

三、我為數據中的每個性別估計了一組模型

MoSpc <- as.formula(math ~ Female + size + year)
dfMo = dta %>% group_by(female) %>%
   do(fitMo = plm(update(MoSpc, . ~ . -Female), 
      data = ., index = c("childid", "year", "schoolid"), model="within") )

第四,讓我們看一下兩個估計模型,

texreg::screenreg(dfMo[[2]], custom.model.names = paste0('FE: ', dfMo[[1]]))
#> ===================================
#> FE: Female FE: Male 
#> -----------------------------------
#> year-1.5 0.79 *** 0.88 ***
#> (0.07) (0.10) 
#> year-0.5 1.80 *** 1.88 ***
#> (0.07) (0.10) 
#> year0.5 2.51 *** 2.56 ***
#> (0.08) (0.10) 
#> year1.5 3.04 *** 3.17 ***
#> (0.08) (0.10) 
#> year2.5 3.84 *** 3.98 ***
#> (0.08) (0.10) 
#> -----------------------------------
#> R^2 0.77 0.79 
#> Adj. R^2 0.70 0.72 
#> Num. obs. 3545 3685 
#> ===================================
#> *** p < 0.001, ** p < 0.01, * p < 0.05 #> 

現在,我想測試這兩個(線性 OLS)模型是否顯著不同,參見。上面的第 1 點。我環顧了 SO和互聯網,有些人建議我需要使用plm::pFtest(),也建議在這裡,我已經嘗試過,但我不相信。我會想像一些非嵌套模型的測試,可能的 Cox 測試,lmtest::coxtest但我完全不確定。如果這裡有人可以幫助我。

我試過了,

plm::pFtest(dfMo[[1,2]], dfMo[[2,2]])
# >
# > F test for individual effects
# >
# >data: update(MoSpc, . ~ . - Female)
# >F = -0.30494, df1 = 113, df2 = 2693, p-value = 1
# >alternative hypothesis: significant effects

和,

lmtest::coxtest(dfMo[[1,2]], dfMo[[2,2]])
# > Cox test
# > 
# > Model 1: math ~ size + year
# > Model 2: math ~ size + year
# > Estimate Std. Error z value Pr(>|z|) 
# > fitted(M1) ~ M2 0.32 1.66695 0.1898 0.8494 
# > fitted(M2) ~ M1 -1222.87 0.13616 -8981.1963 <2e-16 ***
# > ---
# > Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
# > Warning messages:
# > 1: In lmtest::coxtest(dfMo[[1, 2]], dfMo[[2, 2]]) :
# > models fitted on different subsets
# > 2: In lmtest::coxtest(dfMo[[1, 2]], dfMo[[2, 2]]) :
# > different dependent variables specified

其次,我有興趣比較兩組之間的回歸係數。比如說,year1.53.04 的估計值是否與 3.17 顯著不同?參照。上述第 2 點。

請詢問以上是否有任何不清楚的地方,我很樂意詳細說明。任何幫助將不勝感激!

我意識到這個問題有點像編程,但我最初是在 SO 中發布的。但是,DWin非常友好地指出該問題屬於 CrossValidated 並將其遷移到此處。

固定效應模型 r plm 嵌套數據 假設檢驗 重複測量 面板數據 混合模式 回歸 面板數據 非嵌套模型 嵌套模型

下面的代碼實現了在Femaledummy 和 year 之間放置交互的做法。底部的 F 測試測試你的 null. 輸出中的 t 統計plm量測試您的空值. 特別是,對於year=1.5,p 值為 0.32。

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

引用自:https://stats.stackexchange.com/questions/351746

comments powered by Disqus