Skip to content

Commit ff81af1

Browse files
authored
Merge pull request #47 from generable/develop
v0.2.11
2 parents 7723889 + 8464c55 commit ff81af1

8 files changed

Lines changed: 49 additions & 9 deletions

File tree

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: bmstate
22
Type: Package
33
Title: Bayesian multistate modeling
4-
Version: 0.2.10
4+
Version: 0.2.11
55
Authors@R:
66
c(person(given = "Juho",
77
family = "Timonen",

R/DosingData.R

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ PSSDosingData <- R6::R6Class(
9292
subject_id = sid, dose_ss = dose_ss,
9393
dose = doses, time = times
9494
)
95+
which_missed <- which(rows$dose == 0)
96+
rows$dose_time <- "Taken"
97+
rows$dose_time[which_missed] <- "Missed"
9598
out <- rbind(out, rows)
9699
}
97100
out
@@ -167,8 +170,12 @@ PSSDosingData <- R6::R6Class(
167170
)) +
168171
facet_wrap(. ~ .data$subject_id, scales = "free_x") +
169172
geom_vline(
170-
data = dos, mapping = aes(xintercept = time),
171-
col = "firebrick", lty = 2
173+
data = dos, mapping = aes(xintercept = time, lty = .data$dose_time),
174+
col = "firebrick"
175+
) +
176+
scale_linetype_manual(
177+
values =
178+
c(3, 1), name = "Dose"
172179
)
173180
if (!is.null(df_fit)) {
174181
if (!is.null(df_fit$lower)) {

R/MultistateModel.R

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -399,13 +399,15 @@ MultistateModel <- R6::R6Class("MultistateModel",
399399
#' @param w Spline weights. Matrix of shape \code{num_trans} x
400400
#' \code{num_weights}. If \code{NULL}, a matrix of zeros is used.
401401
#' @param num_doses Average number of doses taken by each subject. Only
402-
#' has effect if model as a PK submodel.
402+
#' has effect if model has a PK submodel.
403403
#' @param subjects_df Subject data frame. If \code{NULL}, simulated using
404404
#' the \code{simulate_subjects} method.
405+
#' @param truncate Truncate paths after terminal events?
405406
#' @return A \code{\link{JointData}} object.
406407
simulate_data = function(N_subject = 100, beta_haz = NULL,
407408
beta_pk = NULL, w0 = 1e-3, w = NULL, num_doses = 10,
408-
subjects_df = NULL) {
409+
subjects_df = NULL, truncate = TRUE) {
410+
checkmate::assert_logical(truncate, len = 1)
409411
H <- self$system$num_trans()
410412
if (is.null(subjects_df)) {
411413
subjects_df <- self$simulate_subjects(N_subject)
@@ -442,6 +444,9 @@ MultistateModel <- R6::R6Class("MultistateModel",
442444
subjects_df, path_df, link_df, self$system$tm(),
443445
colnames(subjects_df)
444446
)
447+
if (truncate) {
448+
pd <- pd$truncate()
449+
}
445450
JointData$new(pd, pksim$dosing)
446451
},
447452

R/PathData.R

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,14 @@ PathData <- R6::R6Class(
106106
unique(self$subject_df$subject_id)
107107
},
108108

109+
#' @description Truncate paths after terminal events
110+
#' @return A new \code{\link{PathData}} object with only the paths data
111+
#' frame edited.
112+
truncate = function() {
113+
pdf <- self$get_path_df(truncate = TRUE)
114+
PathData$new(self$subject_df, pdf, self$link_df, self$transmat, self$covs)
115+
},
116+
109117
#' @description Get names of covariates
110118
#' @return a character vector
111119
covariate_names = function() {

R/utils.R

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ pksim_to_quantiles <- function(sim, ci_alpha) {
44
av <- (1 - ci_alpha) / 2
55
sim <- sim |>
66
dplyr::group_by(.data$subject_id, .data$time) |>
7-
dplyr::summarise(q = list(quantile(.data$val, probs = c(av / 2, 0.5, 1 - av / 2))), .groups = "drop") |>
7+
dplyr::summarise(q = list(
8+
stats::quantile(.data$val, probs = c(av / 2, 0.5, 1 - av / 2))
9+
), .groups = "drop") |>
810
tidyr::unnest_wider(q, names_sep = "_")
911
colnames(sim)[3:5] <- c("lower", "val", "upper")
1012
sim

man/MultiStateModel.Rd

Lines changed: 5 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/PathData.Rd

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vignettes/math.Rmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ set.seed(2344)
150150
mod <- create_msm(tmat, n_grid = 12) # set very low n_grid for demo
151151
h0_true <- rep(1e-3, 3)
152152
mod$set_prior_mean_h0(h0_true) # has no effect for simulation
153-
dat <- mod$simulate_data(N_subject = 1, w0 = h0_true)
153+
dat <- mod$simulate_data(N_subject = 1, w0 = h0_true, truncate = FALSE)
154154
dat$paths$plot_paths(truncate = TRUE, alpha = 1) + ggtitle("")
155155
```
156156

0 commit comments

Comments
 (0)