Skip to contents

This function determines an ordering of the predictors based on the regularization path of the penalized regression; in particular, the predictors are ordered based on the order in which the coefficients are included in the model as the penalty strength decreases.

Usage

path.order(fit)

Arguments

fit

A fit object whose coef() method returns a matrix of coefficients with the intercept in the first row and one column per penalty strength (as produced by typical penalized-regression implementations).

Value

An ordering of the predictors.

Examples

### generate synthetic data
set.seed(1)
n           = 200
p           = 30
X           = matrix(rnorm(n*p),n,p)
beta        = double(p)
beta[1:10]  = 1:10
y           = X %*% beta + rnorm(n)

### build a minimal example 'fit' object with the same structure as a
### fit from a penalized regression: a coefficient matrix with the
### intercept in row 1 and one column per (decreasing) penalty value.
beta_path   = matrix(0, p + 1, p)
for (k in 1:p) beta_path[k + 1, k:p] = 1
fit         = list(coefficients = beta_path)
order       = path.order(fit)