Skip to content

Commit 83b2461

Browse files
committed
more refactor
1 parent 024429b commit 83b2461

File tree

1 file changed

+29
-15
lines changed

1 file changed

+29
-15
lines changed

R/hcp.R

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ ci_hcp <- function(cis, estimates, value, dist, est, rescale, nboot, hc) {
8787
}
8888

8989
censoring <- censoring / rescale
90-
90+
9191
ests <- boot_estimates(fun = fun, dist = dist, estimates = estimates,
9292
pars = pars, nboot = nboot, data = data, weighted = weighted,
9393
censoring = censoring, min_pmix = min_pmix,
@@ -212,10 +212,26 @@ hcp_weighted <- function(hcp, weight, value, method, nboot) {
212212
# wt = rep(1, length(value)),
213213
method = method,
214214
nboot = nboot,
215-
# pboot = min$pboot
215+
# pboot = min$pboot
216216
)
217217
}
218218

219+
.ssd_hcp_ind <- function(x, value, ci, level, nboot, min_pboot, estimates,
220+
data, rescale,
221+
weighted, censoring, min_pmix, range_shape1,
222+
range_shape2, parametric, fix_weights,
223+
average, control, hc, save_to, samples, fun, method) {
224+
weight <- purrr::map_dbl(estimates, function(x) x$weight)
225+
hcp <- purrr::map2(x, weight, .ssd_hcp_tmbfit,
226+
value = value, ci = ci, level = level, nboot = nboot,
227+
min_pboot = min_pboot,
228+
data = data, rescale = rescale, weighted = weighted, censoring = censoring,
229+
min_pmix = min_pmix, range_shape1 = range_shape1, range_shape2 = range_shape2,
230+
parametric = parametric, fix_weights = fix_weights, average = average, control = control,
231+
hc = hc, save_to = save_to, samples = samples, fun = fun)
232+
hcp_ind(hcp, weight, method)
233+
}
234+
219235
.ssd_hcp_fitdists <- function(
220236
x,
221237
value,
@@ -268,8 +284,18 @@ hcp_weighted <- function(hcp, weight, value, method, nboot) {
268284

269285
method <- if (parametric) "parametric" else "non-parametric"
270286

271-
# roll this block into own function and then call with ci = FALSE to get estimates if needed.
272287
if(!average) {
288+
hcp_ind <- .ssd_hcp_ind(
289+
x, value = value, ci = ci, level = level, nboot = nboot,
290+
min_pboot = min_pboot, estimates = estimates,
291+
data = data, rescale = rescale, weighted = weighted, censoring = censoring,
292+
min_pmix = min_pmix, range_shape1 = range_shape1, range_shape2 = range_shape2,
293+
parametric = parametric, fix_weights = fix_weights, average = average, control = control,
294+
hc = hc, save_to = save_to, samples = samples, fun = fun, method = method)
295+
return(hcp_ind)
296+
}
297+
298+
if(!multi) {
273299
weight <- purrr::map_dbl(estimates, function(x) x$weight)
274300
hcp <- purrr::map2(x, weight, .ssd_hcp_tmbfit,
275301
value = value, ci = ci, level = level, nboot = nboot,
@@ -278,18 +304,6 @@ hcp_weighted <- function(hcp, weight, value, method, nboot) {
278304
min_pmix = min_pmix, range_shape1 = range_shape1, range_shape2 = range_shape2,
279305
parametric = parametric, fix_weights = fix_weights, average = average, control = control,
280306
hc = hc, save_to = save_to, samples = samples, fun = fun)
281-
return(hcp_ind(hcp, weight, method))
282-
}
283-
284-
if(!multi) {
285-
weight <- purrr::map_dbl(estimates, function(x) x$weight)
286-
hcp <- purrr::map2(x, weight, .ssd_hcp_tmbfit,
287-
value = value, ci = ci, level = level, nboot = nboot,
288-
min_pboot = min_pboot,
289-
data = data, rescale = rescale, weighted = weighted, censoring = censoring,
290-
min_pmix = min_pmix, range_shape1 = range_shape1, range_shape2 = range_shape2,
291-
parametric = parametric, fix_weights = fix_weights, average = average, control = control,
292-
hc = hc, save_to = save_to, samples = samples, fun = fun)
293307

294308
# TODO: implement hcp_weighted
295309
# TODO: perhaps rename average to unweighted

0 commit comments

Comments
 (0)