plm model“within” - R中的警告消息

时间:2014-01-26 13:53:34

标签: r warnings plm

我在运行这个plm模型时遇到问题:

我的数据是(示例):

    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

有什么问题?

2 个答案:

答案 0 :(得分:1)

我遇到了同样的问题并找到了答案(here

当这样的矢量:

时会发出此警告
le<-c(4,2,6,5)

用于这样的测试:

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

R仅查看测试向量中的第一个值,但警告 您还有其他未经测试的值。如果测试是:

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

“le”只有一个值或多于一个并且你是没关系的 不要收到警告。它通常不会弄乱任何东西。

答案 1 :(得分:1)

这是因为str检查其对象的长度,plm使用Formula包中的扩展公式。现在,Formula:::length.Formula返回一个向量而不是一个数字,这会导致警告,如simon_icl所解释的那样。虽然您可能不会自己调用str,但您的IDE(例如RStudio)可能会使用它来显示工作区中对象的对象结构。