Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: bmstate
Type: Package
Title: Bayesian multistate modeling
Version: 0.2.4
Version: 0.2.5
Authors@R:
c(person(given = "Juho",
family = "Timonen",
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export(PKModel)
export(PSSDosingData)
export(PathData)
export(TransitionMatrix)
export(as_any_event)
export(as_single_event)
export(as_survival)
export(c_index)
Expand Down
20 changes: 20 additions & 0 deletions R/PathData.R
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,26 @@ potential_covariates <- function(pd, possible = NULL, ...) {
df
}

#' PathData to time-to-event data format for any state other than null state
#'
#' @export
#' @inheritParams as_single_event
#' @return A \code{\link{PathData}} object
as_any_event <- function(pd, null_state = "Randomization") {
pd_new <- pd$clone(deep = TRUE)
df <- pd_new$path_df
idx <- which(pd_new$transmat$states == null_state)
if (length(idx) != 1) {
stop("error")
}
df$state[which(df$state == idx)] <- 1
df$state[which(df$state != 1)] <- 2
tm <- transmat_survival(state_names = c(null_state, "Any event"))
pd_new$path_df <- df
pd_new$transmat <- tm
as_single_event(pd_new, "Any event", null_state)
}

#' PathData to time-to-event data format with a single event
#'
#' @export
Expand Down
3 changes: 2 additions & 1 deletion R/stan.R
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ fit_stan <- function(model, data,
info <- list(
diag = diag,
runset = stan_fit$runset,
summary = smr$result
summary = smr$result,
time = stan_fit$time()
)
fit <- MultistateModelFit$new(data, sd, model, draws, info)
if (!return_stanfit) {
Expand Down
19 changes: 19 additions & 0 deletions man/as_any_event.Rd

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

6 changes: 3 additions & 3 deletions tests/testthat/test-cav.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
library(ggplot2)
library(dplyr)

test_that("cav data analysis works", {
library(ggplot2)
library(dplyr)

# Modify original data like in
# https://rviews.rstudio.com/2023/04/19/multistate-models-for-medical-applications/
df_full <- as_tibble(msm::cav) |>
Expand Down
4 changes: 4 additions & 0 deletions tests/testthat/test-workflow.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ test_that("entire workflow works", {
fit <- a$fit
expect_true(inherits(fit, "MultistateModelFit"))

# Test
a <- as_any_event(jd$train$paths, "Healthy")
checkmate::assert_true(all(a$state_names() == c("Healthy", "Any event")))

# Print
expect_output(print(fit), "A MultistateModelFit with 30 draws")

Expand Down