@@ -79,9 +79,8 @@ drmd_psm <- function(ptdata, dpam, psmtype="simple", Ty=10, discrate=0, lifetabl
79
79
)
80
80
# Obtain all the hazards
81
81
allh <- calc_haz_psm(timevar = ds $ tmid , ptdata = ptdata , dpam = dpam , psmtype = psmtype )$ adj
82
- # Derive the unconstrained mortality hazards
82
+ # Derive the unconstrained PPD mortality probability
83
83
ds $ q_ppd <- 1 - exp(- allh $ ppd )
84
- ds $ q_pps <- 1 - exp(- allh $ pps )
85
84
# Derive the constrained life table
86
85
ds $ clx <- calc_ltsurv(convert_wks2yrs(ds $ tzero ), lifetable )
87
86
# Other calculations on the dataset
@@ -92,15 +91,23 @@ drmd_psm <- function(ptdata, dpam, psmtype="simple", Ty=10, discrate=0, lifetabl
92
91
# Derive the TTP probability (balancing item)
93
92
q_pfs = 1 - dplyr :: lead(u_pf )/ u_pf ,
94
93
q_ttp = q_pfs - q_ppd ,
94
+ d_pf = u_pf * q_ppd ,
95
95
c_qpfs = q_ttp + pmax(q_ppd , cqx ),
96
+ # Derive the PPS mortality probability
97
+ d_pfpd = u_pf + u_pd - dplyr :: lead(u_pf ) - dplyr :: lead(u_pd ),
98
+ d_pps = d_pfpd - d_pf ,
99
+ q_pps = dplyr :: if_else(u_pd == 0 , 0 , d_pps / u_pd ),
100
+ # Constrained probabilities
101
+ cqpfs = q_ttp + pmax(q_ppd , cqx ),
102
+ cqpps = pmax(q_pps , cqx ),
96
103
# Derive the constrained PF and PD memberships
97
104
c_pf = u_pf ,
98
105
c_pd = u_pd ,
99
106
)
100
107
# Derive the constrained PF and PD memberships
101
108
for (t in 2 : (Tw )) {
102
109
ds $ c_pf [t ] = ds $ c_pf [t - 1 ] * (1 - ds $ cqpfs [t - 1 ])
103
- ds $ c_pd [t ] = ds $ c_pf [t - 1 ] * ds $ q_ttp [t - 1 ] + ds $ c_pd [t - 1 ] * (1 - pmax( ds $ q_pps [t - 1 ], ds $ cqx [ t - 1 ]) )
110
+ ds $ c_pd [t ] = ds $ c_pf [t - 1 ] * ds $ q_ttp [t - 1 ] + ds $ c_pd [t - 1 ] * (1 - ds $ cqpps [t - 1 ])
104
111
}
105
112
# The final membership probabilities are zero
106
113
ds $ c_pf [Tw + 1 ] <- ds $ c_pd [Tw + 1 ] <- 0
@@ -160,13 +167,13 @@ drmd_stm_cf <- function(dpam, Ty=10, discrate=0, lifetable=NA, timestep=1) {
160
167
h_ppd = calc_haz(tmid , survobj = dpam $ ppd ),
161
168
q_ppd = 1 - exp(- h_ppd ),
162
169
# Derive the constrained life table
163
- clx = calc_ltsurv(convert_wks2yrs(ds $ tzero ), lifetable ),
170
+ clx = calc_ltsurv(convert_wks2yrs(tzero ), lifetable ),
164
171
# Derive the background mortality for this timepoint
165
172
cqx = 1 - dplyr :: lead(clx )/ clx ,
166
173
# Derive the TTP probability (balancing item for PFS)
167
174
q_pfs = 1 - dplyr :: lead(u_pf )/ u_pf ,
168
175
q_ttp = q_pfs - q_ppd ,
169
- cqpfs = q_ttp + pmax( q_ppd , cqx ) ,
176
+ d_pf = u_pf * q_ppd ,
170
177
# Derive the PPS mortality probability
171
178
d_pfpd = u_pf + u_pd - dplyr :: lead(u_pf ) - dplyr :: lead(u_pd ),
172
179
d_pps = d_pfpd - d_pf ,
@@ -181,7 +188,7 @@ drmd_stm_cf <- function(dpam, Ty=10, discrate=0, lifetable=NA, timestep=1) {
181
188
# Derive the constrained PF and PD memberships
182
189
for (t in 2 : (Tw )) {
183
190
ds $ c_pf [t ] = ds $ c_pf [t - 1 ] * (1 - ds $ cqpfs [t - 1 ])
184
- ds $ c_pd [t ] = ds $ c_pf [t - 1 ] * ds $ q_ttp [t - 1 ] + ds $ c_pd [t - 1 ] * (1 - pmax( ds $ q_pps [t - 1 ], ds $ cqx [ t - 1 ]) )
191
+ ds $ c_pd [t ] = ds $ c_pf [t - 1 ] * ds $ q_ttp [t - 1 ] + ds $ c_pd [t - 1 ] * (1 - ds $ cqpps [t - 1 ])
185
192
}
186
193
# The final membership probabilities are zero
187
194
ds $ c_pf [Tw + 1 ] <- ds $ c_pd [Tw + 1 ] <- 0
@@ -202,8 +209,6 @@ drmd_stm_cf <- function(dpam, Ty=10, discrate=0, lifetable=NA, timestep=1) {
202
209
return (list (pf = pf , pd = pd , os = pf + pd , calc = ds ))
203
210
}
204
211
205
-
206
-
207
212
# ' Discretized Restricted Mean Duration calculation for State Transition Model Clock Reset structure
208
213
# ' Calculate restricted mean duration (RMD) in PF, PD and OS states under a State Transition Model Clock Reset structure.
209
214
# ' @inherit drmd_psm params return
@@ -246,7 +251,7 @@ drmd_stm_cr <- function(dpam, Ty=10, discrate=0, lifetable=NA, timestep=1) {
246
251
h_ppd = calc_haz(tmid , survobj = dpam $ ppd ),
247
252
q_ppd = 1 - exp(- h_ppd ),
248
253
# Derive the constrained life table
249
- clx = calc_ltsurv(convert_wks2yrs(ds $ tzero ), lifetable ),
254
+ clx = calc_ltsurv(convert_wks2yrs(tzero ), lifetable ),
250
255
cqx = 1 - dplyr :: lead(clx )/ clx ,
251
256
# Derive the TTP probability (balancing item for PF)
252
257
q_pfs = 1 - dplyr :: lead(u_pf )/ u_pf ,
0 commit comments