使用R测试cox比例风险中的多重共线性

时间:2014-05-07 12:38:15

标签: r cox-regression

我想通过计算方差膨胀因子(VIF)来评估cox比例风险模型中的多重共线性。像{car}这样的包中的vif函数不接受coxph对象。

有没有办法在R?

中为cox模型计算VIF

1 个答案:

答案 0 :(得分:2)

您在上面的评论中完全正确,VIF仅取决于X值。 'package:car'中的vif - 函数将接受响应vcovcoefmodel.matrix的任何模型,这些模型应与coxph中的library(survival) library(rms) # one possible source for a `vif`-function .... there are many cvif <- vif( testfit1 ) #assumes testfit from : lrm, ols, psm, cph, Rq, Glm, glm 一起响应package:survival',所以假设你有一个fit-object,这会给你带来结果:

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)

testfit1 <- coxph(Surv(healthvalue, rep(1,nrow(y) ) ) ~numberofdrugs+treatment+improved, data= y)

(尚未测试,因为你没有提供任何实际的例子。)

这是在另一个问题中复制示例并修改构造'coxph'对象后的测试用例构造:

enum permission
{
    ReadPermission = 1,
    WritePermission = 2,
    ExecutePermission = 4,
    // etc.
    FullPermissions = ReadPermissions | WritePermissions | ExecutePermission
};

bool hasReadPermission(permission P)
{
    return P & ReadPermission;
}

bool hasWritePermission(permission P)
{
    return P & WritePermission;
}

void addReadPermission(permission& P)
{
    P |= ReadPermission;
}

void removeReadPermission(permission& P)
{
    P &= ~ReadPermission;
}

…

int MyPermissions = FullPermissions;

assert(hasReadPermission(MyPermissions));
assert(hasWritePermission(MyPermissions));

removeReadPermission(MyPermissions);

assert(!hasReadPermission(MyPermissions));