| pr_tree | R Documentation |
Fits a Probabilistic Regression Tree (PRTree) model. This is the main user-facing function of the package.
pr_tree(y, X, control = list(), ...)
y |
A numeric vector for the dependent variable. |
X |
A strictly numeric matrix or data frame for the independent variables. Categorical variables or factors must be encoded (e.g., one-hot encoding) prior to model fitting. |
control |
A list of control parameters, typically created by
pr_tree_control. Default values are taken from pr_tree_control
for any parameters not specified. Alternatively, control parameters can
be passed directly via the |
... |
Control parameters to be passed to pr_tree_control.
These will override any parameters specified in the |
The tree is built using the training data specified by idx_train (or
determined by prop_hold). If validation data is available (the complement
of idx_train), it is used to select the optimal \boldsymbol\sigma values from
the grid.
Grid generation:
If sigma_grid is not provided, it is automatically generated using
only the training set (the observations identified by idx_train,
which can be passed via control or calculated internally from prop_hold).
The validation/test data is used only for evaluation.
Alternatively, users can create a custom grid using the helper function
expand_sigma_grid(X, ...) and pass it via the control parameter. This
allows using the full dataset (or any desired subset) to define the grid of
\boldsymbol\sigma values to be tested.
Important: The returned model is trained only on the training set, not on the combined training + validation data. This matches standard practice where validation data is used only for hyperparameter selection, not for final parameter estimation.
If you want to retrain the model using the selected \boldsymbol\sigma values on a
larger dataset (e.g., combining training and validation), you can:
Extract the optimal \boldsymbol\sigma from the fitted model (model$sigma)
Create a new control object with sigma_grid = matrix(model$sigma, nrow = 1)
and set prop_hold = 0 to use all data for training
Run pr_tree again
An object of class prtree containing the fitted model. This is a
list with the following components
n_obs |
Number of observations used in the model. |
n_feat |
Number of features (predictor variables) in the model. |
features |
The features names: either |
yhat |
The estimated values for |
XRegion |
A matrix with two columns indicating the terminal node (region)
each observation belongs to. The first column ( |
dist |
A list with distribution information:
|
fill_type |
Fortran code corresponding to the method used to fill the matrix P when missing values are present. |
P |
The matrix of probabilities for each terminal node. |
gamma |
The values of the |
mse |
The mean squared error for the training, test/validation, and global datasets. |
sigma |
The optimal |
nodes_matrix_info |
A matrix with information for each node of the tree. |
regions |
A data frame with the bounds of each variable in each node of the returned tree. |
Alkhoury, S., Devijver, E., Clausel, M., Tami, M., Gaussier, E., & Oppenheim, G. (2020). Smooth and Consistent Probabilistic Regression Trees. Advances in Neural Information Processing Systems, 33, 11345–11355.
Prass, T. S., Neimaier, A. S., & Pumi, G. (2026). Handling Missing Data in Probabilistic Regression Trees. Applied Mathematical Modelling, 117450. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1016/j.apm.2026.117450")}
Prass, T. S., Neimaier, A. S., & Pumi, G. (2025). PRTree: An R Package for Probabilistic Regression Trees with Built-in Missing Data Handling. arXiv preprint. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.48550/arXiv.2510.03634")}
pr_tree_cv for cross-validation options.
pr_tree_control for setting control parameters.
expand_sigma_grid for creating custom sigma grids.
set.seed(1234)
X <- matrix(runif(200, 0, 10), ncol = 1)
eps <- matrix(rnorm(200, 0, 0.05), ncol = 1)
y <- cos(X) + eps
# Fit model
reg <- pr_tree(y, X, max_terminal_nodes = 9, prop_hold = 0)
# Visualize fit (X is 1D, so we can plot the relationship)
ord <- order(X)
plot(X[ord], reg$yhat[ord],
type = "l", col = "blue", lwd = 2,
xlab = "x", ylab = "y",
main = "PRTree Fit to cos(x)"
)
points(X[ord], y[ord], col = "red", cex = 0.5)
legend("topright",
legend = c("Fitted", "Observed"),
col = c("blue", "red"), lty = c(1, NA), pch = c(NA, 1)
)
# Diagnostic plots
oldpar <- par(mar = c(3, 4, 1.5, 1))
plot(reg, y, which = c(1, 4, 2, 5), ncol = 2)
par(oldpar)
# Plotting the final tree
plot_tree(reg, max_bins = 10)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.