predict.savvySh_model: Predict Method for Slab and Shrinkage Linear Regression...

View source: R/predict.savvSh.R

predict.savvySh_modelR Documentation

Predict Method for Slab and Shrinkage Linear Regression Models

Description

Generate predictions (fitted values) or extract regression coefficients from a savvySh_model object returned by savvySh. This function allows you to specify one or more shrinkage estimators (via the estimator parameter) available in the model. If no estimator is specified, all available estimators are used and their results are returned in a named list.

Usage

## S3 method for class 'savvySh_model'
predict(
  object,
  newx = NULL,
  type = c("response", "coefficients"),
  estimator = NULL,
  ...
)

Arguments

object

A fitted savvySh_model object produced by savvySh.

newx

A numeric matrix of new predictor data for which to generate predictions. This argument is required if type = "response" and is ignored if type = "coefficients".

type

A character string specifying the output type. Options are "response" to return predicted values and "coefficients" to extract regression coefficient vectors. Defaults to "response".

estimator

A character vector naming one or more shrinkage estimator(s) to use. These must match names present in object$coefficients. If NULL, all available estimators are used.

...

Additional arguments (currently unused).

Details

The behavior depends on the value of type:

"response":

Generates predicted values using the coefficient estimates from the specified shrinkage estimator(s) for new data supplied via newx.

"coefficients":

Extracts the regression coefficient vector(s) corresponding to the specified estimator(s). Coefficient names are assigned based on whether an intercept is present (for Linear shrinkage, no intercept).

If no estimator is specified, the function returns results for all available estimators as a named list. If a single estimator is specified (or only one is provided in the vector), the result is returned as a numeric vector (for coefficients) or a numeric vector of predictions (for response).

Value

If type = "response", the function returns:

  • A numeric vector of predicted values if exactly one estimator is specified;

  • Otherwise, a named list of numeric vectors, one for each specified estimator.

If type = "coefficients", the function returns:

  • A named numeric vector of regression coefficients if exactly one estimator is specified;

  • Otherwise, a named list of numeric vectors corresponding to each specified estimator.

Author(s)

Ziwei Chen, Vali Asimit, Marina Anca Cidota, Jennifer Asimit
Maintainer: Ziwei Chen <ziwei.chen.3@citystgeorges.ac.uk>

See Also

savvySh for fitting slab and shrinkage linear models, coef.savvySh_model for direct coefficient extraction.

Examples

# Generate simulated data
set.seed(123)
x <- matrix(rnorm(100 * 5), 100, 5)
y <- rnorm(100)

# Fit a Multiplicative shrinkage model
fit <- savvySh(x, y, model_class = "Multiplicative")

# Generate predictions for new data
new_x <- matrix(rnorm(10 * 5), 10, 5)
preds <- predict(fit, newx = new_x, type = "response")

# Extract coefficients for specific estimators
coefs_st <- predict(fit, type = "coefficients", estimator = "St")


savvySh documentation built on March 3, 2026, 5:08 p.m.