Skip to contents

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.

Usage

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

Arguments

object

A fitted model object of class "cv.savvyPR" returned by cv.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 optimal coefficients. If the model was fitted with an intercept, it will be included as the first element.

Details

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.

See also

Author

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

Examples

# \donttest{
# 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")
#>            [,1]
#> [1,] -0.1177877
#> [2,] -0.1147066
#> [3,] -0.1199733
#> [4,] -0.1205656
#> [5,] -0.1192975

# 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")
#>            [,1]
#> [1,] -0.0946370
#> [2,]  0.2040653
#> [3,] -0.1372762
#> [4,] -0.2632835
#> [5,] -0.3434257

# Extract optimal coefficients
predict(cv_fit_budget, type = "coefficients")
#>   (Intercept)            V1            V2            V3            V4 
#> -1.184536e-01 -9.113725e-04 -4.183957e-04  1.153707e-03 -1.110573e-04 
#>            V5            V6            V7            V8            V9 
#>  3.708384e-04 -4.670839e-04  1.414980e-04 -1.258821e-03 -3.001002e-04 
#>           V10           V11           V12           V13           V14 
#>  3.297216e-04  1.088015e-03  3.538372e-04 -1.007521e-03  5.554732e-04 
#>           V15           V16           V17           V18           V19 
#>  5.150588e-04 -7.288305e-04  7.643364e-05 -2.746647e-04  2.107192e-04 
#>           V20 
#> -1.065101e-03 
# }