您可以使用 iptwsurvival 包中的 DIVAT 数据集执行此操作:
##Generate ID
DIVAT$ID<- 1:nrow(DIVAT)
我们可以将 IPTW 计算为平均治疗效果,而不是作为治疗中的平均治疗效果
DIVAT$p.score <- glm(retransplant ~ age + hla, data = DIVAT,
family = "binomial")$fitted.values
DIVAT$ate.weights <- with(DIVAT, retransplant * 1/p.score + (1-retransplant)* 1/(1-p.score))
比我们可以执行 cox 回归
####COX without weight
coxph(Surv(times, failures)~ retransplant, data=DIVAT)->fit
summary(fit)
增加重量很容易
###COX with weight naive model
coxph(Surv(times, failures)~ retransplant, data=DIVAT, weights = ate.weights)->fit
summary(fit)
###COX with weight and robust estimation
coxph(Surv(times, failures)~ retransplant + cluster(ID), data=DIVAT, weights = ate.weights)->fit
summary(fit)
然而,以这种方式,标准误差的估计是有偏差的(请参阅 Austin, Peter C.“Variance estimation when using inverse probability of treatment weighting (IPTW) with Survival analysis.” Statistics in Medicine 35.30 (2016): 5642-5655。 )。奥斯汀建议依靠引导估计器。但是我也很累,因为我无法找到执行此类分析的方法。如果您找到任何答案,请告诉我。