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