stat_glmnet_coef: Generating multiple knockoff statistics using coefficient...

Description Usage Arguments Value Examples

View source: R/generate_statistics.R

Description

This function computes the knockoff statistics based on the absolute value of the coefficient estimate from glmnet.

Usage

1
2
3
4
5
6
7
8
9
stat_glmnet_coef(
  X,
  X_k,
  y,
  omega,
  family = "gaussian",
  nlam = 500,
  lam_min_ratio = 5e-04
)

Arguments

X

A n-by-p matrix of original variables

X_k

A n-by-d matrix of multiple knockoff variables

y

A n vector of response

omega

A p vector indicating the weights for each variable. For now, we require each entry to be an integer greater than or equal to 2.

family

The conditional distribution of y given X. See the family option for glmnet.

nlam

Number of tuning parameter lambda used in fitting the lasso. Default to be 500.

lam_min_ratio

The ratio of the minimum and the maximum value of lambda in constructing the tuning parameters. Default to be 1e-4.

Value

An list of three components:

kappa

the vector of indices of winner for each variable competing with its multiple knockoff counterparts. kappa[j] = 1 indicates that the original variable is beating all of its knockoff counterparts, and kappa[j] not equal to 1 means otherwise.

tau

a vector of scores determining the order for which we consider to include variables into the model.

score_total

the matrix containing the original 'glmnet' coefficient estimates for each variable and its knockoff counterparts. For example, score_total[1:omega[j], j] is the coefficients estimates for the j-th variables and its omega_j - 1 knockoff counterparts.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
library(cheapknockoff)
set.seed(123)
n <- 100
p <- 30
x <- matrix(data = rnorm(n * p), nrow = n, ncol = p)
y <- x[, 1] - 2 * x[, 2] + rnorm(n)
omega <- c(2, 9, sample(seq(2, 9), size = 28, replace = TRUE))
# construct multiple knockoffs
X_k <- multiple_knockoff_Gaussian(X = x, mu = rep(0, p), Sigma = diag(1, p), omega = omega)
# compute knockoff statistics
stat <- cheapknockoff::stat_glmnet_coef(X = x, X_k = X_k, y = y, omega = omega)

hugogogo/cheapknockoff documentation built on Sept. 15, 2021, 1:06 p.m.