Skip to content

Commit

Permalink
median survival time added to output summary statistics in stan model
Browse files Browse the repository at this point in the history
  • Loading branch information
n8thangreen committed Jul 12, 2024
1 parent 4e3254e commit b99503e
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
2 changes: 2 additions & 0 deletions R/stan_code_blocks.R
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ create_code_skeleton <- function(n_grp) {
cglue_data(ids,
"vector[t_max] S_{id};
vector[nTx] rmst_{id};
vector[nTx] median_{id};
matrix[t_max, nTx] S_{id}_pred;
real mean_{id};
int idx_{id};
Expand Down Expand Up @@ -417,6 +418,7 @@ make_summary_estimates <- function(model, id) {
"// restricted mean survival time
for (i in 1:nTx) {{
rmst_{id}[i] = cf_{id}[i]*t_max + (1 - cf_{id}[i])*rmst_{model}(", params, ", t_max);
median_{id}[i] = median_surv_{model}(", params, ");
}\n\n")
}

Expand Down
36 changes: 36 additions & 0 deletions inst/stan/include/distributions.stan
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@ real rmst_exp (real rate, real tmax) {
return rmst;
}

// median survival time
real median_surv_exp (real rate) {
real tmed;
tmed = log(2)/rate;
return tmed;
}


/**
* weibull
Expand Down Expand Up @@ -123,6 +130,13 @@ real rmst_weibull (real shape, real scale, real tmax) {
return rmst;
}

// median survival time
real median_surv_weibull (real shape, real scale) {
real tmed;
tmed = scale * pow(log(2), 1/shape);
return tmed;
}

/**
* gompertz
*
Expand Down Expand Up @@ -199,6 +213,13 @@ real rmst_gompertz (real shape, real scale, real tmax) {
return rmst;
}

// median survival time
real median_surv_gompertz (real scale, real shape) {
real tmed;
tmed = 1/shape * log(log(2)*shape/scale + 1);
return tmed;
}


/**
* log-logistic
Expand Down Expand Up @@ -270,6 +291,15 @@ real rmst_loglogistic (real scale, real shape, real tmax) {
return rmst;
}

//TODO
// // median survival time
// real median_surv_loglogistic (real scale, real shape) {
// real tmed;
// tmed = ;
// return tmed;
// }


/**
* generalised gamma
*
Expand Down Expand Up @@ -400,6 +430,12 @@ real rmst_lognormal (real mu, real sigma, real tmax) {
return rmst;
}

// median survival time
real median_surv_lognormal (real mu) {
real tmed;
tmed = exp(mu);
return tmed;
}

/**
* combined (non-cured) mortality
Expand Down

0 comments on commit b99503e

Please sign in to comment.