使用`plm()`估计具有嵌套结构的重复测量随机效应模型 [英] estimate a repeated measures random effects model with a nested structure using `plm()`

查看:142
本文介绍了使用`plm()`估计具有嵌套结构的重复测量随机效应模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用包?

Is it possible to estimate a repeated measures random effects model with a nested structure using plm() from the plm package?

我知道

此问题的启发.首先是一些必需的软件包和数据,

Here's my minimal working example, inspired by this question. First some required packages and data,

# install.packages(c("plm", "lme4", "texreg", "mlmRev"), dependencies = TRUE)
data(egsingle, package = "mlmRev")

数据集egsingle是一个不平衡的面板,由五个时间点上的6021所学校的1721名学童组成.有关详细信息,请参见?mlmRev::egsingle

the data-set egsingle is a unbalanced panel consisting of 1721 school children, grouped in 60 schools, across five time points. For details see ?mlmRev::egsingle

一些灯光数据管理

dta <- egsingle
dta$Female <- with(dta, ifelse(female == 'Female', 1, 0))

也是相关数据的一小段

dta[118:127,c('schoolid','childid','math','year','size','Female')]
#>     schoolid   childid   math year size Female
#> 118     2040 289970511 -1.830 -1.5  502      1
#> 119     2040 289970511 -1.185 -0.5  502      1
#> 120     2040 289970511  0.852  0.5  502      1
#> 121     2040 289970511  0.573  1.5  502      1
#> 122     2040 289970511  1.736  2.5  502      1
#> 123     2040 292772811 -3.144 -1.5  502      0
#> 124     2040 292772811 -2.097 -0.5  502      0
#> 125     2040 292772811 -0.316  0.5  502      0
#> 126     2040 293550291 -2.097 -1.5  502      0
#> 127     2040 293550291 -1.314 -0.5  502      0

现在,在很大程度上依靠 Robert Long的答案,这就是我如何随机估计重复措施的方法使用来自软件包,

Now, relying heavily on Robert Long's answer, this is how I estimate a repeated measures random effects model with a nested structure using lmer() from the lme4 package,

dta$year <- as.factor(dta$year)
require(lme4)
Model.1 <- lmer(math ~ Female + size + year + (1 | schoolid /childid), dta)
# summary(Model.1)

我在 man 页面中查找了plm(),它有一个索引命令index,但是只需要一个索引和时间,即index = c("childid", "year"),而忽略schoolid模型将如下所示,

I looked in man page for plm() and it has an indexing command, index, but it only takes a single index and time, i.e., index = c("childid", "year"), ignoring the schoolid the model would look like this,

dta$year <- as.numeric(dta$year) 
library(plm)
Model.2 <- plm(math~Female+size+year, dta, index = c("childid", "year"), model="random")
# summary(Model.2)

总结问题

如何或者甚至有可能使用包?

下面是两个模型的实际估算结果,

Below is the actual estimation results form the two models,

# require(texreg)
names(Model.2$coefficients) <- names(coefficients(Model.1)$schoolid) #ugly!
texreg::screenreg(list(Model.1, Model.2), digits = 3)  # pretty! 
#> ==============================================================
#>                                    Model 1        Model 2     
#> --------------------------------------------------------------
#> (Intercept)                           -2.693 ***    -2.671 ***
#>                                       (0.152)       (0.085)   
#> Female                                 0.008        -0.025    
#>                                       (0.042)       (0.046)   
#> size                                  -0.000        -0.000 ***
#>                                       (0.000)       (0.000)   
#> year-1.5                               0.866 ***     0.878 ***
#>                                       (0.059)       (0.059)   
#> year-0.5                               1.870 ***     1.882 ***
#>                                       (0.058)       (0.059)   
#> year0.5                                2.562 ***     2.575 ***
#>                                       (0.059)       (0.059)   
#> year1.5                                3.133 ***     3.149 ***
#>                                       (0.059)       (0.060)   
#> year2.5                                3.939 ***     3.956 ***
#>                                       (0.060)       (0.060)   
#> --------------------------------------------------------------
#> AIC                                16590.715                  
#> BIC                                16666.461                  
#> Log Likelihood                     -8284.357                  
#> Num. obs.                           7230          7230        
#> Num. groups: childid:schoolid       1721                      
#> Num. groups: schoolid                 60                      
#> Var: childid:schoolid (Intercept)      0.672                  
#> Var: schoolid (Intercept)              0.180                  
#> Var: Residual                          0.334                  
#> R^2                                                  0.004    
#> Adj. R^2                                             0.003    
#> ==============================================================
#> *** p < 0.001, ** p < 0.01, * p < 0.05    

推荐答案

基于)方法,即random.method = "walhus",用于估计方差分量,

Based on Helix123's comment I wrote the following model specification for a repeated measures random effects model with a nested structure, in plm() from the plm package using Wallace and Hussain's (1969) method, i.e. random.method = "walhus", for estimation of the variance components,

p_dta <- pdata.frame(dta, index = c("childid", "year", "schoolid"))        
Model.3 <- plm(math ~ Female + size + year, data = p_dta, model = "random",
               effect = "nested", random.method = "walhus")

在下面的Model.3中看到的结果与Model.1中的估计值几乎一样,正如我所期望的那样.只有截距略有不同(请参见下面的输出).

The results, seen in Model.3 below, is as close to identical, to the estimates in Model.1, as I could expect. Only the intercept is slightly different (see output below).

我是根据Baltagi,Song和Jung( 2001 ).在Baltagi,Song和Jung( 2001 )中,以差异为例首先使用Swamy和Arora( 1972 )(即random.method = "swar"),然后使用使用华莱士和侯赛因( 1969 ).只有Nerlove( 1971 )转换无法使用Song and Jung( 2001 )-数据.只有华莱士和侯赛因( 1969 )的方法才能使用egsingle收敛数据集.

I wrote the above based on the example from Baltagi, Song and Jung (2001) provided in ?plm. In the Baltagi, Song and Jung (2001)-example the variance components are estimated first using Swamy and Arora (1972), i.e. random.method = "swar", and second with using Wallace and Hussain's (1969). Only the Nerlove (1971) transformation does not converge using the Song and Jung (2001)-data. Whereas it was only Wallace and Hussain's (1969)-method that could converge using the egsingle data-set.

对此有任何权威的参考文献.我将继续努力.

names(Model.3$coefficients) <- names(coefficients(Model.1)$schoolid) 
texreg::screenreg(list(Model.1, Model.3), digits = 3,
                  custom.model.names = c('Model 1', 'Model 3')) 
#> ==============================================================
#>                                    Model 1        Model 3     
#> --------------------------------------------------------------
#> (Intercept)                           -2.693 ***    -2.697 ***
#>                                       (0.152)       (0.152)   
#> Female                                 0.008         0.008    
#>                                       (0.042)       (0.042)   
#> size                                  -0.000        -0.000    
#>                                       (0.000)       (0.000)   
#> year-1.5                               0.866 ***     0.866 ***
#>                                       (0.059)       (0.059)   
#> year-0.5                               1.870 ***     1.870 ***
#>                                       (0.058)       (0.058)   
#> year0.5                                2.562 ***     2.562 ***
#>                                       (0.059)       (0.059)   
#> year1.5                                3.133 ***     3.133 ***
#>                                       (0.059)       (0.059)   
#> year2.5                                3.939 ***     3.939 ***
#>                                       (0.060)       (0.060)   
#> --------------------------------------------------------------
#> AIC                                16590.715                  
#> BIC                                16666.461                  
#> Log Likelihood                     -8284.357                  
#> Num. obs.                           7230          7230        
#> Num. groups: childid:schoolid       1721                      
#> Num. groups: schoolid                 60                      
#> Var: childid:schoolid (Intercept)      0.672                  
#> Var: schoolid (Intercept)              0.180                  
#> Var: Residual                          0.334                  
#> R^2                                                  0.000    
#> Adj. R^2                                            -0.001    
#> ==============================================================
#> *** p < 0.001, ** p < 0.01, * p < 0.05#> 

这篇关于使用`plm()`估计具有嵌套结构的重复测量随机效应模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆