Hello, here is a example. Thank you Paul!
s<-data.frame(
f1=c(3.85,0.88,5.09,-2.60,4.00,2.96,5.51,-0.14,2.27,3.96),
f2=c(-0.25,0.24,-0.38,0.34,0.23,-0.14,-0.37,-6.70,0.16,0.27),
f3=c(-1.66,0.44,-1.79,0.01,-1.43,-0.06,-1.19,0.56,-0.46,-0.26),
f4=c(0.90,1.05,-0.37,0.80,0.45,-0.23,-1.24,-0.25,-0.33,-1.45),
f5=c(-1.83,1.45,-0.66,-1.37,0.21,0.16,-1.22,1.92,0.39,0.22),
f6=c(-1.00,1.30,0.24,0.92,0.05,0.21,-0.68,-1.30,0.07,-1.07),
y=c(0,1,1,0,1,0,1,1,0,1)
);
#data size
N<-10 #sample size
K<-6 #number of predictors
n_fold<-5 #number of folds
#create 5 folds of data
library(rstan)
library(loo)
hh<-kfold_split_stratified(K=n_fold,x=s$y)
#==============using rstanarm package
library(rstanarm)
model_test <- stan_glm(y~f1+f2+f3+f4+f5+f6,
data=s, family = binomial(link = “logit”),prior=(normal(0,10000)),iter=1000,chains=1)
kf<-brms::kfold(model_test,K=5,save_fits=TRUE,folds=hh,compare=TRUE)
kp<-brms::kfold_predict(kf,method=“predict”)