| Title: | Savvy Parity Regression Model Estimation with 'savvyPR' |
|---|---|
| Description: | Implements the Savvy Parity Regression 'savvyPR' methodology for multivariate linear regression analysis. The package solves an optimization problem that balances the contribution of each predictor variable to ensure estimation stability in the presence of multicollinearity. It supports two distinct parameterization methods, a Budget-based approach that allocates a fixed loss contribution to each predictor, and a Target-based approach (t-tuning) that utilizes a relative elasticity weight for the response variable. The package provides comprehensive tools for model estimation, risk distribution analysis, and parameter tuning via cross-validation (PR1, PR2, and PR3 model types) to optimize predictive accuracy. Methods are based on Asimit, Chen, Ichim and Millossovich (2026) <https://openaccess.city.ac.uk/id/eprint/35005/>. |
| Authors: | Ziwei Chen [aut, cre] (ORCID: <https://orcid.org/0009-0009-6376-3850>), Vali Asimit [aut] (ORCID: <https://orcid.org/0000-0002-7706-0066>), Pietro Millossovich [aut] (ORCID: <https://orcid.org/0000-0001-8269-7507>) |
| Maintainer: | Ziwei Chen <[email protected]> |
| License: | GPL (>= 3) |
| Version: | 0.1.0 |
| Built: | 2026-05-23 09:03:59 UTC |
| Source: | https://github.com/ziwei-chenchen/savvypr |
Extracts the estimated coefficients corresponding to the optimal tuning parameters
from a fitted cross-validated parity regression model object. It seamlessly handles models
optimized using either the "budget" or "target" parameterization method.
## S3 method for class 'cv.savvyPR' coef(object, ...)## S3 method for class 'cv.savvyPR' coef(object, ...)
object |
A fitted model object of class |
... |
Additional arguments passed to the |
Extract Coefficients From a Cross-Validated Parity Regression Model Object
This function is an S3 method for the generic coef function. It extracts the coefficients
of the optimal model identified during the cross-validation procedure. The extraction is
internally delegated to the predict.cv.savvyPR method with type = "coefficients".
A named numeric vector of the estimated coefficients from the optimally tuned model. 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 <[email protected]>
cv.savvyPR, predict.cv.savvyPR
# Generate synthetic data set.seed(123) x <- matrix(rnorm(100 * 10), 100, 10) y <- rnorm(100) # Example 1: Extract coefficients from a Budget-based CV model cv_model_budget <- cv.savvyPR(x, y, method = "budget", model_type = "PR3") coef(cv_model_budget) # Example 2: Extract coefficients from a Target-based CV model cv_model_target <- cv.savvyPR(x, y, method = "target", model_type = "PR1") coef(cv_model_target)# Generate synthetic data set.seed(123) x <- matrix(rnorm(100 * 10), 100, 10) y <- rnorm(100) # Example 1: Extract coefficients from a Budget-based CV model cv_model_budget <- cv.savvyPR(x, y, method = "budget", model_type = "PR3") coef(cv_model_budget) # Example 2: Extract coefficients from a Target-based CV model cv_model_target <- cv.savvyPR(x, y, method = "target", model_type = "PR1") coef(cv_model_target)
Extracts the estimated coefficients from a fitted parity regression model object.
It seamlessly handles models fitted using either the "budget" or "target"
parameterization method.
## S3 method for class 'savvyPR' coef(object, ...)## S3 method for class 'savvyPR' coef(object, ...)
object |
A fitted model object of class |
... |
Additional arguments passed to the |
Extract Coefficients From a Parity Regression Model Object
This function is an S3 method for the generic coef function. It extracts the
estimated coefficients of the fitted model. The extraction is internally delegated to
the predict.savvyPR method with type = "coefficients".
A named numeric vector of the estimated coefficients from the fitted model. 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 <[email protected]>
# Generate synthetic data set.seed(123) x <- matrix(rnorm(100 * 10), 100, 10) y <- rnorm(100) # Example 1: Extract coefficients from a Budget-based model model_budget <- savvyPR(x, y, method = "budget", val = 0.05) coef(model_budget) # Example 2: Extract coefficients from a Target-based model model_target <- savvyPR(x, y, method = "target", val = 1) coef(model_target)# Generate synthetic data set.seed(123) x <- matrix(rnorm(100 * 10), 100, 10) y <- rnorm(100) # Example 1: Extract coefficients from a Budget-based model model_budget <- savvyPR(x, y, method = "budget", val = 0.05) coef(model_budget) # Example 2: Extract coefficients from a Target-based model model_target <- savvyPR(x, y, method = "target", val = 1) coef(model_target)
Performs k-fold cross-validation for Parity Regression (PR) models to select optimal tuning parameters. The underlying PR methodology distributes the total prediction error evenly across all parameters, ensuring stability in the presence of high multicollinearity and substantial noise (such as time series data with structural changes and evolving trends). This function supports both Budget-based and Target-based parameterizations and evaluates models across a variety of loss metrics.
cv.savvyPR( x, y, method = c("budget", "target"), vals = NULL, nval = 100, lambda_vals = NULL, nlambda = 100, folds = 10, model_type = c("PR3", "PR1", "PR2"), measure_type = c("mse", "mae", "rmse", "mape"), foldid = FALSE, use_feature_selection = FALSE, standardize = FALSE, intercept = TRUE, exclude = NULL )cv.savvyPR( x, y, method = c("budget", "target"), vals = NULL, nval = 100, lambda_vals = NULL, nlambda = 100, folds = 10, model_type = c("PR3", "PR1", "PR2"), measure_type = c("mse", "mae", "rmse", "mape"), foldid = FALSE, use_feature_selection = FALSE, standardize = FALSE, intercept = TRUE, exclude = NULL )
x |
A matrix of predictors with rows as observations and columns as variables. Must not contain |
y |
A numeric vector of the response variable, should have the same number of observations as |
method |
Character string specifying the parameterization method to use: |
vals |
Optional; a numeric vector of values for tuning the PR model (acts as |
nval |
Numeric value specifying the number of tuning values to try in the optimization process if |
lambda_vals |
Optional; a numeric vector of |
nlambda |
Numeric value specifying the number of |
folds |
The number of folds to be used in the cross-validation, default is |
model_type |
Character string specifying the type of model to fit. Defaults to |
measure_type |
Character vector specifying the measure to use for model evaluation. Defaults to |
foldid |
Logical indicating whether to return fold assignments. Defaults to |
use_feature_selection |
Logical indicating whether to perform feature selection during the model fitting process. Defaults to |
standardize |
Logical indicating whether to standardize predictor variables. Defaults to |
intercept |
Logical indicating whether to include an intercept in the model. Defaults to |
exclude |
Optional; indicate if any variables should be excluded in the model fitting process. |
Cross-Validation for Parity Regression Model Estimation
This function facilitates cross-validation for parity regression models across a range
of tuning values (val) and regularization values (), depending
on the model type specified. Each model type handles the parameters differently:
Performs cross-validation only over the val sequence while
fixing . This model type is primarily used when the focus is on
understanding how different levels of risk parity constraints impact the
model performance purely based on the parity mechanism without the influence
of ridge shrinkage.
Uses a fixed value determined by performing a ridge
regression (lambda optimization) using cv.glmnet
on the dataset. It then performs cross-validation over the val sequence
while using this optimized value. This approach is useful when
one wishes to maintain a stable amount of standard shrinkage while exploring
the impact of varying levels of the proportional contribution constraint.
First, determines an optimal val using the same method as PR1.
Then, keeping this val fixed, it conducts a cross-validation over all
possible values. This dual-stage optimization can be particularly
effective when the initial parity regularization needs further refinement
via adjustment.
The function supports several types of loss metrics for assessing model performance:
Mean Squared Error: Measures the average of the squares of the errors—that is, the average squared difference between the estimated values and the actual value.
Mean Absolute Error: Measures the average magnitude of the errors in a set of predictions, without considering their direction. It’s the average over the test sample of the absolute differences between prediction and actual observation where all individual differences have equal weight.
Root Mean Squared Error: It is the square root of the mean of the squared
errors. RMSE is a good measure of how accurately the model predicts the response,
and it is the most important criterion for fit if the main purpose of the model is prediction.
Mean Absolute Percentage Error: Measures the size of the error in percentage terms. It is calculated as the average of the unsigned percentage error, as shown above. Because it is based on relative errors, it is less sensitive to large deviations in small true values.
The choice of measure impacts how the model's performance is assessed during cross-validation. Users should select the measure that best reflects the requirements of their specific analytical context.
A list of class "cv.savvyPR" containing the following components based on the specified model_type:
call |
The matched call used to invoke the function. |
coefficients |
The optimal coefficients results of the final fitted model. |
mean_error_cv |
A vector of computed error values across all tested parameters. |
model_type |
The type of PR model used: |
measure_type |
The loss measure used for evaluation, with a descriptive name. |
method |
The parameterization method used: |
PR_fit |
The final fitted model object from the |
coefficients_cv |
A matrix of average coefficients across all cross-validation folds for each tuning parameter. |
vals |
The tuning values (acting as c or t) used in the cross-validation process. |
lambda_vals |
The |
optimal_val |
The optimal tuning value found from cross-validation, applicable to |
fixed_val |
The fixed tuning value used in |
optimal_lambda_val |
The optimal |
fixed_lambda_val |
The fixed |
optimal_index |
A list detailing the indices of the optimal parameters within the cross-validation matrix. |
fold_assignments |
(Optional) The fold assignments used during the cross-validation, provided if |
Ziwei Chen, Vali Asimit and Pietro Millossovich
Maintainer: Ziwei Chen <[email protected]>
Asimit, V., Chen, Z., Ichim, B., & Millossovich, P. (2026). Prity Regression Estimation. Retrieved from https://openaccess.city.ac.uk/id/eprint/37017/
The optimization technique employed follows the algorithm described by: F. Spinu (2013). An Algorithm for Computing Risk Parity Weights. SSRN Preprint. doi:10.2139/ssrn.2297383
savvyPR, glmnet, cv.glmnet,
calcLoss, getMeasureName, optimizeRiskParityBudget, optimizeRiskParityTarget
# Generate synthetic data set.seed(123) n <- 100 # Number of observations p <- 12 # Number of variables x <- matrix(rnorm(n * p), n, p) beta <- matrix(rnorm(p), p, 1) y <- x %*% beta + rnorm(n, sd = 0.5) # Example 1: PR1 with "budget" method (focusing on c values with MSE) result_pr1_budget <- cv.savvyPR(x, y, method = "budget", model_type = "PR1") print(result_pr1_budget) # Example 2: PR1 with "target" method result_pr1_target <- cv.savvyPR(x, y, method = "target", model_type = "PR1") print(result_pr1_target) # Example 3: PR3 (default model_type) exploring budget parameter result_pr3 <- cv.savvyPR(x, y, method = "budget", folds = 5) print(result_pr3)# Generate synthetic data set.seed(123) n <- 100 # Number of observations p <- 12 # Number of variables x <- matrix(rnorm(n * p), n, p) beta <- matrix(rnorm(p), p, 1) y <- x %*% beta + rnorm(n, sd = 0.5) # Example 1: PR1 with "budget" method (focusing on c values with MSE) result_pr1_budget <- cv.savvyPR(x, y, method = "budget", model_type = "PR1") print(result_pr1_budget) # Example 2: PR1 with "target" method result_pr1_target <- cv.savvyPR(x, y, method = "target", model_type = "PR1") print(result_pr1_target) # Example 3: PR3 (default model_type) exploring budget parameter result_pr3 <- cv.savvyPR(x, y, method = "budget", folds = 5) print(result_pr3)
Generates various visualizations for a fitted cross-validated parity regression
model object. It supports plotting estimated coefficients, risk contributions, coefficient
paths, and cross-validation error curves based on the specified plot_type.
## S3 method for class 'cv.savvyPR' plot( x, plot_type = c("estimated_coefficients", "risk_contributions", "cv_coefficients", "cv_errors"), label = TRUE, xvar = c("norm", "lambda", "dev", "val"), max_vars_per_plot = 10, ... )## S3 method for class 'cv.savvyPR' plot( x, plot_type = c("estimated_coefficients", "risk_contributions", "cv_coefficients", "cv_errors"), label = TRUE, xvar = c("norm", "lambda", "dev", "val"), max_vars_per_plot = 10, ... )
x |
A fitted model object of class |
plot_type |
Character string specifying the type of plot to generate. Can be |
label |
Logical; if
Default is |
xvar |
Character string specifying the x-axis variable for plotting coefficient paths. Options are |
max_vars_per_plot |
Integer specifying the maximum number of variables to plot per panel. Cannot exceed |
... |
Additional arguments passed to the underlying |
Plot for a Cross-Validated Parity Regression Model
This function offers four types of plots, depending on the value of plot_type:
Generates a line plot with points for the estimated
coefficients of the optimally tuned cross-validated regression model.
If an intercept term is included, it will be labeled as beta_0;
otherwise, coefficients are labeled sequentially based on the covariates.
If label = TRUE, numeric values are displayed on the plot. This plot
helps visualize the contribution of each predictor variable to the model.
Generates two bar plots, one for the optimization
variables (weights or target values) and one for risk contributions, from
the risk parity model. If label = TRUE, numeric labels are added
above the bars for clarity.
Generates a plot showing the coefficient paths against
the selected x-axis variable (val, lambda, norm,
or dev) depending on the model type:
PR1/PR2: Plots coefficient paths against log(val) values.
PR3: Plots coefficient paths against log(lambda) values.
Invalid combinations of model_type and xvar will result in an error:
PR1/PR2: Cannot use "lambda" as xvar.
PR3: Cannot use "val" as xvar.
If max_vars_per_plot exceeds 10, it is reset to 10.
The plot provides insight into how coefficients evolve across different
regularization parameters.
Generates a plot that shows the cross-validation
error metric against the logarithm of the tuning parameter (val or
lambda), depending on the model type. It adds a vertical dashed line
to indicate the optimal parameter value.
PR1/PR2: Plots cross-validation errors against log(val) values.
PR3: Plots cross-validation errors against log(lambda) values.
A ggplot object representing the requested plot.
Ziwei Chen, Vali Asimit and Pietro Millossovich
Maintainer: Ziwei Chen <[email protected]>
# Example usage for `cv.savvyPR` with Correlated Data: set.seed(123) n <- 100 p <- 10 # Create highly correlated predictors to demonstrate parity regression base_var <- rnorm(n) x <- matrix(rnorm(n * p, sd = 0.1), n, p) + base_var beta <- matrix(rnorm(p), p, 1) y <- x %*% beta + rnorm(n, sd = 0.5) # Fit CV model using Budget method cv_result1 <- cv.savvyPR(x, y, method = "budget", model_type = "PR1", measure_type = "mse", intercept = FALSE) plot(cv_result1, plot_type = "estimated_coefficients") plot(cv_result1, plot_type = "risk_contributions", label = FALSE) plot(cv_result1, plot_type = "cv_coefficients", xvar = "val", max_vars_per_plot = 10) plot(cv_result1, plot_type = "cv_errors") # Fit CV model using Target method cv_result2 <- cv.savvyPR(x, y, method = "target", model_type = "PR2") cv_result3 <- cv.savvyPR(x, y, method = "budget", model_type = "PR3") plot(cv_result2, plot_type = "cv_coefficients", xvar = "val", max_vars_per_plot = 5, label = FALSE) plot(cv_result3, plot_type = "cv_coefficients", xvar = "lambda", max_vars_per_plot = 10, label = TRUE) plot(cv_result2, plot_type = "cv_errors", label = FALSE) plot(cv_result3, plot_type = "cv_errors", label = TRUE)# Example usage for `cv.savvyPR` with Correlated Data: set.seed(123) n <- 100 p <- 10 # Create highly correlated predictors to demonstrate parity regression base_var <- rnorm(n) x <- matrix(rnorm(n * p, sd = 0.1), n, p) + base_var beta <- matrix(rnorm(p), p, 1) y <- x %*% beta + rnorm(n, sd = 0.5) # Fit CV model using Budget method cv_result1 <- cv.savvyPR(x, y, method = "budget", model_type = "PR1", measure_type = "mse", intercept = FALSE) plot(cv_result1, plot_type = "estimated_coefficients") plot(cv_result1, plot_type = "risk_contributions", label = FALSE) plot(cv_result1, plot_type = "cv_coefficients", xvar = "val", max_vars_per_plot = 10) plot(cv_result1, plot_type = "cv_errors") # Fit CV model using Target method cv_result2 <- cv.savvyPR(x, y, method = "target", model_type = "PR2") cv_result3 <- cv.savvyPR(x, y, method = "budget", model_type = "PR3") plot(cv_result2, plot_type = "cv_coefficients", xvar = "val", max_vars_per_plot = 5, label = FALSE) plot(cv_result3, plot_type = "cv_coefficients", xvar = "lambda", max_vars_per_plot = 10, label = TRUE) plot(cv_result2, plot_type = "cv_errors", label = FALSE) plot(cv_result3, plot_type = "cv_errors", label = TRUE)
Generates various visualizations for a fitted parity regression
model object. It supports plotting estimated coefficients and risk contributions
based on the specified plot_type.
## S3 method for class 'savvyPR' plot( x, plot_type = c("estimated_coefficients", "risk_contributions"), label = TRUE, ... )## S3 method for class 'savvyPR' plot( x, plot_type = c("estimated_coefficients", "risk_contributions"), label = TRUE, ... )
x |
A fitted model object of class |
plot_type |
Character string specifying the type of plot to generate. Can be |
label |
Logical; if
Default is |
... |
Additional arguments passed to the underlying |
Plot for a Parity Regression Model
This function offers two types of plots, depending on the value of plot_type:
Generates a line plot with points for the estimated
coefficients of the regression model. If an intercept term is included in the
model, it will be labeled as beta_0. Otherwise, the coefficients are
labeled sequentially as beta_1, beta_2, etc., based on the
covariates. This plot helps to visualize the contribution of each predictor
variable to the model. If label = TRUE, numeric values are displayed.
If the model includes a risk parity component, the
function will check if the optimization results (e.g., orp_fit$weights
for the budget method, or orp_fit$x for the target method, along with
orp_fit$relativeRiskContrib) are available. If available, two bar
plots are created:
Optimization Variables: A bar plot that visualizes the optimal variables assigned to each covariate and the response variable (weights for budget, target parameters for target).
Risk Contributions: A bar plot that visualizes the relative risk contributions of each covariate and the response variable.
If label = TRUE, numeric labels are added above the bars for clarity.
If they are not found, a warning is issued.
A ggplot object representing the requested plot.
Ziwei Chen, Vali Asimit and Pietro Millossovich
Maintainer: Ziwei Chen <[email protected]>
# Example usage for `savvyPR` with Correlated Data: set.seed(123) n <- 100 p <- 12 # Create highly correlated predictors to demonstrate parity regression base_var <- rnorm(n) x <- matrix(rnorm(n * p, sd = 0.1), n, p) + base_var beta <- matrix(rnorm(p), p, 1) y <- x %*% beta + rnorm(n, sd = 0.5) # Fit a Budget-based parity regression model result_budget <- savvyPR(x, y, method = "budget", val = 0.05, intercept = TRUE) plot(result_budget, plot_type = "estimated_coefficients", label = FALSE) plot(result_budget, plot_type = "risk_contributions", label = TRUE) # Fit a Target-based parity regression model result_target <- savvyPR(x, y, method = "target", val = 1, intercept = TRUE) plot(result_target, plot_type = "risk_contributions", label = TRUE)# Example usage for `savvyPR` with Correlated Data: set.seed(123) n <- 100 p <- 12 # Create highly correlated predictors to demonstrate parity regression base_var <- rnorm(n) x <- matrix(rnorm(n * p, sd = 0.1), n, p) + base_var beta <- matrix(rnorm(p), p, 1) y <- x %*% beta + rnorm(n, sd = 0.5) # Fit a Budget-based parity regression model result_budget <- savvyPR(x, y, method = "budget", val = 0.05, intercept = TRUE) plot(result_budget, plot_type = "estimated_coefficients", label = FALSE) plot(result_budget, plot_type = "risk_contributions", label = TRUE) # Fit a Target-based parity regression model result_target <- savvyPR(x, y, method = "target", val = 1, intercept = TRUE) plot(result_target, plot_type = "risk_contributions", label = TRUE)
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"), ...)## 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 <[email protected]>
# 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")# 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")
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"), ...)## 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 <[email protected]>
# 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")# 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")
Prints a summarized output of a fitted cross-validated parity regression model object. It clearly displays the optimal tuning parameters and the resulting estimated coefficients.
## S3 method for class 'cv.savvyPR' print(x, digits = max(3, getOption("digits") - 3), ...)## S3 method for class 'cv.savvyPR' print(x, digits = max(3, getOption("digits") - 3), ...)
x |
A fitted model object of class |
digits |
Significant digits to be used in the printout. |
... |
Additional arguments passed to the generic |
Print a Cross-Validated Parity Regression Model Object
This function is an S3 method for the generic print function. It formats and prints
the matched call that produced the cv.savvyPR object, followed by a summary data frame.
This summary includes:
The parameterization method used ("budget" or "target").
The number of non-zero coefficients.
Whether an intercept was included.
The optimal tuning value (val) and/or lambda parameter, depending on the model_type (PR1, PR2, or PR3).
Finally, it prints a data frame of the optimally tuned estimated coefficients.
Invisibly returns a data frame summarizing the cross-validation results, including the parameterization method, number of non-zero coefficients, and optimal tuning parameters.
Ziwei Chen, Vali Asimit and Pietro Millossovich
Maintainer: Ziwei Chen <[email protected]>
# Generate synthetic data set.seed(123) n <- 100 p <- 10 x <- matrix(rnorm(n * p), n, p) beta <- matrix(rnorm(p), p, 1) y <- x %*% beta + rnorm(n, sd = 0.5) # Fit and print a cross-validated budget-based parity regression model cv_fit_budget <- cv.savvyPR(x, y, method = "budget", model_type = "PR3") print(cv_fit_budget) # Fit and print a cross-validated target-based parity regression model cv_fit_target <- cv.savvyPR(x, y, method = "target", model_type = "PR1") print(cv_fit_target)# Generate synthetic data set.seed(123) n <- 100 p <- 10 x <- matrix(rnorm(n * p), n, p) beta <- matrix(rnorm(p), p, 1) y <- x %*% beta + rnorm(n, sd = 0.5) # Fit and print a cross-validated budget-based parity regression model cv_fit_budget <- cv.savvyPR(x, y, method = "budget", model_type = "PR3") print(cv_fit_budget) # Fit and print a cross-validated target-based parity regression model cv_fit_target <- cv.savvyPR(x, y, method = "target", model_type = "PR1") print(cv_fit_target)
Prints a summarized output of a fitted parity regression model object. It clearly displays the model's configuration and the resulting estimated coefficients.
## S3 method for class 'savvyPR' print(x, digits = max(3, getOption("digits") - 3), ...)## S3 method for class 'savvyPR' print(x, digits = max(3, getOption("digits") - 3), ...)
x |
A fitted model object of class |
digits |
Significant digits to be used in the printout. |
... |
Additional arguments passed to the generic |
Print a Parity Regression Model Object
This function is an S3 method for the generic print function. It formats and prints
the matched call that produced the savvyPR object, followed by a summary data frame.
This summary includes:
The parameterization method used ("budget" or "target").
The number of non-zero coefficients.
Whether an intercept was included.
The penalty value (lambda), if any was applied.
Finally, it prints a data frame of the estimated coefficients.
Invisibly returns a data frame summarizing the model, including the parameterization method, number of non-zero coefficients, intercept status, and lambda value.
Ziwei Chen, Vali Asimit and Pietro Millossovich
Maintainer: Ziwei Chen <[email protected]>
# Generate synthetic data set.seed(123) n <- 100 p <- 10 x <- matrix(rnorm(n * p), n, p) beta <- matrix(rnorm(p), p, 1) y <- x %*% beta + rnorm(n, sd = 0.5) # Fit and print a Budget-based model fit_budget <- savvyPR(x, y, method = "budget", val = 0.05) print(fit_budget) # Fit and print a Target-based model fit_target <- savvyPR(x, y, method = "target", val = 1) print(fit_target)# Generate synthetic data set.seed(123) n <- 100 p <- 10 x <- matrix(rnorm(n * p), n, p) beta <- matrix(rnorm(p), p, 1) y <- x %*% beta + rnorm(n, sd = 0.5) # Fit and print a Budget-based model fit_budget <- savvyPR(x, y, method = "budget", val = 0.05) print(fit_budget) # Fit and print a Target-based model fit_target <- savvyPR(x, y, method = "target", val = 1) print(fit_target)
Implements the Parity Regression (PR) methodology for multiple linear regression. Instead of minimizing the aggregate prediction error in the dependent variable, PR distributes the total prediction error evenly across all parameters. This approach ensures stability in the presence of high multicollinearity and is particularly suitable for data affected by substantial noise, such as time series data experiencing structural changes and evolving trends.
savvyPR( x, y, method = c("budget", "target"), val = NULL, lambda_val = NULL, use_feature_selection = FALSE, standardize = FALSE, intercept = TRUE, exclude = NULL )savvyPR( x, y, method = c("budget", "target"), val = NULL, lambda_val = NULL, use_feature_selection = FALSE, standardize = FALSE, intercept = TRUE, exclude = NULL )
x |
A matrix of predictors with rows as observations and columns as variables. Must not contain |
y |
A numeric vector of the response variable, should have the same number of observations as |
method |
Character string specifying the parameterization method to use: |
val |
Numeric tuning parameter. If |
lambda_val |
Optional; a numeric value specifying the regularization strength.
If |
use_feature_selection |
Logical; if |
standardize |
Logical; if |
intercept |
Logical; if |
exclude |
Optional; an array of indices specifying columns to be excluded from the analysis. |
Parity Regression Model Estimation
The PR methodology assigns an equal risk contribution constraint on each predictor variable within a specific search cone,
leading to a robust solution. This solution is defined in the context of a penalized regression,
wherein the penalty term is a function of both the regularization parameter (lambda_val) and the proportional contribution parameter (val).
The function uses the nleqslv package to solve non-linear systems of equations.
The function supports two parameterization methods:
Budget: Uses val (acting as c) to set a strict budget constraint on the risk contributions.
Target: Uses val (acting as t) to set a risk target for the response variable relative to the predictors.
The function can handle different practical scenarios:
While the PR theorem is not specifically designed for variable selection, the package makes this available as an optional preprocessing step.
If use_feature_selection is TRUE, Lasso regression is performed to select features by zeroing out non-contributive predictors before applying the PR model.
It checks the matrix rank of predictors and applies Ridge regression as a fallback to ordinary least squares if the matrix is not full rank, ensuring computational stability.
For the budget method, the PR methodology optimizes an objective function that includes a variance term and a penalization term:
For the target method, the methodology optimizes a related objective function defined by the target parameter :
In both formulas, represents the parameters (with as an auxiliary parameter set to 1), is the regularization parameter,
is the number of predictors, and is a constant with respect to .
The resulting model provides estimates of the regression coefficients that are equitable across all predictors in terms of contribution to the model's predictive power.
Returns an S3 object of class "savvyPR" containing the following components:
call |
The matched call to the function. |
coefficients |
A numeric vector of estimated coefficients. If the tuning parameter is zero, coefficients are obtained from Ridge regression or OLS. Otherwise, they are obtained from the parity regression model. |
method |
The optimization method used ( |
fit |
The fitted object returned by |
orp_fit |
The fitted object returned by the risk parity optimizer ( |
lambda |
The regularization parameter |
intercept |
A logical value indicating whether an intercept is included in the model. |
model |
A data frame containing the response variable |
Ziwei Chen, Vali Asimit and Pietro Millossovich
Maintainer: Ziwei Chen <[email protected]>
Asimit, V., Chen, Z., Ichim, B., & Millossovich, P. (2026). Prity Regression Estimation. Retrieved from https://openaccess.city.ac.uk/id/eprint/37017/
The optimization technique employed follows the algorithm described by: F. Spinu (2013). An Algorithm for Computing Risk Parity Weights. SSRN Preprint. doi:10.2139/ssrn.2297383
library(glmnet) library(nleqslv) # Generate synthetic data set.seed(123) n <- 100 # Number of observations p <- 10 # Number of variables x <- matrix(rnorm(n * p), n, p) beta <- matrix(rnorm(p), p, 1) y <- x %*% beta + rnorm(n, sd = 0.5) # Linear combination with noise # Example 1: Run PR estimation using the "budget" method (acting as c) result_budget <- savvyPR(x, y, method = "budget", val = 0.05, intercept = TRUE) print(result_budget$coefficients) # Example 2: Run PR estimation using the "target" method (acting as t) result_target <- savvyPR(x, y, method = "target", val = 1, intercept = TRUE) print(result_target$coefficients) # Example 3: Run PR estimation with feature selection result_fs <- savvyPR(x, y, method = "budget", val = 0.05, use_feature_selection = TRUE) print(result_fs$coefficients) # Inspect the risk parity portfolio object for more details if(!is.null(result_fs$orp_fit)) { print("Risk parity portfolio details:") print(result_fs$orp_fit) } # Example 4: Run PR estimation excluding some predictors result_exclude <- savvyPR(x, y, method = "budget", val = 0.05, exclude = c(1, 2)) print("Coefficients with first two predictors excluded:") print(result_exclude$coefficients)library(glmnet) library(nleqslv) # Generate synthetic data set.seed(123) n <- 100 # Number of observations p <- 10 # Number of variables x <- matrix(rnorm(n * p), n, p) beta <- matrix(rnorm(p), p, 1) y <- x %*% beta + rnorm(n, sd = 0.5) # Linear combination with noise # Example 1: Run PR estimation using the "budget" method (acting as c) result_budget <- savvyPR(x, y, method = "budget", val = 0.05, intercept = TRUE) print(result_budget$coefficients) # Example 2: Run PR estimation using the "target" method (acting as t) result_target <- savvyPR(x, y, method = "target", val = 1, intercept = TRUE) print(result_target$coefficients) # Example 3: Run PR estimation with feature selection result_fs <- savvyPR(x, y, method = "budget", val = 0.05, use_feature_selection = TRUE) print(result_fs$coefficients) # Inspect the risk parity portfolio object for more details if(!is.null(result_fs$orp_fit)) { print("Risk parity portfolio details:") print(result_fs$orp_fit) } # Example 4: Run PR estimation excluding some predictors result_exclude <- savvyPR(x, y, method = "budget", val = 0.05, exclude = c(1, 2)) print("Coefficients with first two predictors excluded:") print(result_exclude$coefficients)
Prints a comprehensive statistical summary of a fitted cross-validated parity regression model object. It displays the model's configuration, statistical summaries of the estimated coefficients, model fit statistics, and cross-validation results.
## S3 method for class 'cv.savvyPR' summary(object, ...)## S3 method for class 'cv.savvyPR' summary(object, ...)
object |
A fitted model object of class |
... |
Additional arguments passed to the generic |
Summary of a Fitted Cross-Validated Parity Regression Model with Statistics
This function is an S3 method for the generic summary function. It formats and prints
a detailed statistical overview of the optimal cross-validated model. The output includes:
The parameterization method used ("budget" or "target").
The matched call that produced the model.
Residual quantiles.
A table of estimated optimal coefficients with their corresponding standard errors, t-values, p-values, confidence intervals, and significance codes.
Overall model fit statistics, including Residual Standard Error, Multiple and Adjusted R-squared, F-statistic, AIC, BIC, and Deviance.
A Cross-Validation Summary displaying the minimum mean cross-validation error and the optimal tuning values (val and/or lambda).
Invisibly returns NULL. This function is primarily called for its side
effect of printing the summary to the console.
Ziwei Chen, Vali Asimit and Pietro Millossovich
Maintainer: Ziwei Chen <[email protected]>
# Simulate some data set.seed(123) n <- 100 p <- 10 x <- matrix(rnorm(n * p), n, p) beta <- matrix(rnorm(p), p, 1) y <- x %*% beta + rnorm(n, sd = 0.5) # Example 1: Fit and summarize a budget-based cross-validated model cv_fit_budget <- cv.savvyPR(x, y, method = "budget", model_type = "PR3") summary(cv_fit_budget) # Example 2: Fit and summarize a target-based cross-validated model cv_fit_target <- cv.savvyPR(x, y, method = "target", model_type = "PR1") summary(cv_fit_target)# Simulate some data set.seed(123) n <- 100 p <- 10 x <- matrix(rnorm(n * p), n, p) beta <- matrix(rnorm(p), p, 1) y <- x %*% beta + rnorm(n, sd = 0.5) # Example 1: Fit and summarize a budget-based cross-validated model cv_fit_budget <- cv.savvyPR(x, y, method = "budget", model_type = "PR3") summary(cv_fit_budget) # Example 2: Fit and summarize a target-based cross-validated model cv_fit_target <- cv.savvyPR(x, y, method = "target", model_type = "PR1") summary(cv_fit_target)
Prints a comprehensive statistical summary of a fitted parity regression model object. It displays the model's configuration, statistical summaries of the estimated coefficients, and overall model fit statistics.
## S3 method for class 'savvyPR' summary(object, ...)## S3 method for class 'savvyPR' summary(object, ...)
object |
A fitted model object of class |
... |
Additional arguments passed to the generic |
Summary of a Fitted Parity Regression Model with Statistics
This function is an S3 method for the generic summary function. It formats and prints
a detailed statistical overview of the fitted model. The output includes:
The parameterization method used ("budget" or "target").
The matched call that produced the model.
Residual quantiles.
A table of estimated coefficients with their corresponding standard errors, t-values, p-values, confidence intervals, and significance codes.
Overall model fit statistics, including Residual Standard Error, Multiple and Adjusted R-squared, F-statistic, AIC, BIC, and Deviance.
Invisibly returns NULL. This function is primarily called for its side
effect of printing the summary to the console.
Ziwei Chen, Vali Asimit and Pietro Millossovich
Maintainer: Ziwei Chen <[email protected]>
# Simulate some data set.seed(123) n <- 100 p <- 10 x <- matrix(rnorm(n * p), n, p) beta <- matrix(rnorm(p), p, 1) y <- x %*% beta + rnorm(n, sd = 0.5) # Example 1: Fit and summarize a Budget-based parity regression model fit_budget <- savvyPR(x, y, method = "budget", val = 0.05, intercept = FALSE) summary(fit_budget) # Example 2: Fit and summarize a Target-based parity regression model fit_target <- savvyPR(x, y, method = "target", val = 1, intercept = TRUE) summary(fit_target)# Simulate some data set.seed(123) n <- 100 p <- 10 x <- matrix(rnorm(n * p), n, p) beta <- matrix(rnorm(p), p, 1) y <- x %*% beta + rnorm(n, sd = 0.5) # Example 1: Fit and summarize a Budget-based parity regression model fit_budget <- savvyPR(x, y, method = "budget", val = 0.05, intercept = FALSE) summary(fit_budget) # Example 2: Fit and summarize a Target-based parity regression model fit_target <- savvyPR(x, y, method = "target", val = 1, intercept = TRUE) summary(fit_target)