|
a |
|
b/man/kfold.hsstan.Rd |
|
|
1 |
% Generated by roxygen2: do not edit by hand |
|
|
2 |
% Please edit documentation in R/stan.R |
|
|
3 |
\name{kfold.hsstan} |
|
|
4 |
\alias{kfold.hsstan} |
|
|
5 |
\alias{kfold} |
|
|
6 |
\title{K-fold cross-validation} |
|
|
7 |
\usage{ |
|
|
8 |
\method{kfold}{hsstan}( |
|
|
9 |
x, |
|
|
10 |
folds, |
|
|
11 |
chains = 1, |
|
|
12 |
store.fits = TRUE, |
|
|
13 |
cores = getOption("mc.cores", 1), |
|
|
14 |
... |
|
|
15 |
) |
|
|
16 |
} |
|
|
17 |
\arguments{ |
|
|
18 |
\item{x}{An object of class \code{hsstan}.} |
|
|
19 |
|
|
|
20 |
\item{folds}{Integer vector with one element per observation indicating the |
|
|
21 |
cross-validation fold in which the observation should be withdrawn.} |
|
|
22 |
|
|
|
23 |
\item{chains}{Number of Markov chains to run. By default this is set to 1, |
|
|
24 |
independently of the number of chains used for \code{x}.} |
|
|
25 |
|
|
|
26 |
\item{store.fits}{Whether the fitted models for each fold should be stored |
|
|
27 |
in the returned object (\code{TRUE} by default).} |
|
|
28 |
|
|
|
29 |
\item{cores}{Number of cores to use for parallelization (the value of |
|
|
30 |
\code{options("mc.cores")} by default). The cross-validation folds will |
|
|
31 |
be distributed to the available cores, and the Markov chains for each |
|
|
32 |
model will be run sequentially.} |
|
|
33 |
|
|
|
34 |
\item{...}{Further arguments passed to \code{\link[rstan:stanmodel-method-sampling]{rstan::sampling()}}.} |
|
|
35 |
} |
|
|
36 |
\value{ |
|
|
37 |
An object with classes \code{kfold} and \code{loo} that has a similar structure as the |
|
|
38 |
objects returned by \code{\link[=loo]{loo()}} and \code{\link[=waic]{waic()}} and is compatible with the |
|
|
39 |
\code{\link[loo]{loo_compare}} function for |
|
|
40 |
comparing models. The object contains the following fields: |
|
|
41 |
\item{estimates}{a matrix containing point estimates and standard errors of |
|
|
42 |
the expected log pointwise predictive density ("elpd_kfold"), |
|
|
43 |
the effective number of parameters ("p_kfold", always \code{NA}) and the |
|
|
44 |
K-fold information criterion "kfoldic" (which is \code{-2 * elpd_kfold}, |
|
|
45 |
i.e., converted to the deviance scale).} |
|
|
46 |
\item{pointwise}{a matrix containing the pointwise contributions of |
|
|
47 |
"elpd_kfold", "p_kfold" and "kfoldic".} |
|
|
48 |
\item{fits}{a matrix with two columns and number of rows equal to the number |
|
|
49 |
of cross-validation folds. Column \code{fit} contains the fitted |
|
|
50 |
\code{hsstan} objects for each fold, and column \code{test.idx} contains |
|
|
51 |
the indices of the withdrawn observations for each fold. This is not |
|
|
52 |
present if \code{store.fits=FALSE}.} |
|
|
53 |
\item{data}{the dataset used in fitting the model (before withdrawing |
|
|
54 |
observations). This is not present if \code{store.fits=FALSE}.} |
|
|
55 |
} |
|
|
56 |
\description{ |
|
|
57 |
Perform K-fold cross-validation using the same settings used when fitting |
|
|
58 |
the model on the whole data. |
|
|
59 |
} |
|
|
60 |
\examples{ |
|
|
61 |
\donttest{ |
|
|
62 |
\dontshow{utils::example("hsstan", echo=FALSE)} |
|
|
63 |
# continued from ?hsstan |
|
|
64 |
# only 2 folds for speed of example |
|
|
65 |
folds <- rep(1:2, length.out=length(df$Y)) |
|
|
66 |
cv.biom <- kfold(hs.biom, folds=folds, cores=2) |
|
|
67 |
} |
|
|
68 |
|
|
|
69 |
} |