Learn R Programming

psycho (version 0.4.91)

find_best_model.stanreg: Returns the best combination of predictors based on LOO cross-validation indices.

Description

Returns the best combination of predictors based on LOO cross-validation indices.

Usage

# S3 method for stanreg
find_best_model(fit, interaction = TRUE,
  fixed = NULL, K = 10, k_treshold = NULL, ...)

Arguments

fit

A stanreg object.

interaction

Include interaction term.

fixed

Additional formula part to add at the beginning of each formula

K

For kfold, the number of subsets of equal (if possible) size into which the data will be randomly partitioned for performing K-fold cross-validation. The model is refit K times, each time leaving out one of the K subsets. If K is equal to the total number of observations in the data then K-fold cross-validation is equivalent to exact leave-one-out cross-validation.

k_treshold

Threshold for flagging estimates of the Pareto shape parameters k estimated by loo.

...

Arguments passed to or from other methods.

Value

list containing all combinations.

Examples

Run this code
# NOT RUN {
library(psycho)
library(rstanarm)

data <- standardize(attitude)
fit <- rstanarm::stan_glm(rating ~ advance + privileges, data = data)

best <- find_best_model(fit)
best_formula <- best$formula
best$table

# To deactivate Kfold evaluation
best <- find_best_model(fit, K = 0)
# }
# NOT RUN {
# }

Run the code above in your browser using DataLab