inst/doc/vignette1.R

## ------------------------------------------------------------------------
DF = data.frame(Grp = rep(LETTERS[24:25],c(70,30)),
                a = round(rnorm(100,50,5),1),
                b = round(runif(100,10,90)),
                c = round(runif(100,50,100)))

## ------------------------------------------------------------------------
library(ColsTools)
DFindexes = Kcross(DF = DF, K = 5, Strat = 'Grp')
str(DFindexes)

## ------------------------------------------------------------------------
CV = lapply(1:5, FUN = ModCV, indexlist = DFindexes, Formula = formula(a~.),
            DFrame = DF, Func = lm, Resp = 'a')

## ------------------------------------------------------------------------
unlist(lapply(CV, FUN = function(x) c(x$MSE)))

## ---- fig.cap = "histogram of all test data prediction errors", fig.width=5, fig.height=3.5----
Allerrors = unlist(lapply(CV, FUN = function(x) c(x$Error)))
hist(Allerrors, main="", breaks=12)

## ------------------------------------------------------------------------
Tab = t(sapply(CV, FUN = function(x) rbind(x$Coef)))
colnames(Tab) = names(CV[[1]]$Coef)
Tab

## ------------------------------------------------------------------------
library(randomForest)
CVRF = lapply(1:5, FUN = ModCV, indexlist = DFindexes, Formula = formula(a~.),
            DFrame = DF, Func = randomForest, Resp = 'a')
unlist(lapply(CVRF, FUN = function(x) c(x$MSE)))

## ------------------------------------------------------------------------
library(neuralnet)
CVNN = lapply(1:5, FUN = ModCV, indexlist = DFindexes, Formula = formula(a~.),
            DFrame = DF, Func = randomForest, Resp = 'a')
unlist(lapply(CVNN, FUN = function(x) c(x$MSE)))
helophilus/ColsTools documentation built on May 30, 2019, 4:03 p.m.