【问题标题】:Allowing for aliased coefficients when running `grangertest()` in R在 R 中运行 `grangertest()` 时允许使用别名系数
【发布时间】:2021-04-19 01:52:03
【问题描述】:

我目前正尝试在 R/R Studio 中运行格兰杰因果分析。使用函数grangertest() 时,我收到有关混叠系数的错误。据我了解,这是因为变量之间存在完美的多重共线性。

由于有大量的成对比较(例如 200+),我想简单地按照正常运行带有别名系数的 granger,而不是返回错误。根据一个答案here,解决方案是或者是添加集合singular.ok=TRUE,但要么我做错了答案已经过时了。我试过检查文档,但结果是空的。任何帮助将不胜感激。

library(lmtest)
x <- c(0,1,2,3)
y <- c(0,3,6,9)
grangertest(x,y,1) # I want this to run successfully even if there are aliased coefficients. 
grangertest(x,y,1, singular.ok=TRUE) # this also doesn't work 

"Error in waldtest.lm(fm, 2, ...) : 
  there are aliased coefficients in the model"

另外有没有办法标记xy 实际上是别名变量?似乎有一些答案,例如here,但我在让它正常工作时遇到了问题。

alias((x~ y))

提前致谢。

【问题讨论】:

    标签: r statistics time-series regression


    【解决方案1】:

    经过一些调查并向 grangertest 包的创建者发送电子邮件后,他们向我发送了这个解决方案。当 granger 测试不运行时,该解决方案应该在别名变量上运行。当变量没有别名时,解应该给出与正常的格兰杰检验相同的值。

    library(lmtest)
    library(dynlm)
     
    # Some data that is multicolinear
    x <- c(0,1,2,3,4)
    y <- c(0,3,6,9,12)
    
    # Some data that is not multicolinear
    # x <- c(0,125,200,230,777)
    # y <- c(0,3,6,9,200)
    
    # Convert to time series (this is an important step)
    x=ts(x)
    y=ts(y)
    
    # This will run even when the data is multicolinear (but also when it is not)
    # and is functionally the same as running the granger test (which by default uses the waldtest
    
    m1 = dynlm(x ~ L(x, 1:1) + L(y, 1:1))
    m2 = dynlm(x ~ L(x, 1:1))
    result <-anova(m1, m2, test="F")
     
    # This will fail if the data is multicolinear or aliased but should give the same results as the anova otherwise (F value and P value etc)
    #grangertest(y,x,1)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-21
      • 1970-01-01
      • 2018-07-31
      • 1970-01-01
      相关资源
      最近更新 更多