drizopoulos / JMbayes2

Extended Joint Models for Longitudinal and Survival Data
https://drizopoulos.github.io/JMbayes2/
80 stars 23 forks source link

Baseline Hazard #89

Closed berithunsdieck closed 8 months ago

berithunsdieck commented 8 months ago

I want to dig deeper into the risk calculation since my results do not seem to be correct. Therefore I already extracted the estimated longitudinal outcomes for a given time period by using

predict(model_i,
                        newdata = long_data%>%mutate(status2=0, total_months=10),
                        times = seq(11,20),
                        return_newdata = TRUE, n_chains=1,cores=1,
                        type="subject_specific")

Is there a way the extract the estimated baseline hazard given the model "model_1" for the same time period?

drizopoulos commented 8 months ago

The following code illustrates how to calculate the log baseline hazard at the time points t0:

library("JMbayes2")
pbc2.id$status2 <- as.numeric(pbc2.id$status != 'alive')
CoxFit <- coxph(Surv(years, status2) ~ sex, data = pbc2.id)
fm <- lme(log(serBilir) ~ year * sex, data = pbc2, random = ~ year | id)
jointFit <- jm(CoxFit, fm, time_var = "year")

t0 <- c(3, 5, 7)
W0 <- splineDesign(jointFit$control$knots[[1]], t0, 
                   ord = jointFit$control$Bsplines_degree + 1)
log_base_hazard <- c(W0 %*% jointFit$statistics$Mean$bs_gammas)
log_base_hazard