View source: R/plot.cv.savvyPR.R
| plot.cv.savvyPR | R Documentation |
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,
...
)
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 <ziwei.chen.3@citystgeorges.ac.uk>
cv.savvyPR
# 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.