Jam*_*ite 2 mysql statistics r
我想知道是否有人可以帮助我解决以下问题。当我在各种解释变量之间进行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
Run Code Online (Sandbox Code Playgroud)
在线阅读后,似乎我有两个变量完全共线,但是我看不到2个变量通过cor函数完全相关,并且现在不知道如何解释别名函数表。有没有人有什么建议?先感谢您。
James(原始数据集的链接粘贴在下面,但如果访问此文件有任何问题,可以通过电子邮件发送)。
https://www.dropbox.com/s/nqmagu9m3mjhy9n/IHA_statistics.csv?dl=0
Ste*_*aca 12
使用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)
Run Code Online (Sandbox Code Playgroud)
注意:在自动生成的虚拟变量与其他变量相同的情况下,这将不起作用。变量名称搞砸了。您可以创建自己的hack来解决它。
| 归档时间: |
|
| 查看次数: |
10261 次 |
| 最近记录: |