forked from paul-buerkner/brms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkfold_predict.Rd
55 lines (48 loc) · 1.69 KB
/
kfold_predict.Rd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/kfold.R
\name{kfold_predict}
\alias{kfold_predict}
\title{Predictions from K-Fold Cross-Validation}
\usage{
kfold_predict(x, method = c("predict", "fitted"), resp = NULL, ...)
}
\arguments{
\item{x}{Object of class \code{'kfold'} computed by \code{\link{kfold}}.
For \code{kfold_predict} to work, the fitted model objects need to have
been stored via argument \code{save_fits} of \code{\link{kfold}}.}
\item{method}{The method used to make predictions. Either \code{"predict"}
or \code{"fitted"}. See \code{\link{predict.brmsfit}} for details.}
\item{resp}{Optional names of response variables. If specified, predictions
are performed only for the specified response variables.}
\item{...}{Further arguments passed to \code{\link{prepare_predictions}}
that control several aspects of data validation and prediction.}
}
\value{
A \code{list} with two slots named \code{'y'} and \code{'yrep'}.
Slot \code{y} contains the vector of observed responses.
Slot \code{yrep} contains the matrix of predicted responses,
with rows being posterior draws and columns being observations.
}
\description{
Compute and evaluate predictions after performing K-fold
cross-validation via \code{\link{kfold}}.
}
\examples{
\dontrun{
fit <- brm(count ~ zBase * Trt + (1|patient),
data = epilepsy, family = poisson())
# perform k-fold cross validation
(kf <- kfold(fit, save_fits = TRUE, chains = 1))
# define a loss function
rmse <- function(y, yrep) {
yrep_mean <- colMeans(yrep)
sqrt(mean((yrep_mean - y)^2))
}
# predict responses and evaluate the loss
kfp <- kfold_predict(kf)
rmse(y = kfp$y, yrep = kfp$yrep)
}
}
\seealso{
\code{\link{kfold}}
}