Learn R Programming

spareg (version 1.1.1)

plot.spar: Plot Method for 'spar' Object

Description

Plot values of validation measure or number of active variables over different thresholds or number of models for 'spar' object, or residuals vs fitted

Usage

# S3 method for spar
plot(
  x,
  plot_type = c("val_measure", "val_numactive", "res_vs_fitted", "coefs"),
  plot_along = c("nu", "nummod"),
  nummod = NULL,
  nu = NULL,
  xfit = NULL,
  yfit = NULL,
  prange = NULL,
  coef_order = NULL,
  digits = 2L,
  ...
)

Value

'ggplot2::ggplot' object

Arguments

x

result of spar function of class 'spar'.

plot_type

one of c("val_measure", "val_numactive", "res_vs_fitted", "coefs").

plot_along

one of c("nu","nummod"); ignored when plot_type = "res_vs_fitted".

nummod

fixed value for number of models when plot_along = "nu" for plot_type = "val_measure" or "val_numactive"; same as for predict.spar when plot_type="res_vs_fitted".

nu

fixed value for \(\nu\) when plot_along="nummod" for plot_type = "val_measure" or "val_numactive"; same as for predict.spar when plot_type="res_vs_fitted".

xfit

data used for predictions in "res_vs_fitted".

yfit

data used for predictions in "res_vs_fitted".

prange

optional vector of length 2 for "coefs"-plot to give the limits of the predictors' plot range; defaults to c(1, p).

coef_order

optional index vector of length p for plot_type = "coefs" to give the order of the predictors; defaults to 1 : p.

digits

number of significant digits to be displayed in the axis; defaults to 2L.

...

further arguments passed to or from other methods

Examples

Run this code
example_data <- simulate_spareg_data(n = 100, p = 400, ntest = 100)
spar_res <- spar(example_data$x, example_data$y, xval = example_data$xtest,
  yval = example_data$ytest, nummods=c(5, 10))
plot(spar_res)
plot(spar_res, plot_type = "val_measure", plot_along = "nummod", nu = 0)
plot(spar_res, plot_type = "val_measure", plot_along = "nu", nummod = 10)
plot(spar_res, plot_type = "val_numactive",  plot_along = "nummod", nu = 0)
plot(spar_res, plot_type = "val_numactive",  plot_along = "nu", nummod = 10)
plot(spar_res, plot_type = "res_vs_fitted",  xfit = example_data$xtest,
  yfit = example_data$ytest)
plot(spar_res, plot_type = "coefs", prange = c(1,400))

Run the code above in your browser using DataLab