glmnet_pca: Fit a polygenic model with 'glmnet' and principal components

View source: R/glmnet_pca.R

glmnet_pcaR Documentation

Fit a polygenic model with glmnet and principal components

Description

This 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.

Usage

glmnet_pca(X, y, pcs = NULL, cv = FALSE, ...)

Arguments

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 glmnet and other regression models expect (even lm).

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 X, predictors in this pcs matrix, are not penalized, and their coefficients are not included in the output.

cv

If TRUE, run glmnet::cv.glmnet() instead of glmnet::glmnet(), returning that respective output (with small modifications). Recommended to help pick the best lambda value for the penalized regression. Default FALSE. In both cases, PCs are modeled the same special way described above.

...

Additional parameters passed to glmnet::glmnet() or glmnet::cv.glmnet(). Cannot include penalty.factor, which is set internally so that loci are equally penalized and pcs are unpenalized.

Value

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).

See Also

glmnet::glmnet() and glmnet::cv.glmnet() for the functions this function wraps around, to better understand additional options and return values.

Examples

## Not run: 
# regular glmnet
obj <- glmnet_pca(X, y, pcs)

# cross validation version
obj <- glmnet_pca(X, y, pcs, cv = TRUE)

## End(Not run)


OchoaLab/polygenr documentation built on March 18, 2022, 10:52 a.m.