sprinter: Reluctant Interaction Modeling

Description Usage Arguments Value See Also Examples

View source: R/sprinter.R

Description

This is the main function that fits interaction models with a path of tuning parameters (for Step 3).

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
sprinter(
  x,
  y,
  square = FALSE,
  num_keep = NULL,
  lambda1 = NULL,
  lambda3 = NULL,
  cv_step1 = FALSE,
  nlam1 = 10,
  nlam3 = 100,
  lam_min_ratio = ifelse(nrow(x) < ncol(x), 0.01, 1e-04),
  ...
)

Arguments

x

An n by p design matrix of main effects. Each row is an observation of p main effects.

y

A response vector of size n.

square

Indicator of whether squared effects should be fitted in Step 1. Default to be FALSE.

num_keep

A user specified number of candidate interactions to keep in Step 2. If num_keep is not specified (as default), it will be set to round[n / log n].

lambda1

Tuning parameter values for Step 1. lambda1 is a vector. Default to be NULL, and the program will compute its own lambda1 based on nlam1 and lam_min_ratio.

lambda3

Tuning parameter values for Step 3. lambda3 is a matrix, where the k-th column is the list of tuning parameter in Step 3 corresponding to Step 1 using lambda1[k]. Default to be NULL, and the program will compute its own lambda3 based on nlam3 and lam_min_ratio.

cv_step1

Indicator of whether cross-validation of lambda1 should be carried out in Step 1 before subsequent steps. Default is FALSE.

nlam1

the number of values in lambda1. If not specified, they will be all set to 10.

nlam3

the number of values in each column of lambda3. If not specified, they will be all set to 100.

lam_min_ratio

The ratio of the smallest and the largest values in lambda1 and each column of lambda2. The largest value is usually the smallest value for which all coefficients are set to zero. Default to be 1e-2 in the n < p setting.

...

other arguments to be passed to the glmnet calls, such as alpha or penalty.factor

Value

An object of S3 class "sprinter".

square

The square parameter passed into sprinter

n

The number of observations in the dataset

p

The number of main effects

step1

The output from fitting Step 1

lambda1

The path of tuning parameters passed into / computed for fitting Step 1

step2

The output from the screening Step 2

num_keep

The path of tuning parameters for Step 2

step3

The output from fitting Step 3

lambda3

The path of tuning parameters passed into / computed for fitting Step 3

main_center

Column centers of the input main effects

main_scale

Column scales of the input main effects

call

Function call.

See Also

cv.sprinter

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
set.seed(123)
n <- 100
p <- 100
# dense input
x <- matrix(rnorm(n * p), n, p)
y <- x[, 1] - 2 * x[, 2] + 3 * x[, 1] * x[, 3] - 4 * x[, 4] * x[, 5] + rnorm(n)
mod <- sprinter(x = x, y = y)

# sparse input
library(Matrix)
x <- Matrix::Matrix(0, n, p)
idx <- cbind(sample(seq(n), size = 10, replace = TRUE), sample(seq(p), size = 10, replace = TRUE))
x[idx] <- 1
y <- x[, 1] - 2 * x[, 2] + 3 * x[, 1] * x[, 3] - 4 * x[, 4] * x[, 5] + rnorm(n)
mod <- sprinter(x = x, y = y)

hugogogo/sprintr documentation built on Dec. 14, 2021, 6:07 p.m.