|
166 | 166 | hce_dat[idx, ]$step_values <-
|
167 | 167 | 100 *
|
168 | 168 | stats::ecdf(hce_dat[hce_dat$arm == arm,
|
169 |
| - ]$t_cdf)(hce_dat[idx, ]$t_cdf) |
| 169 | + ]$t_cdf)(hce_dat[idx, ]$t_cdf) |
170 | 170 |
|
171 | 171 | }
|
172 | 172 |
|
173 | 173 | }
|
174 | 174 |
|
175 | 175 | hce_ecdf <- hce_dat %>%
|
176 |
| - dplyr::filter(outcome %in% step_outcomes) %>% |
177 |
| - unique() |
178 |
| - |
179 |
| - # Double-check that all combinations of treatment and outcome have |
180 |
| - # been included (not the case if one combination has no patients) |
181 |
| - poss_comb <- expand.grid("outcome" = step_outcomes, |
182 |
| - "arm" = arm_levels) |
183 |
| - missing_row <- dplyr::anti_join(poss_comb, |
184 |
| - hce_ecdf[, c("outcome", "arm")]) |
185 |
| - |
186 |
| - # If there are missing rows, fill them in |
187 |
| - if (nrow(missing_row) > 0) { |
188 |
| - |
189 |
| - for (i in 1:num_step_outcomes) { |
190 |
| - # Check if current step outcome is missing |
191 |
| - if (step_outcomes[[i]] %in% missing_row$outcome) { |
192 |
| - tmp <- missing_row[missing_row$outcome == step_outcomes[[i]], ] |
193 |
| - # Determine step values based on previous step if available |
194 |
| - if (i == 1) { |
195 |
| - step_values <- 0 |
196 |
| - } else { |
197 |
| - tmp2 <- hce_ecdf[hce_ecdf$outcome == step_outcomes[i - 1] & |
198 |
| - hce_ecdf$arm == tmp$arm, ] |
199 |
| - step_values <- max(tmp2$step_values) |
200 |
| - } |
201 |
| - # Fetch existing data for the same outcome but different arm |
202 |
| - tmp3 <- hce_ecdf[hce_ecdf$outcome == step_outcomes[[i]] & |
203 |
| - hce_ecdf$arm != tmp$arm, ] |
204 |
| - # Append missing row to the main data frame |
205 |
| - hce_ecdf <- |
206 |
| - rbind(hce_ecdf, |
207 |
| - data.frame(outcome = step_outcomes[[i]], |
208 |
| - arm = tmp$arm, |
209 |
| - t_cdf = mean(tmp3$t_cdf), |
210 |
| - step_values = step_values, |
211 |
| - value = 0)) |
| 176 | + dplyr::filter(outcome %in% step_outcomes) %>% |
| 177 | + unique() |
| 178 | + |
| 179 | + # Double-check that all combinations of treatment and outcome have |
| 180 | + # been included (not the case if one combination has no patients) |
| 181 | + poss_comb <- expand.grid("outcome" = step_outcomes, |
| 182 | + "arm" = arm_levels) |
| 183 | + missing_row <- dplyr::anti_join(poss_comb, |
| 184 | + hce_ecdf[, c("outcome", "arm")]) |
| 185 | + |
| 186 | + # If there are missing rows, fill them in |
| 187 | + if (nrow(missing_row) > 0) { |
| 188 | + |
| 189 | + for (i in 1:num_step_outcomes) { |
| 190 | + # Check if current step outcome is missing |
| 191 | + if (step_outcomes[[i]] %in% missing_row$outcome) { |
| 192 | + tmp <- missing_row[missing_row$outcome == step_outcomes[[i]], ] |
| 193 | + # Determine step values based on previous step if available |
| 194 | + if (i == 1) { |
| 195 | + step_values <- 0 |
| 196 | + } else { |
| 197 | + tmp2 <- hce_ecdf[hce_ecdf$outcome == step_outcomes[i - 1] & |
| 198 | + hce_ecdf$arm == tmp$arm, ] |
| 199 | + step_values <- max(tmp2$step_values) |
212 | 200 | }
|
| 201 | + # Fetch existing data for the same outcome but different arm |
| 202 | + tmp3 <- hce_ecdf[hce_ecdf$outcome == step_outcomes[[i]] & |
| 203 | + hce_ecdf$arm != tmp$arm, ] |
| 204 | + # Append missing row to the main data frame |
| 205 | + hce_ecdf <- |
| 206 | + rbind(hce_ecdf, |
| 207 | + data.frame(outcome = step_outcomes[[i]], |
| 208 | + arm = tmp$arm, |
| 209 | + t_cdf = mean(tmp3$t_cdf), |
| 210 | + step_values = step_values, |
| 211 | + value = 0)) |
213 | 212 | }
|
214 | 213 | }
|
| 214 | + } |
215 | 215 |
|
216 | 216 | # Order the data frame by step values
|
217 | 217 | hce_ecdf <- hce_ecdf[order(hce_ecdf$step_values), ]
|
|
0 commit comments