Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

object oriented re-write #17

Merged
merged 105 commits into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
105 commits
Select commit Hold shift + click to select a range
4148a77
first oop commit
bcjaeger Sep 12, 2022
e2f5db2
data object for pointers to arma objects
bcjaeger Sep 16, 2022
78ef315
trying to use sample
bcjaeger Sep 16, 2022
b4cdd3f
rcpp arma sample can only be defined once
bcjaeger Sep 17, 2022
57191db
bootstrap and surv classes
bcjaeger Sep 18, 2022
9d48cc7
informal memory trace check
bcjaeger Sep 19, 2022
29d581c
first oop commit
bcjaeger Sep 12, 2022
b7afb1c
data object for pointers to arma objects
bcjaeger Sep 16, 2022
77bd1a7
trying to use sample
bcjaeger Sep 16, 2022
3e2c2df
rcpp arma sample can only be defined once
bcjaeger Sep 17, 2022
ca9e7df
bootstrap and surv classes
bcjaeger Sep 18, 2022
4f27a8c
informal memory trace check
bcjaeger Sep 19, 2022
e845af1
arma objects causing trouble unless in header
bcjaeger Sep 20, 2022
62a287b
merged conf
bcjaeger Sep 23, 2022
2813295
progress to coxph
bcjaeger Sep 27, 2022
a14681b
learning headers
bcjaeger Oct 5, 2022
ccb8d41
non-working cph
bcjaeger Jun 30, 2023
010ba14
working cph code
bcjaeger Jun 30, 2023
3e586e3
coxph test passes
bcjaeger Jul 10, 2023
dfa4c2a
untested nodesplitstat
bcjaeger Jul 10, 2023
3ed132f
test failing nodesplitstat
bcjaeger Jul 11, 2023
1f77114
nodesplitstats code passing lrt tests
bcjaeger Jul 12, 2023
110b149
starting to modularize lrt multi
bcjaeger Jul 14, 2023
0ff92f4
more like ranger data
bcjaeger Aug 6, 2023
5e75fa9
test from home
bcjaeger Aug 6, 2023
b31637f
getting more specific with Rcpp data transfer
bcjaeger Aug 6, 2023
b58844d
thinking about trees
bcjaeger Aug 8, 2023
c9f0672
tinkering with init for trees
bcjaeger Aug 8, 2023
70b2e6b
faster bootstrap samples
bcjaeger Aug 9, 2023
c1820fe
handling R function passage
bcjaeger Aug 11, 2023
41504b7
getting to coxph in tree grow
bcjaeger Aug 12, 2023
396f139
incorporated coxph into grow
bcjaeger Aug 14, 2023
6292458
setting up logrank compare
bcjaeger Aug 14, 2023
37f04fc
setting up vi pointers
bcjaeger Aug 15, 2023
52ed250
already catching bugs! weights in trees now sum to n total
bcjaeger Aug 16, 2023
c70413d
vi references included, need to make these pointers
bcjaeger Aug 17, 2023
4971461
tree growing do loop setup
bcjaeger Aug 17, 2023
283faeb
tree outputs now stdvecs, bc it seems these are most flexible and rel…
bcjaeger Aug 22, 2023
6949b96
parallel, very bare bones
bcjaeger Aug 23, 2023
6bf288b
placeholder ptrs for threads
bcjaeger Aug 23, 2023
8c0af92
bug fix on cp sample, n_threads an input, and split_max_stat incorpor…
bcjaeger Aug 23, 2023
4c61747
bug hunting
bcjaeger Aug 24, 2023
b579af1
drop the debug log
bcjaeger Aug 25, 2023
ccf41eb
ignore debug log
bcjaeger Aug 25, 2023
05b089f
ignore debug log take 2
bcjaeger Aug 25, 2023
027ec57
retries included
bcjaeger Aug 25, 2023
42bd613
try to ignore output txt file again
bcjaeger Aug 25, 2023
61fd7c0
showprogress and check interrupts
bcjaeger Aug 25, 2023
f231894
R functions from trees thx to RObjects
bcjaeger Aug 26, 2023
4c362b6
prep for prediction
bcjaeger Aug 27, 2023
dae3d3a
prediction progress; not quite there
bcjaeger Aug 27, 2023
996d311
oobag functions, needs testing and denom tune
bcjaeger Aug 31, 2023
1418944
predict in threads almost
bcjaeger Aug 31, 2023
4ac3457
separate name for cutpoint sampler
bcjaeger Sep 2, 2023
bca62b2
send unique vi vec to each thread, prevent shared memory access problem
bcjaeger Sep 2, 2023
2d56099
prep to merge main
bcjaeger Sep 3, 2023
fc9a243
merge main branch
bcjaeger Sep 3, 2023
786ef63
mort pre-computed
bcjaeger Sep 3, 2023
3315fce
more unique random number generators
bcjaeger Sep 4, 2023
58d3854
working shell for survival forest
bcjaeger Sep 5, 2023
eaeaeee
bigger shell for ForestSurvival
bcjaeger Sep 5, 2023
4ec93cf
shell for survival trees
bcjaeger Sep 5, 2023
b372d5b
slowly transferring code to survival classes
bcjaeger Sep 5, 2023
27f96ac
prep to use arma field for leaf data
bcjaeger Sep 6, 2023
70dec0e
survival subclass functions
bcjaeger Sep 7, 2023
822846e
mute oobag preds from empty trees
bcjaeger Sep 8, 2023
2db644d
almost done separating members into survival
bcjaeger Sep 11, 2023
d3a1f48
done moving attributes to survival class
bcjaeger Sep 11, 2023
156fa38
almost a sliver of vi permute functioning
bcjaeger Sep 14, 2023
46809bb
vi permute stable but buggy
bcjaeger Sep 14, 2023
4d4e04a
cant use tree rng to make rng in data class
bcjaeger Sep 14, 2023
28bf4ea
cleanup, plus eval_oobag_every might work in threads
bcjaeger Sep 16, 2023
10e40e7
runs on workstation now (maybe)
bcjaeger Sep 17, 2023
fd169b6
the merge begins
bcjaeger Sep 19, 2023
22e671a
drop unused node split code
bcjaeger Sep 19, 2023
fa548fa
back from conf
bcjaeger Sep 21, 2023
9e5e39c
no_fit does prevent fit now
bcjaeger Sep 21, 2023
341d643
hiccups from update
bcjaeger Sep 21, 2023
eeeb141
mort oobag! Still working out workflow of it
bcjaeger Sep 21, 2023
b9453e0
oob functions allowed
bcjaeger Sep 23, 2023
aac2a1c
much closer to survival::concordance
bcjaeger Sep 23, 2023
cb4476c
starting to make verbosity more flexible
bcjaeger Sep 24, 2023
9c56aac
merging new predict with old
bcjaeger Sep 25, 2023
c137536
the moby dick of bugs has been caught
bcjaeger Sep 26, 2023
4d2dae1
oob leaf preds
bcjaeger Sep 26, 2023
246ecda
some support for leaf and non-aggregate preds
bcjaeger Sep 26, 2023
524dc28
merging new VI with current orsf_vi syntax
bcjaeger Sep 27, 2023
2521766
more trees in the noise/scale tests
bcjaeger Sep 27, 2023
4a1b7cf
toying with compute_dependence function for Forests
bcjaeger Sep 28, 2023
ba30364
about to fix pd backend api
bcjaeger Sep 30, 2023
ea632ac
solid progress but need to fix the data restore mechanics
bcjaeger Oct 1, 2023
7caff97
about to rework saved values
bcjaeger Oct 1, 2023
bb83a06
must reset oob denom while doing pd loops
bcjaeger Oct 1, 2023
79d0727
core features might be stable again
bcjaeger Oct 1, 2023
1d6efed
ready to merge
bcjaeger Oct 1, 2023
4b602a4
adding docs, fix col sample edge case
bcjaeger Oct 2, 2023
0696ee1
a day of chasing the RNG bug
bcjaeger Oct 3, 2023
f8c1f53
getting docs updated
bcjaeger Oct 3, 2023
cc14bf5
cleaner n_thread doc and option for n_thread=0
bcjaeger Oct 3, 2023
3f0dc66
ignore scratch
bcjaeger Oct 3, 2023
cc188fc
move scratch.R instead
bcjaeger Oct 3, 2023
adce44d
checks for new orsf args
bcjaeger Oct 3, 2023
290cb8e
draft some release notes
bcjaeger Oct 3, 2023
7a76258
doc updates
bcjaeger Oct 3, 2023
5788982
formula tests get a specific file
bcjaeger Oct 3, 2023
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
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@
^Rmd/
lastMiKTeXException
^\.zenodo\.json$
^scratch\.R$
10 changes: 9 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
# aorsf 0.0.8
# aorsf 0.1.0 (unreleased)

* Re-worked `aorsf`'s C++, code following the design of `ranger`, to set it up for classification and regression trees.

* Allowed multi-threading to be performed in `orsf()`, `predict.orsf_fit()`, and functions in the `orsf_vi()` and `orsf_pd()` family.

* Allowed for sampling without replacement and sampling a specific fraction of observations in `orsf()`

* Included Harrell's C-statistic as an option for assessing goodness of splits while growing trees.

* Fixed an issue where an uninformative error message would occur when `pred_horizon` was > max(time) for `orsf_summarize_uni`. Thanks to @JyHao1 and @DustinMLong for finding this!

Expand Down
64 changes: 12 additions & 52 deletions R/RcppExports.R
Original file line number Diff line number Diff line change
@@ -1,67 +1,27 @@
# Generated by using Rcpp::compileAttributes() -> do not edit by hand
# Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393

std_setdiff <- function(x, y) {
.Call(`_aorsf_std_setdiff`, x, y)
coxph_fit_exported <- function(x_node, y_node, w_node, method, cph_eps, cph_iter_max) {
.Call(`_aorsf_coxph_fit_exported`, x_node, y_node, w_node, method, cph_eps, cph_iter_max)
}

x_node_scale_exported <- function(x_, w_) {
.Call(`_aorsf_x_node_scale_exported`, x_, w_)
compute_cstat_exported_vec <- function(y, w, p, pred_is_risklike) {
.Call(`_aorsf_compute_cstat_exported_vec`, y, w, p, pred_is_risklike)
}

leaf_kaplan_testthat <- function(y, w) {
.Call(`_aorsf_leaf_kaplan_testthat`, y, w)
compute_cstat_exported_uvec <- function(y, w, g, pred_is_risklike) {
.Call(`_aorsf_compute_cstat_exported_uvec`, y, w, g, pred_is_risklike)
}

newtraph_cph_testthat <- function(x_in, y_in, w_in, method, cph_eps_, iter_max) {
.Call(`_aorsf_newtraph_cph_testthat`, x_in, y_in, w_in, method, cph_eps_, iter_max)
compute_logrank_exported <- function(y, w, g) {
.Call(`_aorsf_compute_logrank_exported`, y, w, g)
}

lrt_multi_testthat <- function(y_node_, w_node_, XB_, n_split_, leaf_min_events_, leaf_min_obs_) {
.Call(`_aorsf_lrt_multi_testthat`, y_node_, w_node_, XB_, n_split_, leaf_min_events_, leaf_min_obs_)
cph_scale <- function(x, w) {
.Call(`_aorsf_cph_scale`, x, w)
}

oobag_c_harrell_testthat <- function(y_mat, s_vec) {
.Call(`_aorsf_oobag_c_harrell_testthat`, y_mat, s_vec)
}

ostree_pred_leaf_testthat <- function(tree, x_pred_) {
.Call(`_aorsf_ostree_pred_leaf_testthat`, tree, x_pred_)
}

orsf_fit <- function(x, y, weights, n_tree, n_split_, mtry_, leaf_min_events_, leaf_min_obs_, split_min_events_, split_min_obs_, split_min_stat_, cph_method_, cph_eps_, cph_iter_max_, cph_do_scale_, net_alpha_, net_df_target_, oobag_pred_, oobag_pred_type_, oobag_pred_horizon_, oobag_eval_every_, oobag_importance_, oobag_importance_type_, tree_seeds, max_retry_, f_beta, type_beta_, f_oobag_eval, type_oobag_eval_, verbose_progress) {
.Call(`_aorsf_orsf_fit`, x, y, weights, n_tree, n_split_, mtry_, leaf_min_events_, leaf_min_obs_, split_min_events_, split_min_obs_, split_min_stat_, cph_method_, cph_eps_, cph_iter_max_, cph_do_scale_, net_alpha_, net_df_target_, oobag_pred_, oobag_pred_type_, oobag_pred_horizon_, oobag_eval_every_, oobag_importance_, oobag_importance_type_, tree_seeds, max_retry_, f_beta, type_beta_, f_oobag_eval, type_oobag_eval_, verbose_progress)
}

orsf_oob_negate_vi <- function(x, y, forest, last_eval_stat, time_pred_, f_oobag_eval, pred_type_, type_oobag_eval_) {
.Call(`_aorsf_orsf_oob_negate_vi`, x, y, forest, last_eval_stat, time_pred_, f_oobag_eval, pred_type_, type_oobag_eval_)
}

orsf_oob_permute_vi <- function(x, y, forest, last_eval_stat, time_pred_, f_oobag_eval, pred_type_, type_oobag_eval_) {
.Call(`_aorsf_orsf_oob_permute_vi`, x, y, forest, last_eval_stat, time_pred_, f_oobag_eval, pred_type_, type_oobag_eval_)
}

orsf_pred_uni <- function(forest, x_new, time_dbl, pred_type) {
.Call(`_aorsf_orsf_pred_uni`, forest, x_new, time_dbl, pred_type)
}

orsf_pred_multi <- function(forest, x_new, time_vec, pred_type) {
.Call(`_aorsf_orsf_pred_multi`, forest, x_new, time_vec, pred_type)
}

pd_new_smry <- function(forest, x_new_, x_cols_, x_vals_, probs_, time_dbl, pred_type) {
.Call(`_aorsf_pd_new_smry`, forest, x_new_, x_cols_, x_vals_, probs_, time_dbl, pred_type)
}

pd_oob_smry <- function(forest, x_new_, x_cols_, x_vals_, probs_, time_dbl, pred_type) {
.Call(`_aorsf_pd_oob_smry`, forest, x_new_, x_cols_, x_vals_, probs_, time_dbl, pred_type)
}

pd_new_ice <- function(forest, x_new_, x_cols_, x_vals_, probs_, time_dbl, pred_type) {
.Call(`_aorsf_pd_new_ice`, forest, x_new_, x_cols_, x_vals_, probs_, time_dbl, pred_type)
}

pd_oob_ice <- function(forest, x_new_, x_cols_, x_vals_, probs_, time_dbl, pred_type) {
.Call(`_aorsf_pd_oob_ice`, forest, x_new_, x_cols_, x_vals_, probs_, time_dbl, pred_type)
orsf_cpp <- function(x, y, w, tree_type_R, tree_seeds, loaded_forest, lincomb_R_function, oobag_R_function, n_tree, mtry, sample_with_replacement, sample_fraction, vi_type_R, vi_max_pvalue, leaf_min_events, leaf_min_obs, split_rule_R, split_min_events, split_min_obs, split_min_stat, split_max_cuts, split_max_retry, lincomb_type_R, lincomb_eps, lincomb_iter_max, lincomb_scale, lincomb_alpha, lincomb_df_target, lincomb_ties_method, pred_mode, pred_type_R, pred_horizon, pred_aggregate, oobag, oobag_eval_type_R, oobag_eval_every, pd_type_R, pd_x_vals, pd_x_cols, pd_probs, n_thread, write_forest, run_forest, verbosity) {
.Call(`_aorsf_orsf_cpp`, x, y, w, tree_type_R, tree_seeds, loaded_forest, lincomb_R_function, oobag_R_function, n_tree, mtry, sample_with_replacement, sample_fraction, vi_type_R, vi_max_pvalue, leaf_min_events, leaf_min_obs, split_rule_R, split_min_events, split_min_obs, split_min_stat, split_max_cuts, split_max_retry, lincomb_type_R, lincomb_eps, lincomb_iter_max, lincomb_scale, lincomb_alpha, lincomb_df_target, lincomb_ties_method, pred_mode, pred_type_R, pred_horizon, pred_aggregate, oobag, oobag_eval_type_R, oobag_eval_every, pd_type_R, pd_x_vals, pd_x_cols, pd_probs, n_thread, write_forest, run_forest, verbosity)
}

125 changes: 103 additions & 22 deletions R/check.R
Original file line number Diff line number Diff line change
Expand Up @@ -610,9 +610,13 @@
n_tree = NULL,
n_split = NULL,
n_retry = NULL,
n_thread = NULL,
mtry = NULL,
sample_with_replacement = NULL,
sample_fraction = NULL,
leaf_min_events = NULL,
leaf_min_obs = NULL,
split_rule = NULL,
split_min_events = NULL,
split_min_obs = NULL,
split_min_stat = NULL,
Expand Down Expand Up @@ -796,6 +800,25 @@

}

if(!is.null(n_thread)){

check_arg_type(arg_value = n_thread,
arg_name = 'n_thread',
expected_type = 'numeric')

check_arg_is_integer(arg_name = 'n_thread',
arg_value = n_thread)

check_arg_gteq(arg_name = 'n_thread',
arg_value = n_thread,
bound = 0)

check_arg_length(arg_name = 'n_thread',
arg_value = n_thread,
expected_length = 1)

}

if(!is.null(mtry)){

check_arg_type(arg_value = mtry,
Expand All @@ -815,6 +838,38 @@

}

if(!is.null(sample_with_replacement)){

check_arg_type(arg_value = sample_with_replacement,
arg_name = 'sample_with_replacement',
expected_type = 'logical')

check_arg_length(arg_name = 'sample_with_replacement',
arg_value = sample_with_replacement,
expected_length = 1)

}

if(!is.null(sample_fraction)){

check_arg_type(arg_value = sample_fraction,
arg_name = 'sample_fraction',
expected_type = 'numeric')

check_arg_gt(arg_value = sample_fraction,
arg_name = 'sample_fraction',
bound = 0)

check_arg_lteq(arg_value = sample_fraction,
arg_name = 'sample_fraction',
bound = 1)

check_arg_length(arg_value = sample_fraction,
arg_name = 'sample_fraction',
expected_length = 1)

}

if(!is.null(leaf_min_events)){

check_arg_type(arg_value = leaf_min_events,
Expand Down Expand Up @@ -852,6 +907,22 @@

}

if(!is.null(split_rule)){

check_arg_type(arg_value = split_rule,
arg_name = 'split_rule',
expected_type = 'character')

check_arg_length(arg_value = split_rule,
arg_name = 'split_rule',
expected_length = 1)

check_arg_is_valid(arg_value = split_rule,
arg_name = 'split_rule',
valid_options = c("logrank", "cstat"))

}

if(!is.null(split_min_events)){

check_arg_type(arg_value = split_min_events,
Expand Down Expand Up @@ -916,19 +987,14 @@
arg_name = 'oobag_pred_type',
expected_length = 1)

if(oobag_pred_type == 'mort') stop(
"Out-of-bag mortality predictions aren't supported yet. ",
" Sorry for the inconvenience - we plan on including this option",
" in a future update.",
call. = FALSE
)

check_arg_is_valid(arg_value = oobag_pred_type,
arg_name = 'oobag_pred_type',
valid_options = c("none",
"surv",
"risk",
"chf"))
"chf",
"mort",
"leaf"))

}

Expand All @@ -938,13 +1004,17 @@
arg_name = 'oobag_pred_horizon',
expected_type = 'numeric')

check_arg_length(arg_value = oobag_pred_horizon,
arg_name = 'oobag_pred_horizon',
expected_length = 1)
# check_arg_length(arg_value = oobag_pred_horizon,
# arg_name = 'oobag_pred_horizon',
# expected_length = 1)

check_arg_gteq(arg_value = oobag_pred_horizon,
arg_name = 'oobag_pred_horizon',
bound = 0)
for(i in seq_along(oobag_pred_horizon)){

check_arg_gteq(arg_value = oobag_pred_horizon[i],
arg_name = 'oobag_pred_horizon',
bound = 0)

}

}

Expand Down Expand Up @@ -1000,7 +1070,7 @@

check_arg_is_integer(tree_seeds, arg_name = 'tree_seeds')

if(length(tree_seeds) != n_tree){
if(length(tree_seeds) > 1 && length(tree_seeds) != n_tree){

stop('tree_seeds should have length <', n_tree,
"> (the number of trees) but instead has length <",
Expand Down Expand Up @@ -1550,7 +1620,8 @@
valid_options = c("risk",
"surv",
"chf",
"mort"))
"mort",
"leaf"))

}

Expand Down Expand Up @@ -1615,8 +1686,8 @@

oobag_fun_args <- names(formals(oobag_fun))

if(length(oobag_fun_args) != 2) stop(
"oobag_fun should have 2 input arguments but instead has ",
if(length(oobag_fun_args) != 3) stop(
"oobag_fun should have 3 input arguments but instead has ",
length(oobag_fun_args),
call. = FALSE
)
Expand All @@ -1627,8 +1698,14 @@
call. = FALSE
)

if(oobag_fun_args[2] != 's_vec') stop(
"the second input argument of oobag_fun should be named 's_vec' ",
if(oobag_fun_args[2] != 'w_vec') stop(
"the second input argument of oobag_fun should be named 'w_vec' ",
"but is instead named '", oobag_fun_args[1], "'",
call. = FALSE

Check warning on line 1704 in R/check.R

View check run for this annotation

Codecov / codecov/patch

R/check.R#L1701-L1704

Added lines #L1701 - L1704 were not covered by tests
)

if(oobag_fun_args[3] != 's_vec') stop(
"the third input argument of oobag_fun should be named 's_vec' ",
"but is instead named '", oobag_fun_args[2], "'",
call. = FALSE
)
Expand All @@ -1637,9 +1714,12 @@
test_status <- rep(c(0,1), each = 50)

.y_mat <- cbind(time = test_time, status = test_status)
.w_vec <- rep(1, times = 100)
.s_vec <- seq(0.9, 0.1, length.out = 100)

test_output <- try(oobag_fun(y_mat = .y_mat, s_vec = .s_vec),
test_output <- try(oobag_fun(y_mat = .y_mat,
w_vec = .w_vec,
s_vec = .s_vec),
silent = FALSE)

if(is_error(test_output)){
Expand All @@ -1649,8 +1729,9 @@
"test_time <- seq(from = 1, to = 5, length.out = 100)\n",
"test_status <- rep(c(0,1), each = 50)\n\n",
"y_mat <- cbind(time = test_time, status = test_status)\n",
"w_vec <- rep(1, times = 100)\n",
"s_vec <- seq(0.9, 0.1, length.out = 100)\n\n",
"test_output <- oobag_fun(y_mat = y_mat, s_vec = s_vec)\n\n",
"test_output <- oobag_fun(y_mat = y_mat, w_vec = w_vec, s_vec = s_vec)\n\n",
"test_output should be a numeric value of length 1",
call. = FALSE)

Expand Down
15 changes: 15 additions & 0 deletions R/compute_mean_leaves.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@


compute_mean_leaves <- function(forest){

if(is.null(forest$leaf_summary)){
return(0)

Check warning on line 6 in R/compute_mean_leaves.R

View check run for this annotation

Codecov / codecov/patch

R/compute_mean_leaves.R#L6

Added line #L6 was not covered by tests
}

collapse::fmean(
vapply(forest$leaf_summary,
function(leaf_smry) sum(leaf_smry != 0),
FUN.VALUE = integer(1))
)

}
49 changes: 49 additions & 0 deletions R/misc.R
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,55 @@

}

#' Find cut-point boundaries (R version)
#'
#' Used to test the cpp version for finding cutpoints
#'
#' @param y_node outcome matrix
#' @param w_node weight vector
#' @param XB linear combination of predictors
#' @param xb_uni unique values in XB
#' @param leaf_min_events min no. of events in a leaf
#' @param leaf_min_obs min no. of observations in a leaf
#'
#' @noRd
#'
#' @return data.frame with description of valid cutpoints
cp_find_bounds_R <- function(y_node,
w_node,
XB,
xb_uni,
leaf_min_events,
leaf_min_obs){

status = y_node[, 'status']

Check warning on line 128 in R/misc.R

View check run for this annotation

Codecov / codecov/patch

R/misc.R#L128

Added line #L128 was not covered by tests

cp_stats <-
sapply(
X = xb_uni,
FUN = function(x){
c(
cp = x,
e_right = sum(status[XB > x]),
e_left = sum(status[XB <= x]),
n_right = sum(XB > x),
n_left = sum(XB <= x)

Check warning on line 139 in R/misc.R

View check run for this annotation

Codecov / codecov/patch

R/misc.R#L130-L139

Added lines #L130 - L139 were not covered by tests
)
}
)

cp_stats <- as.data.frame(t(cp_stats))

Check warning on line 144 in R/misc.R

View check run for this annotation

Codecov / codecov/patch

R/misc.R#L144

Added line #L144 was not covered by tests

cp_stats$valid_cp = with(
cp_stats,
e_right >= leaf_min_events & e_left >= leaf_min_events &
n_right >= leaf_min_obs & n_left >= leaf_min_obs

Check warning on line 149 in R/misc.R

View check run for this annotation

Codecov / codecov/patch

R/misc.R#L146-L149

Added lines #L146 - L149 were not covered by tests
)

cp_stats

Check warning on line 152 in R/misc.R

View check run for this annotation

Codecov / codecov/patch

R/misc.R#L152

Added line #L152 was not covered by tests

}

has_units <- function(x){
inherits(x, 'units')
}
Expand Down
Loading
Loading