# NOT RUN {
## Load Mayo Clinic Primary Biliary Cirrhosis Data
library(survival)
library(tableeasy)
data(pbc)
## Check variables
head(pbc)
##The censored data is not discussed here
pbc_full <- subset(pbc,status!=0)
pbc_full$status <- pbc_full$status-1
## Make categorical variables factors
varsToFactor <- c('status','trt','ascites','hepato','spiders','edema','stage','sex')
pbc_full[varsToFactor] <- lapply(pbc_full[varsToFactor], factor)
## Moderator variables
adj_pbc <- c('age','alk.phos','ast')
## Smooth curve of General linear regression:
gam <- smooth_curve(x='albumin',
y='bili',
adj=adj_pbc,
data=pbc_full)
plot(gam$gam,se=TRUE,rug=TRUE,shift=gam$shift)
## Smooth curve of logistic regression:
gam <- smooth_curve(x = 'albumin',
y = 'status',
adj = adj_pbc,
split_var ='age',
div = c(45),
data = pbc_full)
plot(gam$gam[[1]],se=FALSE,rug=TRUE,xlim=c(2,4.5),ylab = 'Adjusted ln ORs for death')
oldpar <- par(new=TRUE)
plot(gam$gam[[2]],se=FALSE,rug=TRUE,xlim=c(2,4.5),ylab = 'Adjusted ln ORs for death',lty=2)
on.exit(par(oldpar))
## Smooth curve of conditional logistic regression:
pbc_full <- data.frame(pbc_full,'ytime'=1)
gam <- smooth_curve(x ='albumin',
y_time = 'ytime',
y = 'status',
adj = adj_pbc,
strata = 'trt',
data = pbc_full)
termplot(gam,term =c(1),col.term ="black",col.se = "black",se=TRUE,rug=FALSE,
ylab="Log ORs for death")
## Smooth curve of Cox proportional hazards regression:
gam <- smooth_curve(x ='albumin',
y_time = 'time',
y = 'status',
adj = adj_pbc,
data = pbc_full)
termplot(gam,term =c(1),col.term ="black",col.se = "black",se=TRUE,rug=FALSE)
# }
Run the code above in your browser using DataLab