50% off | Unlimited Data & AI Learning
Get 50% off unlimited learning

Cross-Validation for Linear & Ridge Regression Models (Rcpp, RcppParallel & Eigen)

This package provides efficient implementations of cross-validation techniques for linear and ridge regression models, leveraging C++ code with Rcpp, RcppParallel, and Eigen libraries. It supports leave-one-out, generalized, and K-fold cross-validation methods, utilizing Eigen matrices for high performance.

Dependencies

  • Rcpp: Integration between R and C++.
  • RcppParallel: Parallel computing support for Rcpp.
  • RcppEigen: Integration between R and Eigen C++ library.

Requirements

Acknowledgments

This code is adapted and extended from various sources, leveraging the capabilities of the following:

  • Rcpp by Dirk Eddelbuettel, Romain Francois, et al., for R and C++ integration.
  • RcppParallel by Romain Francois, et al., for parallel computing support in Rcpp.
  • RcppEigen by Douglas Bates, Romain Francois, et al., for integration between R and Eigen C++ library.

Please refer to the source files for detailed information and licenses.

Contributors

License

This code is under MIT License.

Example Usage

library(cvLM)
data(mtcars)
n <- nrow(mtcars)

# Formula method
cvLM(
  mpg ~ .,
  data = mtcars,
  K.vals = n,    # Leave-one-out CV
  lambda = 10    # Shrinkage parameter of 10
)

# lm method
my.lm <- lm(mpg ~ ., data = mtcars)
cvLM(
  my.lm,
  data = mtcars,
  K.vals = c(5L, 8L), # Perform both 5- and 8-fold CV
  n.threads = 8L,     # Allow up to 8 threads for computation
  seed = 1234L
)

# glm method
my.glm <- glm(mpg ~ ., data = mtcars)
cvLM(
  my.glm,
  data = mtcars,
  K.vals = n, generalized = TRUE # Use generalized CV
)

Copy Link

Version

Install

install.packages('cvLM')

Monthly Downloads

139

Version

1.0.4

License

MIT + file LICENSE

Maintainer

Philip Nye

Last Published

August 1st, 2024