Cross-validates the model using the leave-one-out approach. In this method each subject's data is separated into a testing data set, and all other subject's are kept in the training data set, with as many resamples as the number of subjects in the original data set. It computes the model's predicted value in the testing data set for each subject.

loo_cv(model, data, id, keep = "all")

# S3 method for default
loo_cv(model, data, id, keep = "all")

# S3 method for lm
loo_cv(model, data, id, keep = "all")

# S3 method for lmerMod
loo_cv(model, data, id, keep = "all")

Arguments

model

An object containing a model.

data

A data frame.

id

The bare (unquoted) name of the column which identifies subjects.

keep

A character string which controls which columns are present in the output. Can be one of three options:

  • "all": The default. Retain all variables in the original data frame plus the ".actual" and ".predicted" columns.

  • "used": Keeps only the "id" column of the original data frame, plus the ".actual" and ".predicted" columns.

  • "none": Returns just the ".actual" and `".predicted" columns.

Value

Returns an object of class lvmisc_cv. A tibble containing the ".actual" and ".predicted" columns.

Examples

mtcars$car <- row.names(mtcars) m <- stats::lm(disp ~ mpg, mtcars) loo_cv(m, mtcars, car, keep = "used")
#> # A tibble: 32 x 3 #> car .actual .predicted #> <chr> <dbl> <dbl> #> 1 Toyota Corolla 71.1 -30.3 #> 2 Fiat 128 78.7 3.75 #> 3 Merc 240D 147. 156. #> 4 Porsche 914-2 120. 128. #> 5 Cadillac Fleetwood 472 390. #> 6 Hornet Sportabout 360 251. #> 7 Mazda RX4 160 217. #> 8 Mazda RX4 Wag 160 217. #> 9 Lincoln Continental 460 392. #> 10 Merc 280C 168. 274. #> # … with 22 more rows