Skip to content

Instantly share code, notes, and snippets.

@MJacobs1985
Created November 10, 2022 13:42
Show Gist options
  • Save MJacobs1985/143fdbf1aed5fe04c55fba6e3427157c to your computer and use it in GitHub Desktop.
Save MJacobs1985/143fdbf1aed5fe04c55fba6e3427157c to your computer and use it in GitHub Desktop.
fitLME <- lme(Severity ~ ns(time,3),
random = ~ time | Patientnr,
data=try2,
control=lmeControl(maxIter = 10000),
na.action=na.exclude)
fitSURV<-coxph(Surv(SurvTimeWeek, Event) ~ 1,
data = pancreas2, x = TRUE,
na.action=na.exclude,
cluster = Patientnr)
jointFit1 <- jm(fitSURV,
fitLME,
time_var = "time",
id_var="Patientnr",
data_Surv = pancreas2,
n_iter = 50000L,
n_burnin = 10000L,
n_thin = 5L,
n_chains=4)
try_pred<-try2%>%dplyr::select(Patientnr, time, Severity)%>%arrange(Patientnr, time)
pancreas_pred<-pancreas2%>%dplyr::select(Patientnr, SurvTimeWeek, Event)
nd<-list(newdataL = try_pred,
newdataE = pancreas_pred)
predLong1<-predict(jointFit1,
newdata=nd,
return_newdata = TRUE,
type = "mean_subject")
predLong1%>%
dplyr::arrange(time)%>%
dplyr::select(time, pred_Severity , low_Severity, upp_Severity)%>%
dplyr::group_by(time)%>%
dplyr::summarise(pred_m = mean(pred_Severity, na.rm=TRUE),
ci_l_m = mean(low_Severity, na.rm=TRUE),
ci_h_m = mean(upp_Severity, na.rm=TRUE))%>%
ungroup()%>%
ggplot(., aes(x=time, group=1))+
geom_point(aes(x=time, y=pred_m), color = "red")+
geom_line(aes(y=pred_m), color = "red", size=0.8)+
geom_ribbon(aes(ymin=ci_l_m, ymax=ci_h_m), fill="red", alpha=0.2)+
ggtitle(paste("A")) +
theme_survminer() +
scale_x_continuous("Time",
breaks = c(0,1,2,4,5,7,11,19,31))+
scale_y_continuous("BPI - Severity 0-10 scale",
breaks = seq(0, 10, by = 2))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment