3

plm パッケージを使用して、パネル データのランダム効果モデルを推定しています。plm パッケージの予測に関するこの質問を読むと、疑問が生じます。それはどのように正確に機能しますか?私は3つの代替方法を試しましたが、それらは異なる解決策を提供します. なんで ?

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') 
4

1 に答える 1

2

方法 1: これは簡単に実行できます。

FV <- data.table(plmFEit$model, residuals=as.numeric(plmFEit$residuals))
FV[ , fitted := y - residuals]

ただし、アプローチの場合と同じ適合値が得られますmerge()

方法 2: ランダム効果モデルを当てはめます (ただし、FE は通常固定効果を意味する plmFEit と名付けます)。方法 1 と比較すると、固有のエラー用語がありません。

方法 3: pmodel.response()応答変数 (この場合はy) が得られますが、指定された変換 (ランダム効果変換 (「準侮辱」)) が適用されます (「参考文献」を参照pmodel.response())。

あなたが望むものは方法1で与えられると思います。

于 2015-07-06T19:59:59.890 に答える