【问题标题】:VIFs returning aliased coefficients in RVIF 返回 R 中的混叠系数
【发布时间】:2015-03-05 18:32:01
【问题描述】:

我想知道是否有人可以帮助我解决以下问题。当我在各种解释变量之间进行 VIF 分析时,会出现以下错误消息。

test <-vif(lm(Spring_Autumn ~ Oct + Nov + Dec + Jan + Feb +  
 Mar + Apr + May + Jun + Jul + Aug + Sep + X1min + X3min +   X7min + X30min + X90min + X1max + X3max + X7max + X30max + X90max + BF + Dmin + Dmax+ LP + LPD + HP + HPD + RR + FR + Rev, data = IHA_stats))


Error in vif.default(lm(Spring_Autumn ~ Oct + Nov + Dec + Jan + Feb +  : 
  there are aliased coefficients in the model

在线阅读后,我似乎有两个完全共线的变量,但我看不到通过 cor 函数完全相关的 2 个变量,现在不知道如何解释别名函数表。有没有人有什么建议?先感谢您。

James(原始数据集的链接粘贴在下面,但如果访问该链接有任何问题,可以通过电子邮件发送)。

https://www.dropbox.com/s/nqmagu9m3mjhy9n/IHA_statistics.csv?dl=0

【问题讨论】:

  • 我不确定完美的共线性是你的问题(没有做同样的阅读),但如果是这样,它可能不仅仅是两个变量之间,例如如果LPLPDHP 的某种线性组合,则成对相关都不会为1,但存在共线性。您应该能够至少说出其中一个变量,因为如果存在完美共线性,则估计系数将为NA
  • 感谢您的回复罗曼。你是对的,有一个变量是其他两个变量的线性乘积,因此 VIF 不起作用。

标签: mysql r statistics


【解决方案1】:

使用 R 中的“别名”函数查看哪些变量是线性相关的。去掉因变量,vif函数应该可以正常工作了。

formula <- as.formula(Spring_Autumn ~ Oct + Nov + Dec + Jan + Feb + Mar + Apr + May + Jun + Jul + Aug + Sep + X1min + X3min +   X7min + X30min + X90min + X1max + X3max + X7max + X30max + X90max + BF + Dmin + Dmax+ LP + LPD + HP + HPD + RR + FR + Rev, data = IHA_stats)
fit <-lm(formula)

#the linearly dependent variables
ld.vars <- attributes(alias(fit)$Complete)$dimnames[[1]]

#remove the linearly dependent variables variables
formula.new <- as.formula(
    paste(
        paste(deparse(formula), collapse=""), 
        paste(ld.vars, collapse="-"),
        sep="-"
    )
)

#run model again
fit.new <-lm(formula.new)
vif(fit.new)

注意:如果您有自动生成的虚拟变量与其他变量相同,这将不起作用。变量名弄乱了。您可以创建自己的 hack 来绕过它。

【讨论】:

    猜你喜欢
    • 2018-04-30
    • 2020-05-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多