kfold_predict {brms} | R Documentation |
Predictions from K-Fold Cross-Validation
Description
Compute and evaluate predictions after performing K-fold
cross-validation via kfold
.
Usage
kfold_predict(x, method = "posterior_predict", resp = NULL, ...)
Arguments
x |
Object of class |
method |
Method used to obtain predictions. Can be set to
|
resp |
Optional names of response variables. If specified, predictions are performed only for the specified response variables. |
... |
Further arguments passed to |
Value
A list
with two slots named 'y'
and 'yrep'
.
Slot y
contains the vector of observed responses.
Slot yrep
contains the matrix of predicted responses,
with rows being posterior draws and columns being observations.
See Also
Examples
## Not run:
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)
## End(Not run)