View source: R/predict.cv.savvyPR.R
| predict.cv.savvyPR | R Documentation |
Predicts fitted values or extracts estimated coefficients from a fitted
cross-validated parity regression model object. It handles models optimized
using either the "budget" or "target" parameterization method seamlessly.
## S3 method for class 'cv.savvyPR'
predict(object, newx = NULL, type = c("response", "coefficients"), ...)
object |
A fitted model object of class |
newx |
Matrix of new data for which predictions are to be made. Must have the same number of columns as the training data.
This argument is required if |
type |
Type of prediction required. Can be |
... |
Additional arguments (currently unused in this function). |
Predict for Cross-Validated Parity Regression Models
This function is an S3 method for the generic predict function. It utilizes the optimal
model identified during the cross-validation procedure. For type = "response", it computes
predictions based on the provided newx matrix. For type = "coefficients", it extracts
the optimal coefficients. The underlying computation is delegated to an internal helper function
to ensure consistency across the package.
Depending on the type argument, this function returns:
"response": A numeric vector of predicted values corresponding to the rows of newx.
"coefficients": A named numeric vector of the estimated optimal coefficients. If the model was fitted with an intercept, it will be included as the first element.
Ziwei Chen, Vali Asimit and Pietro Millossovich
Maintainer: Ziwei Chen <ziwei.chen.3@citystgeorges.ac.uk>
cv.savvyPR
# Generate synthetic data
set.seed(123)
x <- matrix(rnorm(100 * 20), 100, 20)
y <- rnorm(100)
# Example 1: Predict using a cross-validated Budget-based model
cv_fit_budget <- cv.savvyPR(x, y, method = "budget", model_type = "PR3")
predict(cv_fit_budget, newx = x[1:5, ], type = "response")
# Example 2: Predict using a cross-validated Target-based model
cv_fit_target <- cv.savvyPR(x, y, method = "target", model_type = "PR1")
predict(cv_fit_target, newx = x[1:5, ], type = "response")
# Extract optimal coefficients
predict(cv_fit_budget, type = "coefficients")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.