Skip to content

Commit 586f9fd

Browse files
committed
Changed n_t to n_cycles
1 parent e02eb70 commit 586f9fd

File tree

2 files changed

+19
-19
lines changed

2 files changed

+19
-19
lines changed

R/Functions.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#' @return a ggplot object - plot of the cohort trace
1010
#'
1111
plot_trace <- function(m_M) {
12-
df_M <- data.frame(Cycle = 0:n_t, m_M, check.names = F)
12+
df_M <- data.frame(Cycle = 0:n_cycles, m_M, check.names = F)
1313
df_M_long <- tidyr::gather(df_M, key = `Health State`, value, 2:ncol(df_M))
1414
df_M_long$`Health State` <- factor(df_M_long$`Health State`, levels = v_names_states)
1515
p <- ggplot(df_M_long, aes(x = Cycle, y = value,
@@ -39,7 +39,7 @@ plot_trace_strategy <- function(l_m_M) {
3939
l_df_M <- lapply(l_m_M, as.data.frame)
4040
df_M_strategies <- data.table::rbindlist(l_df_M, use.names = T,
4141
idcol = "Strategy")
42-
df_M_strategies$Cycle <- rep(0:n_t, n_str)
42+
df_M_strategies$Cycle <- rep(0:n_cycles, n_str)
4343
m_M_plot <- tidyr::gather(df_M_strategies, key = `Health State`, value,
4444
2:(ncol(df_M_strategies)-1))
4545
m_M_plot$`Health State` <- factor(m_M_plot$`Health State`, levels = v_names_states)
@@ -76,7 +76,7 @@ calc_surv <- function(l_m_M, v_names_death_states) {
7676
}
7777
))
7878
colnames(df_surv) <- v_names_str
79-
df_surv$Cycle <- 0:n_t
79+
df_surv$Cycle <- 0:n_cycles
8080
df_surv_long <- tidyr::gather(df_surv, key = Strategy, Survival, 1:n_str)
8181
df_surv_long$Strategy <- ordered(df_surv_long$Strategy, levels = v_names_str)
8282
df_surv_long <- df_surv_long %>%
@@ -107,7 +107,7 @@ calc_sick <- function(l_m_M, v_names_sick_states) {
107107
}
108108
))
109109
colnames(df_sick) <- v_names_str
110-
df_sick$Cycle <- 0:n_t
110+
df_sick$Cycle <- 0:n_cycles
111111
df_sick_long <- tidyr::gather(df_sick, key = Strategy, Sick, 1:n_str)
112112
df_sick_long$Strategy <- ordered(df_sick_long$Strategy, levels = v_names_str)
113113
df_sick_long <- df_sick_long %>%

analysis/STM_01.R

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ source("R/Functions.R")
6262
## General setup
6363
n_age_init <- 25 # age at baseline
6464
n_age_max <- 100 # maximum age of follow up
65-
n_t <- n_age_max - n_age_init # time horizon, number of cycles
65+
n_cycles <- n_age_max - n_age_init # time horizon, number of cycles
6666
v_names_states <- c("H", "S1", "S2", "D") # the 4 health states of the model:
6767
# Healthy (H), Sick (S1), Sicker (S2), Dead (D)
6868
n_states <- length(v_names_states) # number of health states
@@ -73,7 +73,7 @@ d_e <- 0.03 # discount rate for QALYs
7373
v_names_str <- c("SoC", "A", "B", "AB") # store the strategy names
7474
n_str <- length(v_names_str) # number of strategies
7575
# Within-cycle correction (WCC) using Simpson's 1/3 rule
76-
v_wcc <- darthtools::gen_wcc(n_t = n_t, method = "Simpson1/3") # vector of wcc
76+
v_wcc <- darthtools::gen_wcc(n_t = n_cycles, method = "Simpson1/3") # vector of wcc
7777

7878

7979
## Transition probabilities (per cycle), hazard ratios and odds ratio
@@ -107,8 +107,8 @@ ic_HS1 <- 1000 # increase in cost when transitioning from Healthy to Sick
107107
ic_D <- 2000 # increase in cost when dying
108108

109109
# Discount weight (equal discounting is assumed for costs and effects)
110-
v_dwc <- 1 / ((1 + d_e) ^ (0:n_t))
111-
v_dwe <- 1 / ((1 + d_c) ^ (0:n_t))
110+
v_dwc <- 1 / ((1 + d_e) ^ (0:n_cycles))
111+
v_dwe <- 1 / ((1 + d_c) ^ (0:n_cycles))
112112

113113
### Process model inputs
114114
## Age-specific transition probabilities to the Dead state
@@ -136,8 +136,8 @@ v_s_init
136136

137137
## Initialize cohort trace for cSTM for strategies SoC and A
138138
m_M <- matrix(0,
139-
nrow = (n_t + 1), ncol = n_states,
140-
dimnames = list(0:n_t, v_names_states))
139+
nrow = (n_cycles + 1), ncol = n_states,
140+
dimnames = list(0:n_cycles, v_names_states))
141141
# Store the initial state vector in the first row of the cohort trace
142142
m_M[1, ] <- v_s_init
143143
## Initialize cohort trace for strategies B and AB
@@ -177,22 +177,22 @@ m_P_strB["S1", "S2"] <- (1 - p_S1D) * p_S1S2_trtB
177177
check_transition_probability(m_P, verbose = TRUE)
178178
check_transition_probability(m_P_strB, verbose = TRUE)
179179
## Check that all rows sum to 1
180-
check_sum_of_transition_array(m_P, n_states = n_states, n_t = n_t, verbose = TRUE)
181-
check_sum_of_transition_array(m_P_strB, n_states = n_states, n_t = n_t, verbose = TRUE)
180+
check_sum_of_transition_array(m_P, n_states = n_states, n_t = n_cycles, verbose = TRUE)
181+
check_sum_of_transition_array(m_P_strB, n_states = n_states, n_t = n_cycles, verbose = TRUE)
182182

183183
## Initialize transition array which will capture transitions from each state to another over time
184184
# for strategies SoC and A
185185
a_A <- array(0,
186-
dim = c(n_states, n_states, n_t + 1),
187-
dimnames = list(v_names_states, v_names_states, 0:n_t))
186+
dim = c(n_states, n_states, n_cycles + 1),
187+
dimnames = list(v_names_states, v_names_states, 0:n_cycles))
188188
# Set first slice of A with the initial state vector in its diagonal
189189
diag(a_A[, , 1]) <- v_s_init
190190
# For strategies B and AB, the array structure and initial state are identical
191191
a_A_strB <- a_A
192192

193193
#### Run Markov model ####
194194
# Iterative solution of time-independent cSTM
195-
for(t in 1:n_t){
195+
for(t in 1:n_cycles){
196196
## Fill in cohort trace
197197
# For strategies SoC and A
198198
m_M[t + 1, ] <- m_M[t, ] %*% m_P
@@ -294,12 +294,12 @@ for (i in 1:n_str) {
294294
m_c_str <- matrix(v_c_str, nrow = n_states, ncol = n_states, byrow = T)
295295
# Expand the transition matrix of state utilities across cycles to form a transition array of state utilities
296296
a_R_u_str <- array(m_u_str,
297-
dim = c(n_states, n_states, n_t + 1),
298-
dimnames = list(v_names_states, v_names_states, 0:n_t))
297+
dim = c(n_states, n_states, n_cycles + 1),
298+
dimnames = list(v_names_states, v_names_states, 0:n_cycles))
299299
# Expand the transition matrix of state costs across cycles to form a transition array of state costs
300300
a_R_c_str <- array(m_c_str,
301-
dim = c(n_states, n_states, n_t + 1),
302-
dimnames = list(v_names_states, v_names_states, 0:n_t))
301+
dim = c(n_states, n_states, n_cycles + 1),
302+
dimnames = list(v_names_states, v_names_states, 0:n_cycles))
303303

304304
#### Apply transition rewards ####
305305
# Apply disutility due to transition from H to S1

0 commit comments

Comments
 (0)