View source: R/predict.savvyPR.R
| predict.savvyPR | R Documentation |
Predicts fitted values or extracts estimated coefficients from a fitted
parity regression model object. It handles models optimized
using either the "budget" or "target" parameterization method seamlessly.
## S3 method for class '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 Parity Regression Models
This function is an S3 method for the generic predict function. It utilizes the
parameters estimated during the fitting procedure. For type = "response", it computes
predictions based on the provided newx matrix. For type = "coefficients", it extracts
the estimated 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 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>
savvyPR
# Generate synthetic data
set.seed(123)
x <- matrix(rnorm(100 * 20), 100, 20)
y <- rnorm(100)
# Example 1: Predict using a Budget-based model
fit_budget <- savvyPR(x, y, method = "budget", val = 0.05)
predict(fit_budget, newx = x[1:5, ], type = "response")
# Example 2: Predict using a Target-based model
fit_target <- savvyPR(x, y, method = "target", val = 1)
predict(fit_target, newx = x[1:5, ], type = "response")
# Extract coefficients
predict(fit_budget, type = "coefficients")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.