Description Usage Arguments Details Value Examples
View source: R/knockoff_filters.R
This is an adaptation of the knockoff.filter function from the R-package knockoff.
1 2 | knockoff_filter(X, y, fdr = 0.2, family = "gaussian",
knockoffs = knockoffs_seq, statistic = stat_glmnet)
|
X |
data.frame (or tibble) with "numeric" and "factor" columns only. The number of columns, ncol(X) needs to be > 2. |
y |
response vector with |
fdr |
target false discovery rate. Can be a vector of multiple thresholds. |
family |
should be "gaussian" if y is numeric, but "binomial" if y is a binary factor variable. |
knockoffs |
user-specified function to construct knockoff of X. It must take as input
the data.frame (or tibble) X and return a data.frame (or tibble) X_k of corresponding
knockoffs. By default, |
statistic |
user-specified function that constructs feature statistics used to assess variable importance.
By default |
This function takes input X with either "numeric" or "factor" columns (or both), input y can be either
numeric or binary factor, and user may specify multiple fdr thresholds. The function performs the
knockoff filter, which consists of three steps: 1) Simulate knockoff of X with the input function knockoffs
,
2) calculate importance statistic W with the input function statistic
, and 3) calculate the knockoff+ threshold
for each target fdr provided. Finally, selection is made based on W > threshold.
if length(fdr)=1 the function returns a vector of selected indices, otherwise a list of selected indices, one selection vector per fdr threshold supplied.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | library(seqknockoff)
set.seed(1)
# Simulate 10 Gaussian covariate predictors:
X <- generate_X(n=1000, p=10, p_b=0, cov_type="cov_equi", rho=0.5)
# Simulate response from model y = X%*%beta + epsilon, where epsilon ~ N(0,1) with
# first 5 beta-coefficients = 8 (all other zero).
y <- generate_y(X, p_nn=5, a=8)
S <- knockoff_filter(X, y, fdr=c(0.05, 0.1, 0.2))
# dichotomize y for logistic regression knockoff filter:
y <- factor(y > median(y))
# Below the family argument gets passed to the statistic = knockoff::stat.glmnet_coefdiff function:
S <- knockoff_filter(X, y, fdr=c(0.05, 0.1, 0.2), family="binomial")
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.