From 8bbb32c37dfca78b5efb6cd44bf3f288b8037543 Mon Sep 17 00:00:00 2001 From: jtimonen Date: Thu, 4 Dec 2025 08:01:21 +0200 Subject: [PATCH 1/3] Increment version number to 0.2.11.9000 --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 5119800..1519de5 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: bmstate Type: Package Title: Bayesian multistate modeling -Version: 0.2.11 +Version: 0.2.11.9000 Authors@R: c(person(given = "Juho", family = "Timonen", From 075772d08cec5dc5aa9e3604507a179af3c0178c Mon Sep 17 00:00:00 2001 From: jtimonen Date: Fri, 5 Dec 2025 03:38:43 +0200 Subject: [PATCH 2/3] use log ss_auc as exposure (xpsr) --- R/MultistateModel.R | 38 +++++++++---------- R/MultistateModelFit.R | 37 +++++++++++-------- R/PKModel.R | 14 +++---- R/stan-data.R | 8 ++-- R/stan.R | 10 ++--- inst/stan/msm.stan | 53 +++++++++++++++------------ man/MultiStateModel.Rd | 26 ++++++------- man/PKModel.Rd | 14 +++---- man/msmfit_pk_params.Rd | 4 +- tests/testthat/test-MultistateModel.R | 2 +- vignettes/exposure-hazard.Rmd | 12 +++--- 11 files changed, 116 insertions(+), 102 deletions(-) diff --git a/R/MultistateModel.R b/R/MultistateModel.R index 0d308f6..d4e6667 100644 --- a/R/MultistateModel.R +++ b/R/MultistateModel.R @@ -47,13 +47,13 @@ MultistateModel <- R6::R6Class("MultistateModel", categorical = NULL, normalizer_locations = NULL, normalizer_scales = NULL, - auc_normalizer_loc = 2000, - auc_normalizer_scale = 1000, + xpsr_normalizer_loc = 7.5, + xpsr_normalizer_scale = 0.5, n_grid = NULL, simulate_log_hazard_multipliers = function(df_subjects, beta) { ts <- self$target_states() x <- self$covs() - auc_norm <- self$get_auc_normalizers() + xpsr_norm <- self$get_xpsr_normalizers() B <- length(ts) K <- length(x) checkmate::assert_matrix(beta, nrows = B, ncols = K) @@ -64,10 +64,10 @@ MultistateModel <- R6::R6Class("MultistateModel", X <- df_subjects |> dplyr::select(tidyselect::all_of(x)) X <- as.matrix(X) X_norm <- normalize_columns(X) - if ("ss_auc" %in% x) { - idx <- which(x == "ss_auc") - x_norm <- (X[, idx] - auc_norm$loc) / auc_norm$scale - check_normalized_covariate(x_norm, "ss_auc") + if ("xpsr" %in% x) { + idx <- which(x == "xpsr") + x_norm <- (X[, idx] - xpsr_norm$loc) / xpsr_norm$scale + check_normalized_covariate(x_norm, "xpsr") X_norm[, idx] <- x_norm } for (s in seq_len(S)) { @@ -149,28 +149,28 @@ MultistateModel <- R6::R6Class("MultistateModel", invisible(NULL) }, - #' @description Get normalization constants for AUC (PK) + #' @description Get normalization constants for exposure (PK) #' @return list - get_auc_normalizers = function() { + get_xpsr_normalizers = function() { list( - loc = private$auc_normalizer_loc, - scale = private$auc_normalizer_scale + loc = private$xpsr_normalizer_loc, + scale = private$xpsr_normalizer_scale ) }, - #' @description Set normalization constants for AUC (side effect) + #' @description Set normalization constants for exposure (side effect) #' #' @param loc Location #' @param scale Scale - set_auc_normalizers = function(loc = 0, scale = 1) { + set_xpsr_normalizers = function(loc = 0, scale = 1) { checkmate::assert_numeric(loc, lower = 0, len = 1) checkmate::assert_numeric(scale, lower = 0, len = 1) message( - "setting auc normalizers to loc = ", + "setting xpsr normalizers to loc = ", round(loc, 5), ", scale = ", round(scale, 5) ) - private$auc_normalizer_loc <- loc - private$auc_normalizer_scale <- scale + private$xpsr_normalizer_loc <- loc + private$xpsr_normalizer_scale <- scale invisible(NULL) }, @@ -211,7 +211,7 @@ MultistateModel <- R6::R6Class("MultistateModel", #' @param system A \code{\link{MultistateSystem}} #' @param covariates The names of the hazard covariates (excluding possible #' exposure estimated from PK model). Do not use reserved names - #' \code{ss_auc} or \code{dose}. + #' \code{xpsr} or \code{dose}. #' @param pk_model A \code{\link{PKModel}} or NULL. #' @param t_max Max time. #' @param num_knots Total number of spline knots. @@ -232,7 +232,7 @@ MultistateModel <- R6::R6Class("MultistateModel", if (!all(categorical %in% covariates)) { stop("all categorical covariates should be also in covariates") } - checkmate::assert_true(!("ss_auc" %in% covariates)) # special name + checkmate::assert_true(!("xpsr" %in% covariates)) # special name checkmate::assert_true(!("dose" %in% covariates)) # special name checkmate::assert_class(system, "MultistateSystem") checkmate::assert_integerish(n_grid, lower = 10, len = 1) @@ -310,7 +310,7 @@ MultistateModel <- R6::R6Class("MultistateModel", covs = function() { x <- private$hazard_covariates if (self$has_pk()) { - x <- c(x, "ss_auc") + x <- c(x, "xpsr") } unique(x) }, diff --git a/R/MultistateModelFit.R b/R/MultistateModelFit.R index 22b24b5..9ef5e60 100644 --- a/R/MultistateModelFit.R +++ b/R/MultistateModelFit.R @@ -292,9 +292,9 @@ msmfit_covariate_effects <- function(fit) { df <- rbind(df, df_j) } if (fit$model$has_pk()) { - rv <- as.vector(fit$get_draws("beta_auc")[1, 1, ]) + rv <- as.vector(fit$get_draws("beta_xpsr")[1, 1, ]) df_j <- data.frame( - covariate = "ss_auc", beta = rv, + covariate = "xpsr", beta = rv, target_state_idx = fit$model$target_states() ) df <- rbind(df, df_j) @@ -344,9 +344,11 @@ mat2list <- function(mat) { #' @param oos Out-of-sample mode? If \code{FALSE}, the possible subject-specific #' fitted parameters are used. If \code{TRUE}, acting #' as if the subjects are new. +#' @param log Get logarithm of params? #' @return A list with length equal to number of draws. -msmfit_pk_params <- function(fit, oos = FALSE, data = NULL) { +msmfit_pk_params <- function(fit, oos = FALSE, data = NULL, log = FALSE) { check_oos(oos, data) + checkmate::assert_logical(log, len = 1) sd <- msmfit_stan_data(fit, data) S <- fit$num_draws() @@ -372,9 +374,9 @@ msmfit_pk_params <- function(fit, oos = FALSE, data = NULL) { # Call exposed Stan function for each draw (not optimal) out <- list() for (s in seq_len(S)) { - theta <- NULL + log_theta <- NULL if (sd$do_pk == 1) { - theta <- compute_theta_pk( + log_theta <- compute_log_theta_pk( mat2list(t(log_z[s, 1, , ])), log_mu[s, 1, ], log_sig[s, 1, ], @@ -386,6 +388,11 @@ msmfit_pk_params <- function(fit, oos = FALSE, data = NULL) { mat2list(t(sd$x_V2)) ) } + if (log) { + theta <- log_theta + } else { + theta <- exp(log_theta) + } out[[s]] <- theta } out @@ -400,18 +407,18 @@ msmfit_exposure <- function(fit, oos = FALSE, data = NULL) { # Get draws sd <- msmfit_stan_data(fit, data) - pkpar <- msmfit_pk_params(fit, oos, data) + log_pkpar <- msmfit_pk_params(fit, oos, data, log = TRUE) # Call exposed Stan function S <- fit$num_draws() out <- list() for (s in seq_len(S)) { if (sd$do_pk == 1) { - x_auc <- sd$dose_ss / (pkpar[[s]][, 2] * pkpar[[s]][, 3]) # D/(CL*V2) + x_xpsr <- log_ss_area_under_conc(sd$dose_ss, log_pkpar[[s]]) # log D/(CL*V2) } else { - x_auc <- NULL + x_xpsr <- NULL } - out[[s]] <- x_auc + out[[s]] <- x_xpsr } out } @@ -445,16 +452,16 @@ msmfit_log_hazard_multipliers <- function(fit, oos = FALSE, data = NULL) { # Get draws sd <- msmfit_stan_data(fit, data) - auc <- msmfit_exposure(fit, oos, data) + xpsr <- msmfit_exposure(fit, oos, data) S <- fit$num_draws() beta_oth <- fit$get_draws_of("beta_oth") if (is.null(beta_oth)) { beta_oth <- array(0, dim = c(S, 1, 0, sd$N_trans_types)) } if (sd$do_pk == 1) { - beta_auc <- fit$get_draws_of("beta_auc") + beta_xpsr <- fit$get_draws_of("beta_xpsr") } else { - beta_auc <- array(0, dim = c(S, 1, 0, sd$N_trans_types)) + beta_xpsr <- array(0, dim = c(S, 1, 0, sd$N_trans_types)) } # Create x_haz_long (long version of hazard covariates vector) @@ -465,14 +472,14 @@ msmfit_log_hazard_multipliers <- function(fit, oos = FALSE, data = NULL) { } else { x_haz_long <- array(0, dim = c(0, sd$N_int)) } - an <- fit$model$get_auc_normalizers() + an <- fit$model$get_xpsr_normalizers() # Call exposed Stan function for each draw (not optimal) out <- list() for (s in seq_len(S)) { if (sd$do_pk == 1) { - ba <- list(beta_auc[s, 1, 1, ]) - aa <- list(auc[[s]][sd$idx_sub]) + ba <- list(beta_xpsr[s, 1, 1, ]) + aa <- list(xpsr[[s]][sd$idx_sub]) } else { ba <- NULL aa <- NULL diff --git a/R/PKModel.R b/R/PKModel.R index 4136bb4..f919ef9 100644 --- a/R/PKModel.R +++ b/R/PKModel.R @@ -102,18 +102,18 @@ PKModel <- R6::R6Class("PKModel", conc }, - #' @description Compute steady-state area under concentration curve over - #' one dosing interval + #' @description Compute exposure, which is the steady-state + #' log area under concentration curve over one dosing interval #' #' @param theta parameter values #' @param dose dose #' @return A numeric value - compute_ss_auc = function(theta, dose) { + compute_xpsr = function(theta, dose) { CL <- theta[2] V2 <- theta[3] checkmate::assert_number(CL, lower = 0) checkmate::assert_number(dose, lower = 0) - dose / (CL * V2) + log(dose) - log(CL * V2) }, #' @description Simulate data with many subjects @@ -159,17 +159,17 @@ PKModel <- R6::R6Class("PKModel", CONC <- dd$simulate_pk(t_obs, THETA, self$get_max_conc()) df_out <- NULL for (n in seq_len(N)) { - ss_auc <- self$compute_ss_auc(THETA[n, ], dd$dose_ss[n]) + xpsr <- self$compute_xpsr(THETA[n, ], dd$dose_ss[n]) sid <- SUB_ID[n] conc <- (CONC |> dplyr::filter(.data$subject_id == sid))[["val"]] conc_noisy <- stats::rlnorm(2, meanlog = log(conc), sdlog = sigma) - out <- c(t_obs[[n]], conc_noisy, ss_auc) + out <- c(t_obs[[n]], conc_noisy, xpsr) df_out <- rbind(df_out, out) } df_out <- data.frame(df_out) df_out <- cbind(df_out, THETA) colnames(df_out) <- c( - "t_pre", "t_post", "conc_pre", "conc_post", "ss_auc", + "t_pre", "t_post", "conc_pre", "conc_post", "xpsr", "ka", "CL", "V2" ) rownames(df_out) <- NULL diff --git a/R/stan-data.R b/R/stan-data.R index 47f5fe1..3c2bc1d 100644 --- a/R/stan-data.R +++ b/R/stan-data.R @@ -40,7 +40,7 @@ create_stan_data_model <- function(model) { sd_t_grid <- create_stan_data_timegrid(model) # PK options - an <- model$get_auc_normalizers() + an <- model$get_xpsr_normalizers() MC <- 1e-7 if (model$has_pk()) { MC <- model$pk_model$get_max_conc() @@ -49,9 +49,9 @@ create_stan_data_model <- function(model) { nc_ka = length(model$data_covs("ka")), nc_CL = length(model$data_covs("CL")), nc_V2 = length(model$data_covs("V2")), - I_auc = as.numeric(model$has_pk()), - auc_loc = an$loc, - auc_scale = an$scale, + I_xpsr = as.numeric(model$has_pk()), + xpsr_loc = an$loc, + xpsr_scale = an$scale, MAX_CONC = MC ) diff --git a/R/stan.R b/R/stan.R index aff4304..6166a64 100644 --- a/R/stan.R +++ b/R/stan.R @@ -101,12 +101,12 @@ fit_stan <- function(model, data, if (set_normalizers) { model$set_normalizers(data) if (!is.null(data$dosing)) { - mu_CL <- exp(-2) # should match msm.stan - mu_V2 <- exp(-2) # should match msm.stan - aaa <- data$dosing$dose_ss / (mu_CL * mu_V2) + log_mu_CL <- -2 # should match msm.stan + log_mu_V2 <- -2 # should match msm.stan + aaa <- log(data$dosing$dose_ss) - log_mu_CL - log_mu_V2 loc <- mean(aaa) sca <- stats::sd(aaa) - model$set_auc_normalizers(loc, sca) + model$set_xpsr_normalizers(loc, sca) } } @@ -133,7 +133,7 @@ fit_stan <- function(model, data, # Return pars <- c( "weights", "log_w0", "beta_ka", "beta_V2", "beta_CL", "beta_oth", - "beta_auc", "sigma_pk", "log_z_pk", "log_mu_pk", "log_sig_pk", "lp__" + "beta_xpsr", "sigma_pk", "log_z_pk", "log_mu_pk", "log_sig_pk", "lp__" ) draws <- create_rv_list(stan_fit, pars) diag <- NULL diff --git a/inst/stan/msm.stan b/inst/stan/msm.stan index 357bfa8..89308c0 100644 --- a/inst/stan/msm.stan +++ b/inst/stan/msm.stan @@ -1,14 +1,19 @@ functions { + // log SS AUC + vector log_ss_area_under_conc(vector dose_ss, matrix log_theta_pk){ + return(log(dose_ss) - log_theta_pk[:,2] - log_theta_pk[:,3]) ; // D/(CL*V2) + } + // log of hazard multiplier matrix compute_log_hazard_multiplier( data int N_int, array[] vector beta_oth, - array[] vector beta_auc, + array[] vector beta_xpsr, data array[] vector x_haz, - array[] vector x_auc, - real auc_loc, - real auc_scale, + array[] vector x_xpsr, + real xpsr_loc, + real xpsr_scale, data array[] int ttype ) { int N_trans = size(ttype); @@ -21,8 +26,8 @@ functions { log_C_haz[,j] += beta_oth[k][h] * x_haz[k]; } } - if(size(beta_auc)==1){ - log_C_haz[,j] += beta_auc[1][h] * ((x_auc[1] - auc_loc) / auc_scale); + if(size(beta_xpsr)==1){ + log_C_haz[,j] += beta_xpsr[1][h] * ((x_xpsr[1] - xpsr_loc) / xpsr_scale); } } return(log_C_haz); @@ -50,7 +55,7 @@ functions { } // Transform params - matrix compute_theta_pk( + matrix compute_log_theta_pk( array[] vector log_z, vector log_mu, vector log_sig, vector beta_ka, vector beta_CL, vector beta_V2, array[] vector x_ka, array[] vector x_CL, array[] vector x_V2 @@ -72,7 +77,7 @@ functions { sum(beta_V2 .* x_V2[n]); } - return(exp(log_theta)); + return(log_theta); } // Analytic solution with general initial condition (A0, C0) @@ -298,9 +303,9 @@ data { array[N_trans] int ttype; // PK options - int I_auc; - real auc_loc; - real auc_scale; + int I_xpsr; + real xpsr_loc; + real xpsr_scale; int nc_ka; // num of predictors for ka int nc_CL; // num of predictors for CL int nc_V2; // num of predictors for V2 @@ -379,7 +384,7 @@ parameters { // Covariate effects array[do_haz, nc_haz] vector[N_trans_types] beta_oth; - array[do_haz, I_auc] vector[N_trans_types] beta_auc; + array[do_haz, I_xpsr] vector[N_trans_types] beta_xpsr; // PK model array[do_pk, N_sub] vector[3] log_z_pk; @@ -408,31 +413,31 @@ transformed parameters { } // PK quantities - array[do_pk] matrix[N_sub, 3] theta_pk; + array[do_pk] matrix[N_sub, 3] log_theta_pk; array[do_pk, N_sub] vector[2] conc_mu_pk; - array[do_pk] vector[N_sub] ss_auc; // auc for each subject - array[do_pk] vector[N_int] x_auc_long; // auc for each interval + array[do_pk] vector[N_sub] ss_xpsr; // xpsr for each subject + array[do_pk] vector[N_int] x_xpsr_long; // xpsr for each interval if(do_pk == 1){ // PK params - theta_pk[1] = compute_theta_pk( + log_theta_pk[1] = compute_log_theta_pk( log_z_pk[1], log_mu_pk[1], log_sig_pk[1], beta_ka[1], beta_CL[1], beta_V2[1], x_ka, x_CL, x_V2 ); // Drug concentration estimated at t_obs conc_mu_pk[1] = pop_2cpt_partly_ss( - t_obs_pk, dose_ss, last_two_times, last_two_doses, theta_pk[1], tau_ss, + t_obs_pk, dose_ss, last_two_times, last_two_doses, exp(log_theta_pk[1]), tau_ss, MAX_CONC ); - // Concentration AUC at steady state - ss_auc[1] = (dose_ss ./ (theta_pk[1][:,2] .* theta_pk[1][:,3])); // D/(CL*V2) + // Concentration xpsr at steady state + ss_xpsr[1] = log_ss_area_under_conc(dose_ss, log_theta_pk[1]); - // Set AUC corresponding to each interval + // Set xpsr corresponding to each interval for(n in 1:N_int){ - x_auc_long[1][n] = ss_auc[1][idx_sub[n]]; + x_xpsr_long[1][n] = ss_xpsr[1][idx_sub[n]]; } } } @@ -446,8 +451,8 @@ model { beta_oth[1, k] ~ normal(0, 1); } } - if(I_auc==1){ - beta_auc[1, 1] ~ normal(0, 1); // only if has pk submodel + if(I_xpsr==1){ + beta_xpsr[1, 1] ~ normal(0, 1); // only if has pk submodel } // Baseline hazard base level @@ -481,7 +486,7 @@ model { // log of hazard multiplier on each interval matrix[N_int, N_trans] log_C_haz = compute_log_hazard_multiplier( - N_int, beta_oth[1], beta_auc[1], x_haz_long, x_auc_long, auc_loc, auc_scale, + N_int, beta_oth[1], beta_xpsr[1], x_haz_long, x_xpsr_long, xpsr_loc, xpsr_scale, ttype ); diff --git a/man/MultiStateModel.Rd b/man/MultiStateModel.Rd index 20d42c0..5eaa27e 100644 --- a/man/MultiStateModel.Rd +++ b/man/MultiStateModel.Rd @@ -26,8 +26,8 @@ hazard model part?} \item \href{#method-MultistateModel-get_normalizers}{\code{MultistateModel$get_normalizers()}} \item \href{#method-MultistateModel-get_n_grid}{\code{MultistateModel$get_n_grid()}} \item \href{#method-MultistateModel-set_normalizers}{\code{MultistateModel$set_normalizers()}} -\item \href{#method-MultistateModel-get_auc_normalizers}{\code{MultistateModel$get_auc_normalizers()}} -\item \href{#method-MultistateModel-set_auc_normalizers}{\code{MultistateModel$set_auc_normalizers()}} +\item \href{#method-MultistateModel-get_xpsr_normalizers}{\code{MultistateModel$get_xpsr_normalizers()}} +\item \href{#method-MultistateModel-set_xpsr_normalizers}{\code{MultistateModel$set_xpsr_normalizers()}} \item \href{#method-MultistateModel-get_prior_mean_h0}{\code{MultistateModel$get_prior_mean_h0()}} \item \href{#method-MultistateModel-set_prior_mean_h0}{\code{MultistateModel$set_prior_mean_h0()}} \item \href{#method-MultistateModel-set_prior_mean_h0_data}{\code{MultistateModel$set_prior_mean_h0_data()}} @@ -91,12 +91,12 @@ Set normalization constant for each variable (side effect) } } \if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-MultistateModel-get_auc_normalizers}{}}} -\subsection{Method \code{get_auc_normalizers()}}{ -Get normalization constants for AUC (PK) +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-MultistateModel-get_xpsr_normalizers}{}}} +\subsection{Method \code{get_xpsr_normalizers()}}{ +Get normalization constants for exposure (PK) \subsection{Usage}{ -\if{html}{\out{
}}\preformatted{MultistateModel$get_auc_normalizers()}\if{html}{\out{
}} +\if{html}{\out{
}}\preformatted{MultistateModel$get_xpsr_normalizers()}\if{html}{\out{
}} } \subsection{Returns}{ @@ -104,12 +104,12 @@ list } } \if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-MultistateModel-set_auc_normalizers}{}}} -\subsection{Method \code{set_auc_normalizers()}}{ -Set normalization constants for AUC (side effect) +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-MultistateModel-set_xpsr_normalizers}{}}} +\subsection{Method \code{set_xpsr_normalizers()}}{ +Set normalization constants for exposure (side effect) \subsection{Usage}{ -\if{html}{\out{
}}\preformatted{MultistateModel$set_auc_normalizers(loc = 0, scale = 1)}\if{html}{\out{
}} +\if{html}{\out{
}}\preformatted{MultistateModel$set_xpsr_normalizers(loc = 0, scale = 1)}\if{html}{\out{
}} } \subsection{Arguments}{ @@ -197,7 +197,7 @@ Create model \item{\code{covariates}}{The names of the hazard covariates (excluding possible exposure estimated from PK model). Do not use reserved names -\code{ss_auc} or \code{dose}.} +\code{xpsr} or \code{dose}.} \item{\code{pk_model}}{A \code{\link{PKModel}} or NULL.} diff --git a/man/PKModel.Rd b/man/PKModel.Rd index a8a270c..7318c3e 100644 --- a/man/PKModel.Rd +++ b/man/PKModel.Rd @@ -19,7 +19,7 @@ oral absorption. \item \href{#method-PKModel-covs}{\code{PKModel$covs()}} \item \href{#method-PKModel-print}{\code{PKModel$print()}} \item \href{#method-PKModel-simulate_ss}{\code{PKModel$simulate_ss()}} -\item \href{#method-PKModel-compute_ss_auc}{\code{PKModel$compute_ss_auc()}} +\item \href{#method-PKModel-compute_xpsr}{\code{PKModel$compute_xpsr()}} \item \href{#method-PKModel-simulate_data}{\code{PKModel$simulate_data()}} \item \href{#method-PKModel-format_params}{\code{PKModel$format_params()}} \item \href{#method-PKModel-clone}{\code{PKModel$clone()}} @@ -151,13 +151,13 @@ concentration in the central compartment. } } \if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-PKModel-compute_ss_auc}{}}} -\subsection{Method \code{compute_ss_auc()}}{ -Compute steady-state area under concentration curve over -one dosing interval +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-PKModel-compute_xpsr}{}}} +\subsection{Method \code{compute_xpsr()}}{ +Compute exposure, which is the steady-state +log area under concentration curve over one dosing interval \subsection{Usage}{ -\if{html}{\out{
}}\preformatted{PKModel$compute_ss_auc(theta, dose)}\if{html}{\out{
}} +\if{html}{\out{
}}\preformatted{PKModel$compute_xpsr(theta, dose)}\if{html}{\out{
}} } \subsection{Arguments}{ diff --git a/man/msmfit_pk_params.Rd b/man/msmfit_pk_params.Rd index caab8c5..96eeb81 100644 --- a/man/msmfit_pk_params.Rd +++ b/man/msmfit_pk_params.Rd @@ -4,7 +4,7 @@ \alias{msmfit_pk_params} \title{Evaluate PK parameters} \usage{ -msmfit_pk_params(fit, oos = FALSE, data = NULL) +msmfit_pk_params(fit, oos = FALSE, data = NULL, log = FALSE) } \arguments{ \item{fit}{A \code{\link{MultistateModelFit}} object} @@ -15,6 +15,8 @@ as if the subjects are new.} \item{data}{A \code{\link{JointData}} object. If \code{NULL}, the data used to fit the model is used.} + +\item{log}{Get logarithm of params?} } \value{ A list with length equal to number of draws. diff --git a/tests/testthat/test-MultistateModel.R b/tests/testthat/test-MultistateModel.R index 047a65a..9edb7ab 100644 --- a/tests/testthat/test-MultistateModel.R +++ b/tests/testthat/test-MultistateModel.R @@ -59,7 +59,7 @@ test_that("MultistateModel with PK submodel works", { V2 = c("weight", "sex") ) mod <- create_msm(tm, covs, pk_covs) - expect_equal(mod$covs(), c("sex", "age", "ss_auc")) + expect_equal(mod$covs(), c("sex", "age", "xpsr")) expect_equal(mod$data_covs(), c("sex", "age", "CrCL", "weight")) tmax <- 3 * 365.25 mod$set_knots(tmax, seq(0, tmax - 1, length.out = 1000), 3) diff --git a/vignettes/exposure-hazard.Rmd b/vignettes/exposure-hazard.Rmd index 58d17b5..a0e8c09 100644 --- a/vignettes/exposure-hazard.Rmd +++ b/vignettes/exposure-hazard.Rmd @@ -133,8 +133,8 @@ create_oracle_fit <- function(similar_fit, beta_true, h0_true) { beta_oth[1, , ] <- t(beta_true$matrix[, 1]) beta_oth <- posterior::rvar(beta_oth) - beta_auc <- similar_fit$get_draws("beta_auc") - beta_auc[1, , ] <- t(beta_true$matrix[, 2]) + beta_xpsr <- similar_fit$get_draws("beta_xpsr") + beta_xpsr[1, , ] <- t(beta_true$matrix[, 2]) lp <- similar_fit$get_draws("lp__") lp[] <- NA @@ -154,7 +154,7 @@ create_oracle_fit <- function(similar_fit, beta_true, h0_true) { # Create fit draws <- list( beta_oth = beta_oth, - beta_auc = beta_auc, + beta_xpsr = beta_xpsr, beta_CL = beta_CL, beta_V2 = beta_V2, weights = weights, @@ -190,8 +190,8 @@ covs_dh <- unique(c(mod_true$data_covs(), "dose_amt")) simdat_dh <- simdat$paths$subset_covariates(covs_dh, renamed_old = "dose", renamed_new = "dose_amt") simdat_death <- as_single_event(simdat_dh, "Dead", null_state = "Healthy") -sa <- simdat$paths$subject_df$ss_auc -mod_true$set_auc_normalizers(loc = mean(sa), scale = stats::sd(sa)) +sa <- simdat$paths$subject_df$xpsr +mod_true$set_xpsr_normalizers(loc = mean(sa), scale = stats::sd(sa)) simdat <- mod_true$simulate_data( params$N_subject, @@ -223,7 +223,7 @@ pk_covs <- list( # Exposure-hazard multistate model mod_ms_eh <- create_msm( tm, - hazard_covs = setdiff(mod_true$covs(), "ss_auc"), + hazard_covs = setdiff(mod_true$covs(), "xpsr"), pk_covs = pk_covs, num_knots = NK, t_max = mod_true$get_tmax() ) From 75357d4cb2383351f82b3cb4f6fdbb50a713dba6 Mon Sep 17 00:00:00 2001 From: jtimonen Date: Fri, 5 Dec 2025 03:49:53 +0200 Subject: [PATCH 3/3] Increment version number to 0.3.0 --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 1519de5..7cb0903 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: bmstate Type: Package Title: Bayesian multistate modeling -Version: 0.2.11.9000 +Version: 0.3.0 Authors@R: c(person(given = "Juho", family = "Timonen",