View source: R/prtree_control.R
| pr_tree_control | R Documentation |
This function creates a list of control parameters for the
pr_tree function, with validation for each parameter.
pr_tree_control(sigma_grid = NULL, grid_size = 8, min_mult = 0,
max_mult = 2, tiny_sigma = NULL, max_terminal_nodes = 15L,
max_depth = max_terminal_nodes - 1, cp = 0.01, n_min = 5L,
prop_x = 0.1, p_min = 0.05, prop_hold = 0.2, idx_train = NULL,
fill_type = 2L, proxy_crit = "both", n_candidates = 3L,
by_node = FALSE, dist = "norm", iprint = -1, verbose = TRUE, ...)
sigma_grid |
Optional. Custom grid of candidate Note: The dimensions of |
grid_size |
Integer. Number of candidate vectors to generate when
|
min_mult |
Numeric. Minimum multiplier for automatic grid generation. Default is 0. See ‘Details’ for how this defines the multiplier interval. Ignored when a custom grid is provided. |
max_mult |
Numeric. Maximum multiplier for automatic grid generation. Default is 2. Ignored when a custom grid is provided. |
tiny_sigma |
A single numeric value or |
max_terminal_nodes |
A non-negative integer. The maximum number of terminal nodes (regions/leaves) in the output tree. The default is 15. |
max_depth |
A non-negative integer. The maximum depth of the decision
tree. The depth is defined as the length of the longest path from the root
to a leaf. The default is |
cp |
A positive numeric value. The complexity parameter. Any split that
does not decrease the MSE (mean square error) by a factor of at least |
n_min |
A positive integer. The minimum number of observations required in a terminal (final) node. While Probabilistic Regression Trees can theoretically handle empty regions, this restriction is enforced to ensure the stable and well-posed calculation of the region's cut points (thresholds) based on empirical data. The default is 5. |
prop_x |
A numeric value between 0 and 1. The minimum proportion of
observations in a region that must have a probability greater than |
p_min |
A numeric value between 0 and 1. The threshold probability used
in conjunction with |
prop_hold |
A numeric value between 0 (inclusive) and 1 (exclusive) that
specifies the proportion of the data to be held out for model validation or
testing. Default is |
idx_train |
Optional integer vector specifying which observations to use
as the training sample. Default is |
fill_type |
Integer indicating the method to be used to fill the
probability matrix when
|
proxy_crit |
Character. Default is
|
n_candidates |
Integer. The number of competing candidates to consider
when searching for the best split. To select the candidates, a proxy
improvement measure is used. Then a full analysis is performed to choose
the best among the |
by_node |
Logical. If |
dist |
Character. The distribution to be used in the model. One of
|
iprint |
Integer. Controls the verbosity of the Fortran backend. Default is -1 (silent).
|
verbose |
Logical. If |
... |
Extra parameters to be passed to the chosen distribution.
|
Custom grid specification
When a custom grid is provided via sigma_grid, it must follow these rules:
A single number is expanded to a constant vector (same value for all features).
A numeric vector of length p (the number of features)
is used directly as one candidate vector.
A k \times p numeric matrix provides k candidates,
one per row.
In all custom grid cases, the automatic grid parameters (grid_size,
min_mult, max_mult, tiny_sigma) are ignored.
Automatic grid generation
The automatic grid is generated as follows:
For each feature j, the base values are the empirical standard deviations
\hat\sigma_j from the training data.
If grid_size = 1, the grid consists solely of these base values
\hat{\boldsymbol\sigma}.
If grid_size > 1, the grid is constructed using grid_size
multipliers equally spaced in the interval:
(min_mult, max_mult] when min_mult = 0 (excludes 0, includes max_mult).
[min_mult, max_mult] when min_mult > 0 (both inclusive).
Each multiplier m generates a candidate vector m \times \hat{\boldsymbol\sigma}.
If tiny_sigma is provided, it is added as an extra candidate (first
row) with \boldsymbol\sigma = \text{tiny\_sigma} \cdot
\boldsymbol{1}_p, where \boldsymbol{1}_p is a vector of ones of
length p (the number of features). This results in a final grid of
size grid_size + 1.
Splitting Constraints and Numerical Stability
The parameters prop_x and p_min work together to control the splitting
process. A splitting attempt is made in a given region only when at least a
proportion prop_x of the training rows have a probability greater than
p_min in that region's column of the probability matrix P. The split
will be ignored if any of the resulting child regions do not meet this same
criterion.
Warning: Setting either parameter to zero may lead to near-zero
columns in P, making the matrix computationally singular or
ill-conditioned for inversion.
Data Splitting Strategy
The package uses a flexible data splitting strategy controlled by the
prop_hold and idx_train arguments:
Automatic Split (idx_train = NULL): The training indices
are computed automatically based on prop_hold. The split uses stratified
sampling to ensure that the proportion of observations with missing values
is preserved across the training and validation/test sets.
Manual Split (idx_train provided): The supplied indices
are used directly, and prop_hold is ignored. The vector must be a valid
subset of 1:nrow(X). This approach is useful for reusing specific splits
from previous analyses, performing custom cross-validation, or ensuring
identical training sets across different models.
Role of the Hold-out Set
When prop_hold > 0 and idx_train is NULL, the exact role of the
held-out data depends on the grid search parameters (sigma_grid or grid_size):
Multiple candidates (grid_size > 1): The hold-out data acts
as a validation set to select the best \boldsymbol\sigma.
If prop_hold = 0, the selection is based on the in-sample MSE of the
training data.
Single candidate (grid_size = 1): The hold-out data acts
as a test set to evaluate the final model. If prop_hold = 0,
the entire dataset is used for training without an independent test evaluation.
A list of class prtree.control containing the validated control
parameters.
# Get default control parameters
controls <- pr_tree_control()
# Customize some parameters
ctrl1 <- pr_tree_control(max_depth = 5, n_candidates = 5)
# equivalent calls
ctrl2.v1 <- pr_tree_control(dist = "t", df = 4)
ctrl2.v2 <- pr_tree_control(dist = "t", dist_pars = list(df = 4))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.