crossv_loo_grouped: Generate cross-validation resamples using a grouped...

View source: R/statistics.R

crossv_loo_groupedR Documentation

Generate cross-validation resamples using a grouped data.frame

Description

Expands the capability of the crossv_loo and crossv_mc functions such that groups in a grouped data frame form the basis of folds to be "left out" of a model training set for cross-validation.

Usage

crossv_loo_grouped(data, id = ".id")

crossv_mc_grouped(data, n, test = 0.25, id = ".id")

Arguments

data

A grouped data frame.

id

Name of variable that gives each training set a unique integer id.

Examples


# Normal crossv_loo
cv_iris <- modelr::crossv_loo(iris)

# Note that the number of training paritions is equal to nrow(iris)

# Use the new function
cv_iris2 <- crossv_loo_grouped(group_by(iris, Species))

# Note that the number of training partitions is equal to n_groups(data)




library(agridat)
wheat <- vargas.wheat2.yield

# Normal crossv_mc
cv_wheat <- modelr::crossv_mc(data = wheat, n = 10, test = 0.25)

# Note that partitions are made across environments or genotypes

# Use the new function
cv_wheat2 <- crossv_mc_grouped(data = group_by(wheat, env), n = 15)

# Note that partitions are made according to the group


neyhartj/miscRutils documentation built on Jan. 17, 2024, 11:15 a.m.