## R code examples for IPW analyses of nested case-control studies and case-cohort studies ## Materials for the tutorial seminar in the 27th Annual Scientific Meeting of the Japan Epidemiological Association ## 1. Nested case-control studies require(multipleNCC) data(CVD_Accidents) attach(CVD_Accidents) CVD_Accidents$samplestat2 <- samplestat CVD_Accidents$samplestat2[samplestat==3] <- 2 wpl(Surv(agestart,agestop,dead24) ~ factor(smoking3gr)+bmi+factor(sex), data=CVD_Accidents, samplestat=CVD_Accidents$samplestat2, m=1, match.var=cbind(CVD_Accidents$sex, CVD_Accidents$bmi), match.int=c(0,0,-2,2), weight.method="KM") # IPW analysis by design weights wpl(Surv(agestart,agestop,dead24) ~ factor(smoking3gr)+bmi+factor(sex), data=CVD_Accidents, samplestat=CVD_Accidents$samplestat2, m=1, match.var=cbind(CVD_Accidents$sex, CVD_Accidents$bmi), match.int=c(0,0,-2,2), weight.method="glm") # IPW analysis by estimated weights ## 2. Case-cohort studies require(survival) ## The complete Wilms Tumor Data ## (Breslow and Chatterjee, Applied Statistics, 1999) ## subcohort selected by simple random sampling. ## subcoh <- nwtco$in.subcohort selccoh <- with(nwtco, rel==1|subcoh==1) ccoh.data <- nwtco[selccoh,] ccoh.data$subcohort <- subcoh[selccoh] ## central-lab histology ccoh.data$histol <- factor(ccoh.data$histol,labels=c("FH","UH")) ## tumour stage ccoh.data$stage <- factor(ccoh.data$stage,labels=c("I","II","III","IV")) ccoh.data$age <- ccoh.data$age/12 # Age in years ## ## Standard case-cohort analysis: simple random subcohort ## fit.ccP <- cch(Surv(edrel, rel) ~ stage + histol + age, data =ccoh.data, subcoh = ~subcohort, id=~seqno, cohort.size=4028) summary(fit.ccP) # Prentice method fit.ccSP <- cch(Surv(edrel, rel) ~ stage + histol + age, data =ccoh.data, subcoh = ~subcohort, id=~seqno, cohort.size=4028, method="SelfPren") summary(fit.ccSP) # Self-Prentice method fit.ccLY <- cch(Surv(edrel, rel) ~ stage + histol + age, data =ccoh.data, subcoh = ~subcohort, id=~seqno, cohort.size=4028, method="LinYing") summary(fit.ccLY) # Lin-Ying method ## ## (post-)stratified on instit ## stratsizes <- table(nwtco$instit) fit.BI <- cch(Surv(edrel, rel) ~ stage + histol + age, data =ccoh.data, subcoh = ~subcohort, id=~seqno, stratum=~instit, cohort.size = stratsizes, method="I.Borgan") summary(fit.BI) # Borgan's type-I estimator fit.BII <- cch(Surv(edrel, rel) ~ stage + histol + age, data =ccoh.data, subcoh = ~subcohort, id=~seqno, stratum=~instit, cohort.size = stratsizes, method="II.Borgan") summary(fit.BII) # Borgan's type-II estimator