Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

kfold_predict

Predictions from K-Fold Cross-Validation


Description

Compute and evaluate predictions after performing K-fold cross-validation via kfold.

Usage

kfold_predict(x, method = c("predict", "fitted"), resp = NULL, ...)

Arguments

x

Object of class 'kfold' computed by kfold. For kfold_predict to work, the fitted model objects need to have been stored via argument save_fits of kfold.

method

The method used to make predictions. Either "predict" or "fitted". See predict.brmsfit for details.

resp

Optional names of response variables. If specified, predictions are performed only for the specified response variables.

...

Further arguments passed to prepare_predictions that control several aspects of data validation and prediction.

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)

brms

Bayesian Regression Models using 'Stan'

v2.15.0
GPL-2
Authors
Paul-Christian Bürkner [aut, cre], Jonah Gabry [ctb], Sebastian Weber [ctb], Andrew Johnson [ctb], Martin Modrak [ctb]
Initial release
2021-03-10

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.