Learn R Programming

lvmisc (version 0.1.2)

loo_cv: Leave-one-out cross-validation

Description

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.

Usage

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")

Value

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

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.

Examples

Run this code
mtcars$car <- row.names(mtcars)
m <- stats::lm(disp ~ mpg, mtcars)
loo_cv(m, mtcars, car, keep = "used")

Run the code above in your browser using DataLab