# create.second_order: Second-order Gaussian knockoffs In knockoff: The Knockoff Filter for Controlled Variable Selection

## Description

This function samples second-order multivariate Gaussian knockoff variables. First, a multivariate Gaussian distribution is fitted to the observations of X. Then, Gaussian knockoffs are generated according to the estimated model.

## Usage

 `1` ```create.second_order(X, method = c("asdp", "equi", "sdp"), shrink = F) ```

## Arguments

 `X` n-by-p matrix of original variables. `method` either "equi", "sdp" or "asdp" (default: "asdp"). This determines the method that will be used to minimize the correlation between the original variables and the knockoffs. `shrink` whether to shrink the estimated covariance matrix (default: F).

## Details

If the argument `shrink` is set to T, a James-Stein-type shrinkage estimator for the covariance matrix is used instead of the traditional maximum-likelihood estimate. This option requires the package `corpcor`. See `cov.shrink` for more details.

Even if the argument `shrink` is set to F, in the case that the estimated covariance matrix is not positive-definite, this function will apply some shrinkage.

## Value

A n-by-p matrix of knockoff variables.

## References

Candes et al., Panning for Gold: Model-free Knockoffs for High-dimensional Controlled Variable Selection, arXiv:1610.02351 (2016). https://web.stanford.edu/group/candes/knockoffs/index.html

Other create: `create.fixed()`, `create.gaussian()`
 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17``` ```p=200; n=100; k=15 rho = 0.4 Sigma = toeplitz(rho^(0:(p-1))) X = matrix(rnorm(n*p),n) %*% chol(Sigma) nonzero = sample(p, k) beta = 3.5 * (1:p %in% nonzero) y = X %*% beta + rnorm(n) # Basic usage with default arguments result = knockoff.filter(X, y, knockoffs=create.second_order) print(result\$selected) # Advanced usage with custom arguments knockoffs = function(X) create.second_order(X, method='equi') result = knockoff.filter(X, y, knockoffs=knockoffs) print(result\$selected) ```