# NOT RUN {
library(WR)
head(non_ischemic)
id_unique <-unique(non_ischemic$ID)
# Randomly sample 200 subjects from non_ischemic data
set.seed(2019)
id_sample <- sample(id_unique, 200)
non_ischemic_reduce <- non_ischemic[non_ischemic$ID %in% id_sample, ]
# Use the reduced non_ischemic data for analysis
nr <- nrow(non_ischemic_reduce)
p <- ncol(non_ischemic_reduce)-3
ID <- non_ischemic_reduce[,"ID"]
time <- non_ischemic_reduce[,"time"]
status <- non_ischemic_reduce[,"status"]
Z <- as.matrix(non_ischemic_reduce[,4:(3+p)],nr,p)
## unstratified analysis
pwreg.obj <- pwreg(time=time,status=status,Z=Z,ID=ID)
print(pwreg.obj)
# }
# NOT RUN {
## stratified PW by sex
sex<-Z[,3]
## take out sex from the covariate matrix
Z1<-Z[,-3]
pwreg.obj1 <- pwreg(time=time,status=status,Z=Z1,ID=ID,strata=sex)
print(pwreg.obj1)
# }
Run the code above in your browser using DataLab