mysql - VIF 在 R 中返回别名系数

标签 mysql r statistics

我想知道是否有人可以帮助我解决以下问题。当我在各种解释变量之间进行 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 函数完全相关,现在不知道如何解释别名函数表。有没有人有什么建议?先感谢您。

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

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

最佳答案

使用 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 来绕过它。

关于mysql - VIF 在 R 中返回别名系数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28885160/

相关文章:

php - 如何检查 session 是否已启动并重定向用户?

ec2 amazon 实例上的 mysql 尝试使用错误的用户登录

r - 如何使因子名称出现在R中的ifelse语句中?

r - 如何更新这个过时的示例,以便 ggplot2 不会给出 "error: use theme instead"

r - 使用 ggplot2 的多面 qqplots

r - 有没有办法让 R 脚本在收到错误消息后继续执行而不是停止执行?

php - 我如何以提供相同输出的方式重写它

r - 使用 dplyr 对 R 中不同列(和不同行位置)的行进行运算

r - 使用正态分布计算概率。和 R 中的 t 分布

mysql - 使用php导入mysql blob数据