Skip to contents

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.

Usage

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

Arguments

object

A fitted model object of class "savvyPR" returned by savvyPR.

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 = "response".

type

Type of prediction required. Can be "response" (fitted values) or "coefficients". Defaults to "response".

...

Additional arguments (currently unused in this function).

Value

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.

Details

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.

See also

Author

Ziwei Chen, Vali Asimit and Pietro Millossovich
Maintainer: Ziwei Chen <ziwei.chen.3@citystgeorges.ac.uk>

Examples

# 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")
#>             [,1]
#> [1,]  0.28875944
#> [2,]  1.25922648
#> [3,]  0.08748994
#> [4,] -1.40839843
#> [5,]  2.48023221

# 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")
#>             [,1]
#> [1,]  0.17654967
#> [2,]  0.93541346
#> [3,]  0.01512945
#> [4,] -1.08740163
#> [5,]  1.74665121

# Extract coefficients
predict(fit_budget, type = "coefficients")
#> (Intercept)          V1          V2          V3          V4          V5 
#>  -0.1276835  -0.6241244  -0.7659382   0.7451672  -0.6588579   0.5418841 
#>          V6          V7          V8          V9         V10         V11 
#>  -0.5547075   0.5139377  -0.4280244  -0.5469627   0.5556044   0.6648925 
#>         V12         V13         V14         V15         V16         V17 
#>   0.4577995  -0.7904907   0.4804409   0.6494294  -0.6285696  -0.8838885 
#>         V18         V19         V20 
#>  -0.5773568   0.6777546  -0.7786869