View source: R/crossvalidatedR2.R
crossvalidatedR2 | R Documentation |
Computes an R^2 value for predicting an outcome measure using a k-fold cross-validation scheme.
crossvalidatedR2(x, y, ngroups=5, covariates=NA, fast=F)
x |
Input predictor matrix. |
y |
Target dependent variable. |
ngroups |
Number of cross-validation folds to use or the fold labels themselves, equal to the length of y. e.g. c(1,1,1,2,2,2...) |
covariates |
Covariate predictors. |
fast |
Use low-level |
Matrix of size ngroups
by ncol(x)
, which each row corresponding to one fold and the columns corresponding to the R2 values for each predictor.
Brian B Avants, Benjamin M. Kandel
set.seed(300)
ncol <- 30
nrow <- 20
covariate <- sin((1:nrow) * 2 * pi / nrow)
x <- matrix(rep(NA, nrow * ncol), nrow = nrow)
xsig <- seq(0, 1, length.out = nrow)
y <- xsig + covariate + rnorm(nrow, sd = 0.5)
for (i in 1:ncol) {
x[, i] <- xsig + rnorm(nrow, sd = i / ncol)
}
r2 <- crossvalidatedR2(x, y, covariates = covariate)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.