refit: Refitting a path of selected variables from the cheapknockoff...

Description Usage Arguments Value Examples

View source: R/refit.R

Description

Refitting a path of selected variables from the cheapknockoff filter and compute prediction on the newdata

Usage

1
refit(path, x, y, newdata, family = "gaussian")

Arguments

path

A path of selected variables set

x

A n-by-p matrix of original variables

y

A n vector of response

newdata

A new data set of features that the predictions are computed

family

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

Value

a list consisting the refitted model and the corresponding prediction for each model on the path returned by generate_path.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
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)
# yield the path of selected variables
path <- cheapknockoff::generate_path(kappa = stat$kappa, tau = stat$tau)
# refit and compute predictions on the original data
refit_output <- refit(path, x, y, x)

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