Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into 402-individual-loo
Browse files Browse the repository at this point in the history
  • Loading branch information
gowerc committed Aug 20, 2024
2 parents 5d62acf + 31c82a1 commit 8bba385
Show file tree
Hide file tree
Showing 15 changed files with 428 additions and 18 deletions.
4 changes: 4 additions & 0 deletions R/LongitudinalClaretBruno.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ NULL
#' @param sigma (`Prior`)\cr for the variance of the longitudinal values.
#'
#' @param centred (`logical`)\cr whether to use the centred parameterization.
#' @param scaled_variance (`logical`)\cr whether the variance should be scaled by the expected value
#' (see the "Statistical Specifications" vignette for more details)
#'
#' @export
LongitudinalClaretBruno <- function(
Expand All @@ -55,11 +57,13 @@ LongitudinalClaretBruno <- function(

sigma = prior_lognormal(log(0.1), 0.5),

scaled_variance = TRUE,
centred = FALSE
) {

sf_model <- StanModule(decorated_render(
.x = read_stan("lm-claret-bruno/model.stan"),
scaled_variance = scaled_variance,
centred = centred
))

Expand Down
6 changes: 5 additions & 1 deletion R/LongitudinalGSF.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ NULL
#' @param sigma (`Prior`)\cr for the variance of the longitudinal values `sigma`.
#'
#' @param centred (`logical`)\cr whether to use the centred parameterization.
#' @param scaled_variance (`logical`)\cr whether the variance should be scaled by the expected value
#' (see the "Statistical Specifications" vignette for more details)
#'
#' @importFrom stats qlogis
#' @export
Expand All @@ -59,12 +61,14 @@ LongitudinalGSF <- function(

sigma = prior_lognormal(log(0.1), 1),

scaled_variance = TRUE,
centred = FALSE
) {

gsf_model <- StanModule(decorated_render(
.x = read_stan("lm-gsf/model.stan"),
centred = centred
centred = centred,
scaled_variance = scaled_variance
))

# Apply constraints
Expand Down
17 changes: 13 additions & 4 deletions R/SimLongitudinalClaretBruno.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ NULL
#' @param link_identity (`number`)\cr the link coefficient for the SLD Identity contribution.
#' @param link_growth (`number`)\cr the link coefficient for the growth parameter contribution.
#'
#' @param scaled_variance (`logical`)\cr whether the variance should be scaled by the expected value
#' (see the "Statistical Specifications" vignette for more details)
#'
#' @slot sigma (`numeric`)\cr See arguments.
#'
#' @slot mu_b (`numeric`)\cr See arguments.
Expand All @@ -40,6 +43,8 @@ NULL
#' @slot link_identity (`numeric`)\cr See arguments.
#' @slot link_growth (`numeric`)\cr See arguments.
#'
#' @slot scaled_variance (`logical`)\cr See arguments.
#'
#' @family SimLongitudinal
#' @name SimLongitudinalClaretBruno-class
#' @exportClass SimLongitudinalClaretBruno
Expand All @@ -59,7 +64,8 @@ NULL
link_dsld = "numeric",
link_ttg = "numeric",
link_identity = "numeric",
link_growth = "numeric"
link_growth = "numeric",
scaled_variance = "logical"
)
)

Expand All @@ -79,7 +85,8 @@ SimLongitudinalClaretBruno <- function(
link_dsld = 0,
link_ttg = 0,
link_identity = 0,
link_growth = 0
link_growth = 0,
scaled_variance = TRUE
) {

if (length(omega_b) == 1) omega_b <- rep(omega_b, length(mu_b))
Expand All @@ -101,7 +108,8 @@ SimLongitudinalClaretBruno <- function(
link_dsld = link_dsld,
link_ttg = link_ttg,
link_identity = link_identity,
link_growth = link_growth
link_growth = link_growth,
scaled_variance = scaled_variance
)
}

Expand Down Expand Up @@ -158,7 +166,8 @@ sampleObservations.SimLongitudinalClaretBruno <- function(object, times_df) {
dplyr::mutate(mu_sld = clbr_sld(.data$time, .data$ind_b, .data$ind_g, .data$ind_c, .data$ind_p)) |>
dplyr::mutate(dsld = clbr_dsld(.data$time, .data$ind_b, .data$ind_g, .data$ind_c, .data$ind_p)) |>
dplyr::mutate(ttg = clbr_ttg(.data$time, .data$ind_b, .data$ind_g, .data$ind_c, .data$ind_p)) |>
dplyr::mutate(sld = stats::rnorm(dplyr::n(), .data$mu_sld, .data$mu_sld * object@sigma)) |>
dplyr::mutate(sld_sd = ifelse(object@scaled_variance, .data$mu_sld * object@sigma, object@sigma)) |>
dplyr::mutate(sld = stats::rnorm(dplyr::n(), .data$mu_sld, .data$sld_sd)) |>
dplyr::mutate(
log_haz_link =
(object@link_dsld * .data$dsld) +
Expand Down
15 changes: 11 additions & 4 deletions R/SimLongitudinalGSF.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ NULL
#' @param link_identity (`number`)\cr the link coefficient for the SLD Identity contribution.
#' @param link_growth (`number`)\cr the link coefficient for the log-growth parameter contribution.
#' @param link_shrinkage (`number`)\cr the link coefficient for the log-shrinkage parameter contribution.
#' @param scaled_variance (`logical`)\cr whether the variance should be scaled by the expected value
#' (see the "Statistical Specifications" vignette for more details)
#'
#' @slot sigma (`numeric`)\cr See arguments.
#' @slot mu_s (`numeric`)\cr See arguments.
Expand All @@ -37,6 +39,7 @@ NULL
#' @slot link_identity (`numeric`)\cr See arguments.
#' @slot link_growth (`numeric`)\cr See arguments.
#' @slot link_shrinkage (`numeric`)\cr See arguments.
#' @slot scaled_variance (`numeric`)\cr See arguments.
#' @family SimLongitudinal
#' @name SimLongitudinalGSF-class
#' @exportClass SimLongitudinalGSF
Expand All @@ -57,7 +60,8 @@ NULL
link_ttg = "numeric",
link_identity = "numeric",
link_growth = "numeric",
link_shrinkage = "numeric"
link_shrinkage = "numeric",
scaled_variance = "logical"
)
)

Expand All @@ -78,7 +82,8 @@ SimLongitudinalGSF <- function(
link_ttg = 0,
link_identity = 0,
link_growth = 0,
link_shrinkage = 0
link_shrinkage = 0,
scaled_variance = TRUE
) {

if (length(omega_b) == 1) omega_b <- rep(omega_b, length(mu_b))
Expand All @@ -101,7 +106,8 @@ SimLongitudinalGSF <- function(
link_ttg = link_ttg,
link_identity = link_identity,
link_growth = link_growth,
link_shrinkage = link_shrinkage
link_shrinkage = link_shrinkage,
scaled_variance = scaled_variance
)
}

Expand Down Expand Up @@ -161,7 +167,8 @@ sampleObservations.SimLongitudinalGSF <- function(object, times_df) {
dplyr::mutate(mu_sld = gsf_sld(.data$time, .data$psi_b, .data$psi_s, .data$psi_g, .data$psi_phi)) |>
dplyr::mutate(dsld = gsf_dsld(.data$time, .data$psi_b, .data$psi_s, .data$psi_g, .data$psi_phi)) |>
dplyr::mutate(ttg = gsf_ttg(.data$time, .data$psi_b, .data$psi_s, .data$psi_g, .data$psi_phi)) |>
dplyr::mutate(sld = stats::rnorm(dplyr::n(), .data$mu_sld, .data$mu_sld * object@sigma)) |>
dplyr::mutate(sld_sd = ifelse(object@scaled_variance, .data$mu_sld * object@sigma, object@sigma)) |>
dplyr::mutate(sld = stats::rnorm(dplyr::n(), .data$mu_sld, .data$sld_sd)) |>
dplyr::mutate(
log_haz_link =
(object@link_dsld * .data$dsld) +
Expand Down
12 changes: 10 additions & 2 deletions inst/stan/lm-claret-bruno/model.stan
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,21 @@ transformed parameters{
long_obvs_log_lik[subject_tumour_index_obs] = vect_normal_log_dens(
tumour_value[subject_tumour_index_obs],
Ypred[subject_tumour_index_obs],
Ypred[subject_tumour_index_obs] * lm_clbr_sigma
{%- if scaled_variance -%}
Ypred[subject_tumour_index_obs] * lm_clbr_sigma
{% else %}
rep_vector(lm_clbr_sigma, n_tumour_obs)
{%- endif -%}
);
if (n_tumour_cens > 0 ) {
long_obvs_log_lik[subject_tumour_index_cens] = vect_normal_log_cum(
tumour_value_lloq,
Ypred[subject_tumour_index_cens],
Ypred[subject_tumour_index_cens] * lm_clbr_sigma
{%- if scaled_variance -%}
Ypred[subject_tumour_index_cens] * lm_clbr_sigma
{% else %}
rep_vector(lm_clbr_sigma, n_tumour_cens)
{%- endif -%}
);
}
}
Expand Down
12 changes: 10 additions & 2 deletions inst/stan/lm-gsf/model.stan
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,21 @@ transformed parameters{
long_obvs_log_lik[subject_tumour_index_obs] = vect_normal_log_dens(
tumour_value[subject_tumour_index_obs],
Ypred[subject_tumour_index_obs],
Ypred[subject_tumour_index_obs] * lm_gsf_sigma
{%- if scaled_variance -%}
Ypred[subject_tumour_index_obs] * lm_gsf_sigma
{% else %}
rep_vector(lm_gsf_sigma, n_tumour_obs)
{%- endif -%}
);
if (n_tumour_cens > 0 ) {
long_obvs_log_lik[subject_tumour_index_cens] = vect_normal_log_cum(
tumour_value_lloq,
Ypred[subject_tumour_index_cens],
Ypred[subject_tumour_index_cens] * lm_gsf_sigma
{%- if scaled_variance -%}
Ypred[subject_tumour_index_cens] * lm_gsf_sigma
{% else %}
rep_vector(lm_gsf_sigma, n_tumour_cens)
{%- endif -%}
);
}
}
Expand Down
4 changes: 4 additions & 0 deletions man/LongitudinalClaretBruno-class.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions man/LongitudinalGSF-class.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion man/SimLongitudinalClaretBruno-class.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion man/SimLongitudinalGSF-class.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 8bba385

Please sign in to comment.