pr_tree: Probabilistic Regression Trees (PRTrees)

View source: R/prtree_main.R

pr_treeR Documentation

Probabilistic Regression Trees (PRTrees)

Description

Fits a Probabilistic Regression Tree (PRTree) model. This is the main user-facing function of the package.

Usage

pr_tree(y, X, control = list(), ...)

Arguments

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 ... argument.

...

Control parameters to be passed to pr_tree_control. These will override any parameters specified in the control list.

Details

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:

  1. Extract the optimal \boldsymbol\sigma from the fitted model (model$sigma)

  2. Create a new control object with sigma_grid = matrix(model$sigma, nrow = 1) and set prop_hold = 0 to use all data for training

  3. Run pr_tree again

Value

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 colnames(X) or a vector with generic names ⁠X1,...,Xn_feat⁠

yhat

The estimated values for y.

XRegion

A matrix with two columns indicating the terminal node (region) each observation belongs to. The first column (TRUE) may have NA for observations with missing values. The second column (Internal) shows the region assigned by the algorithm.

dist

A list with distribution information:

  • dist_name: Name of the distribution ("norm", "lnorm", "t", "gamma").

  • dist_code: Integer code used by Fortran (1-4).

  • par_name: Name of the distribution parameter (e.g., "df", "shape").

  • <par_name>: Value of the distribution parameter.

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 \gamma_j weights estimated for the returned tree

mse

The mean squared error for the training, test/validation, and global datasets.

sigma

The optimal \boldsymbol\sigma vector selected by the grid search.

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.

References

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")}

See Also

pr_tree_cv for cross-validation options.

pr_tree_control for setting control parameters.

expand_sigma_grid for creating custom sigma grids.

Examples

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)


PRTree documentation built on Nov. 23, 2026, 9:08 a.m.