VIF返回R中的别名系数 [英] VIFs returning aliased coefficients in R

查看:1186
本文介绍了VIF返回R中的别名系数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I was wondering if anyone could help me with the following problem. When I conduct a VIF analysis between various explanatory variables it comes up with the following error messeage.

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函数将两个变量完美相关,并且现在不知道如何解释别名函数表.有没有人有什么建议?先感谢您.

After reading online it would seem I have two variables that are perfectly collinear, but I couldn't see 2 variables perfectly correlated through the cor function and don't now how to interpret an alias function table. Does anyone have any suggestions? Thank you in advance.

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

James (a link to the original dataset is pasted below but can email if there are any issues with accessing this).

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

推荐答案

在R中使用'alias'函数来查看哪些变量与线性相关.删除因变量,vif函数应该可以正常工作.

Use the 'alias' function in R to see which variables are linearly dependent. Remove the dependent variables and the vif function should work correctly.

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来解决它.

NOTE: This will not work in the case that you have auto generated dummy variables that are identical to other variables. The variable names get messed up. You can create your own hack to get around it.

这篇关于VIF返回R中的别名系数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆