gpt4 book ai didi

r - 有因素时的多重共线性检验

转载 作者:行者123 更新时间:2023-12-01 17:36:30 26 4
gpt4 key购买 nike

是否可以使用虚拟变量检查模型中的多重共线性?假设以下示例

treatment <- factor(rep(c(1, 2), c(43, 41)), levels = c(1, 2), labels = c("placebo", "treated"))
improved <- factor(rep(c(1, 2, 3, 1, 2, 3), c(29, 7, 7, 13, 7, 21)), levels = c(1, 2, 3), labels = c("none", "some", "marked"))
numberofdrugs <- rpois(84, 5)+1
healthvalue <- rpois(84,5)
y <- data.frame(healthvalue,numberofdrugs, treatment, improved)

test <- lm(healthvalue~numberofdrugs+treatment+improved, y)

当我想检查这样的模型中是否出现多重共线性时,我应该做什么?

最佳答案

您可以计算VIF让您的预测变量量化多重共线性的量:

library(car)
vif(test)
GVIF Df GVIF^(1/(2*Df))
numberofdrugs 1.035653 1 1.017670
treatment 1.224984 1 1.106790
improved 1.193003 2 1.04510

关于r - 有因素时的多重共线性检验,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6162662/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com