loo_cv: Leave-one-out cross-validation

Description Usage Arguments Value Examples

View source: R/loo_cv.R

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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
loo_cv(model, data, id, keep = "all")

## Default S3 method:
loo_cv(model, data, id, keep = "all")

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

## S3 method for class '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

1
2
3
mtcars$car <- row.names(mtcars)
m <- stats::lm(disp ~ mpg, mtcars)
loo_cv(m, mtcars, car, keep = "used")

lvmisc documentation built on April 5, 2021, 5:06 p.m.