首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >plm方法预测

plm方法预测
EN

Stack Overflow用户
提问于 2015-02-16 18:04:10
回答 1查看 3.2K关注 0票数 3

我使用plm软件包来估计面板数据上的随机效应模型。阅读this question关于plm软件包中的预测的文章让我有些怀疑。它到底是怎么工作的?我尝试了三种替代方法,它们给出了不同的解决方案。为什么?

代码语言:javascript
复制
library(data.table); library(plm)

set.seed(100)
DT <- data.table(CJ(id=c(1,2,3,4), time=c(1:10)))
DT[, x1:=rnorm(40)]
DT[, x2:=rnorm(40)]
DT[, y:=x1 + 2*x2 + rnorm(40)/10 + id]
DT <- DT[!(id=="a" & time==4)] # just to make it an unbalanced panel
setkey(DT, id, time)    

summary(plmFEit <- plm(data=DT, id=c("id","time"), formula=y ~ x1 + x2, model="random"))    
    ###################
    #method 1
    ###################
    # Extract the fitted values from the plm object
    FV <- data.table(plmFEit$model, residuals=as.numeric(plmFEit$residuals))
    FV[, y := as.numeric(y)]
    FV[, x1 := as.numeric(x1)]
    FV[, x2 := as.numeric(x2)]

    DT <- merge(x=DT, y=FV, by=c("y","x1","x2"), all=TRUE)
    DT[, fitted.plm_1 := as.numeric(y) - as.numeric(residuals)]                
    ###################
    #method 2
    ###################        
    # calculate the fitted values 
    DT[, fitted.plm_2 := as.numeric(coef(plmFEit)[1]+coef(plmFEit)[2] * x1 + coef(plmFEit)[3]*x2)]                
    ###################
    #method 3
    ###################
    # using pmodel.response 
    DT$fitted.plm_3 <-pmodel.response(plmFEit,model='random') 
EN

回答 1

Stack Overflow用户

发布于 2015-07-06 19:59:59

方法1:可以更容易地完成:

代码语言:javascript
复制
FV <- data.table(plmFEit$model, residuals=as.numeric(plmFEit$residuals))
FV[ , fitted := y - residuals]

但是,它给出的拟合值与使用merge()的方法相同

方法2: --您正在拟合一个随机效应模型(尽管您将其命名为plmFEit,其中FE通常包含固定的效果)。与方法1相比,您缺少了特性错误项。

方法3: pmodel.response()为您提供响应变量(在本例中为y),但使用指定的转换(随机效果转换(“准降级”))(参见pmodel.response())。

我想,你想要的是方法1。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28547614

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档