2014-01-26 33 views
0

警告信息,我有一個問題,運行此PLM模型:PLM模式 「內」 - R中

我的數據(例如):

country=c(1,1,1,2,2,2,3,3,3) 
    year=c(1,2,3,1,2,3,1,2,3) 
    a=c(1,4,6,3,5,8,4,5,7) 
    b=c(8,5,7,2,7,4,9,7,1) 
    matrix=cbind(country, year, a, b) 
    matrix=plm.data(matrix) 

我運行如下回歸方程:

reg=plm(a~year+b, data=matrix, index=NULL, model="within") 
    summary(reg) 

,並獲得以下警告信息:[1]

Warning messages: 
    1: In if (is.na(le)) { : 
     the condition has length > 1 and only the first element will be used 
    2: In if (is.na(le)) " __no length(.)__ " else if (give.length) { : 
     the condition has length > 1 and only the first element will be used 
    3: In if (le > 0) paste0("[1:", paste(le), "]") else "(0)" : 
     the condition has length > 1 and only the first element will be used 

有什麼不對?

+0

該代碼在pkg:plm版本1.4-0中用'plm.data'引出錯誤。 –

+0

@ user3237581:你發現了更多關於這個錯誤的信息嗎?我對此非常感興趣。 – majom

回答

1

我有同樣的問題,並找到了答案(here

當這樣的載體給出這樣的警告:

le<-c(4,2,6,5) 

在試驗中使用這樣的:

if(is.na(le)) ... 

R僅查看測試向量中的第一個值,但會警告您有其他未經測試的值。如果測試:

if(is.na(le[1])) 

這並不重要,如果「了」只有一個值或一個以上的,你 沒有得到警告。它通常不會弄亂任何東西。

1

這是因爲str檢查其對象的長度,plm使用來自Formula包的擴展公式。現在,Formula:::length.Formula返回一個向量,而不是一個數字,這會導致警告,正如simon_icl所解釋的那樣。雖然你自己可能不會調用str,但是也許你的IDE,比如RStudio,可能會用它來顯示工作區中對象的對象結構。