glmnet_pca | R Documentation |
glmnet
and principal componentsThis function makes it easy to fit a LASSO or Elastic Net model while including principal components or other fixed effects that are not part of the variable selection process and are not penalized.
This resembles in spirit and functionality the snpnet
function of the same package, except that one requires the genetic data to be written into a plink2 file whereas this one requires inputs that are ordinary R matrices.
The cross-validation glmnet
function is also optionally adapted here.
glmnet_pca(X, y, pcs = NULL, cv = FALSE, ...)
X |
The genotype matrix.
It must be oriented with loci along rows and individuals along columns, which agrees with other genetics packages by the main author, although this is transposed from what |
y |
The trait vector. It must have length equal to the number of individuals. |
pcs |
The PC (eigenvector) matrix (optional).
It must have individuals along the rows and dimensions along the columns.
Unlike |
cv |
If |
... |
Additional parameters passed to |
If cv = FALSE
, a glmnet
object (see glmnet::glmnet()
), otherwise a cv.glmnet
object (see glmnet::cv.glmnet()
).
However, the respective beta
matrices (obj$beta
or obj$glmnet.fit$beta
, respectively) are modified to exclude coefficients for the pcs
elements (only include coefficients for loci in X
).
glmnet::glmnet()
and glmnet::cv.glmnet()
for the functions this function wraps around, to better understand additional options and return values.
## Not run: # regular glmnet obj <- glmnet_pca(X, y, pcs) # cross validation version obj <- glmnet_pca(X, y, pcs, cv = TRUE) ## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.