【问题标题】:Regression model without predictors using plm in R?在R中使用plm没有预测变量的回归模型?
【发布时间】:2021-09-25 23:48:31
【问题描述】:

我有一个不平衡面板数据表,其中包含变量 IDyearoutcome。每个ID 的数据跨度从 2005 年到 2020 年,尽管每个 ID 不会包含全部 15 年的数据。这是一个示例:

ID, year, outcome
1, 2005, 70
1, 2006, 73
1, 2007, 70
1, 2008, 68
2, 2005, 65
2, 2006, 71
2, 2007, 68
2, 2008, 64
2, 2009, 63
3, 2011, 78
3, 2012, 81
4, 2008, 75

我想运行一个plm 回归模型没有预测变量(即截距上的回归模型)。

我尝试运行以下命令,但收到错误消息“空模型”:

feModel <- plm(damMean ~ 1, data = finalDT, model = "within", index = c("sireID", "year"))

# Error in plm.fit(data, model, effect, random.method, random.models, random.dfcor,  : 
  empty model

这可以在 R 中使用 plm 包吗?

【问题讨论】:

    标签: r regression linear-regression panel plm


    【解决方案1】:

    我认为这不是一个编程问题,而是一个统计问题。此外,我认为这不是关于包“plm”本身的功能的问题,而是这样的 within 模型是否有意义以及是否实施了模型内的技术估计方法。

    模型内的plm(固定效应模型)不包含截距。其他一些统计软件包在其内部模型中有一些人为的截距(最明显的可能是 Stata,但也有 gretl)。您可能需要查看 ?plm::within_intercept 及其引用的文献,以了解有关模型内截距的更多详细信息。

    让我们看看在模型内只有一个截距作为回归量的情况下会发生什么:

    library("plm")
    data("Grunfeld", package = "plm")
    pGrun <- pdata.frame(Grunfeld)
    plm(inv ~ 1, data = pGrun, model = "within") # errors with "empty model"
    
    pGrun$int <- 1 # intercept
    within_int <- Within(pGrun$int) # within transformation of intercept
    # -> all zeros:
    head(within_int)
    ##  1-1935 1-1936 1-1937 1-1938 1-1939 1-1940 
    ##       0      0      0      0      0      0 
    all.equal(as.numeric(within_int), rep(0, 200L), check.attributes = FALSE)
    ##  TRUE
    

    截距的内部变换全为零,因此 plm 关于空模型的错误消息是正常的。 gretl,一个带有模型内截距的计量经济学包,输出这种仅截距模型的估计值:

                 coefficient   std. error   t-ratio    p-value 
      ---------------------------------------------------------
      const        145.958      7.68517      18.99    8.85e-046 ***
    

    这个值是多少?嗯,它是因变量的平均值

    mean(pGrun$inv)
    ##   145.9582
    

    或者,如果您想通过使用 plm 的模型估计得出这个平均值,您可以估计仅使用截距的 "pooling" 模型:

    plm(inv ~ 1, data = pGrun, model = "pooling")
    ##  Model Formula: inv ~ 1
    
    ##  Coefficients:
    ##  (Intercept) 
    ##       145.96 
    

    【讨论】:

    • 非常感谢您的详细回答!关于没有预测变量的回归模型,我有一个更普遍的问题:我们如何解释截距系数的值?
    • 我认为这已经包含在我的答案中:它是因变量的平均值。同样,这不是编程问题。
    • 我还有一个关于这个话题的非编程问题,所以我在这里发了一个帖子:stats.stackexchange.com/questions/535025/…我希望你能帮助我
    猜你喜欢
    • 1970-01-01
    • 2018-05-22
    • 2018-04-05
    • 1970-01-01
    • 2015-11-04
    • 1970-01-01
    • 1970-01-01
    • 2021-12-30
    • 2016-06-02
    相关资源
    最近更新 更多