fitfuns: Fit Functions for Stability Selection

Description Usage Arguments Details Value See Also Examples

Description

Functions that fit a model until q variables are selected and that returns the indices (and names) of the selected variables.

Usage

1
2
3
4
5
6
7
## package lars:
lars.lasso(x, y, q, ...)
lars.stepwise(x, y, q, ...)

## package glmnet:
glmnet.lasso(x, y, q, type = c("conservative", "anticonservative"), ...)
glmnet.lasso_maxCoef(x, y, q, ...)

Arguments

x

a matrix containing the predictors or an object of class "mboost".

y

a vector or matrix containing the outcome.

q

number of (unique) selected variables (or groups of variables depending on the model) that are selected on each subsample.

type

a charachter vector specifying if the number of selected variables per subsample is <= q (type = "conservative") or >= q (type = "anticonservative"). The conservative version ensures that the PFER is controlled.

...

additional arguments passed to the underlying fitting function. See the example on glmnet.lasso_maxCoef in stabsel for the specification of additional arguments via stabsel.

Details

All fitting functions are named after the package and the type of model that is fitted: package_name.model, e.g., glmnet.lasso stands for a lasso model that is fitted using the package glmnet.

glmnet.lasso_maxCoef fits a lasso model with a given penalty parameter and returns the q largest coefficients. If one wants to use glmnet.lasso_maxCoef, one must specify the penalty parameter lambda (via the ... argument) or in stabsel via args.fitfun(lambda = ). Note that usually, the penalty parameter cannot be specified but is chosen such that q variables are selected. For an example on how to use glmnet.lasso_maxCoef see stabsel.

Value

A named list with elements

selected

logical. A vector that indicates which variable was selected.

path

logical. A matrix that indicates which variable was selected in which step. Each row represents one variable, the columns represent the steps.

See Also

stabsel for stability selection itself.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
  if (require("TH.data")) {
      ## make data set available
      data("bodyfat", package = "TH.data")
  } else {
      ## simulate some data if TH.data not available. 
      ## Note that results are non-sense with this data.
      bodyfat <- matrix(rnorm(720), nrow = 72, ncol = 10)
  }
  
  if (require("lars")) {
      ## selected variables
      lars.lasso(bodyfat[, -2], bodyfat[,2], q = 3)$selected
      lars.stepwise(bodyfat[, -2], bodyfat[,2], q = 3)$selected
  }
  
  if (require("glmnet")) {
      glmnet.lasso(bodyfat[, -2], bodyfat[,2], q = 3)$selected
      ## selection path
      glmnet.lasso(bodyfat[, -2], bodyfat[,2], q = 3)$path
  
      ## Using the anticonservative glmnet.lasso (see args.fitfun):
      stab.glmnet <- stabsel(x = bodyfat[, -2], y = bodyfat[,2],
                             fitfun = glmnet.lasso, 
                             args.fitfun = list(type = "anticonservative"), 
                             cutoff = 0.75, PFER = 1)
  }

Example output

Loading required package: parallel
Loading required package: TH.data
Loading required package: survival
Loading required package: MASS

Attaching package: 'TH.data'

The following object is masked from 'package:MASS':

    geyser

Loading required package: lars
Loaded lars 1.2

Note: 'x' is coerced to a model matrix without intercept
Note: 'x' is coerced to a model matrix without intercept
         age    waistcirc      hipcirc elbowbreadth  kneebreadth     anthro3a 
       FALSE        FALSE         TRUE        FALSE         TRUE        FALSE 
    anthro3b     anthro3c      anthro4 
        TRUE        FALSE        FALSE 
Loading required package: glmnet
Loading required package: Matrix
Loading required package: foreach
Loaded glmnet 2.0-16

Note: 'x' is coerced to a model matrix without intercept
Note: 'x' is coerced to a model matrix without intercept

stabs documentation built on Jan. 29, 2021, 5:14 p.m.