booami_predict: Predict with booami models

View source: R/booami_predict.R

booami_predictR Documentation

Predict with booami models

Description

Minimal, dependency-free predictor for models fitted by cv_boost_raw, cv_boost_imputed, or a pooled impu_boost fit. Supports Gaussian (identity) and logistic (logit) models, returning either the linear predictor or, for logistic, predicted probabilities.

Usage

booami_predict(
  object,
  X_new,
  family = NULL,
  type = c("response", "link"),
  center_means = NULL
)

Arguments

object

A fit returned by cv_boost_raw(), cv_boost_imputed(), or a pooled impu_boost() (i.e., pool = TRUE so that $BETA is a length-p vector and $INT is a scalar).

X_new

New data (matrix or data.frame) with the same p predictors the model was trained on. If column names are present in the model, X_new will be aligned by name; otherwise it must be in the same order.

family

Model family; one of c("gaussian","logistic"). If NULL, the function tries to infer from object$type or attributes; otherwise defaults to "gaussian".

type

Prediction type; one of c("response","link"). For "gaussian", both are identical. For "logistic", "response" returns probabilities via the inverse-logit.

center_means

Optional numeric vector of length p with training means used to center predictors during fitting. If provided, X_new is centered as X_new - center_means before prediction. If the model stores means by name, pass a named vector whose names match predictor names.

Details

This function is deterministic and involves no random number generation. Coefficients are extracted from either $final_model (intercept first, then coefficients) or from $INT+$BETA (pooled impu_boost). If X_new has column names and the model has named coefficients, columns are aligned by name; otherwise they are used in order.

If your training pipeline centered covariates (e.g., center = "auto"), providing the same center_means here yields numerically consistent predictions. If not supplied but object$center_means exists, it will be used automatically. If both are supplied, the explicit center_means argument takes precedence.

Value

A numeric vector of predictions (length nrow(X_new)). If X_new has row names, they are propagated to the returned vector.

See Also

cv_boost_raw, cv_boost_imputed, impu_boost

Examples



# 1) Fit on data WITH missing values
set.seed(123)
sim_tr <- simulate_booami_data(
  n = 120, p = 12, p_inf = 3,
  type = "gaussian",
  miss = "MAR", miss_prop = 0.20
)
X_tr <- sim_tr$data[, 1:12]
y_tr <- sim_tr$data$y

fit <- cv_boost_raw(
  X_tr, y_tr,
  k = 2, mstop = 50, seed = 123,
  impute_args    = list(m = 2, maxit = 1, printFlag = FALSE, seed = 1),
  quickpred_args = list(method = "spearman", mincor = 0.30, minpuc = 0.60),
  show_progress  = FALSE
)

# 2) Predict on a separate data set WITHOUT missing values (same p)
sim_new <- simulate_booami_data(
  n = 5, p = 12, p_inf = 3,
  type = "gaussian",
  miss = "MCAR", miss_prop = 0   # <- complete data with existing API
)
X_new <- sim_new$data[, 1:12, drop = FALSE]

preds <- booami_predict(fit, X_new = X_new, family = "gaussian", type = "response")
round(preds, 3)



booami documentation built on Feb. 19, 2026, 5:07 p.m.