From e4ffc6bb9ca4b3ca97c2a079cdb7469a591e219b Mon Sep 17 00:00:00 2001 From: Erik Date: Wed, 8 Jul 2026 09:23:39 +0200 Subject: [PATCH] fix(simulate_cohort): fixed a small bug in event scheduling with the initial loop having current_event = NULL thus never activating scheduling, also fixed a size coercion bug. --- R/simulate_cohort.R | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/R/simulate_cohort.R b/R/simulate_cohort.R index 17a3282..7f4ad4a 100644 --- a/R/simulate_cohort.R +++ b/R/simulate_cohort.R @@ -24,7 +24,8 @@ #' @param absorbing_events Named list describing absorbing events. #' @param absorbing_events_hook Optional hook to alter the absorbing-event model #' over time. -#' @param parameter_values Named list of model parameters. +#' @param parameter_values A named list of regression coefficients and scale/shape parameters. +#' For binomial events, parameters are specified on the log-odds scale. Use \code{qlogis(p)} to set baseline probabilities. #' @param intervention Optional named list of constant intervention values. #' @param regime Reserved for future use. #' @@ -258,15 +259,14 @@ simulate_cohort <- function(n, sd = visit_schedule[["sd"]]), visit_schedule[["minimum_time_between_visits"]] ) + # respect planned visit times - if (NROW(current_event)>0){ - if (length(visit_schedule[["schedule"]])){ - current_time <- current_event[["time"]] - next_scheduled_visit <- unique( - c(0,visit_schedule[["schedule"]],Inf) - )[2+prodlim::sindex(eval.time = current_time, jump.times = visit_schedule[["schedule"]])]-current_time - next_visit <- pmin(next_visit,next_scheduled_visit) - } + if (length(visit_schedule[["schedule"]])){ + current_time <- last_entry[["time"]] + next_scheduled_visit <- unique( + c(0,visit_schedule[["schedule"]],Inf) + )[2+prodlim::sindex(eval.time = current_time, jump.times = visit_schedule[["schedule"]])]-current_time + next_visit <- pmin(next_visit,next_scheduled_visit) } } ## apply hook for absorbing events @@ -400,3 +400,4 @@ simulate_cohort <- function(n, return(event_history) } +