R/simpleCV.R

Defines functions simpleCV

Documented in simpleCV

#' Perform simple CV, and return the MSE estimate
#'
#' @inheritParams R2oosse
#' @return The MSE estimate
simpleCV = function(y, x, fitFun, predFun, nFolds){
    folds = sample(rep(unFolds <- seq_len(nFolds), length.out = length(y)))
    mean(unlist(lapply(unFolds, function(uf){
            idTrain = folds!=uf
            predTest = predFun(fitFun(y[idTrain], x[idTrain,,drop = FALSE]),
                               x[!idTrain,,drop = FALSE])
            (predTest-y[!idTrain])^2
    })))
}

Try the oosse package in your browser

Any scripts or data that you put into this service are public.

oosse documentation built on May 29, 2024, 10:35 a.m.