create_groups {stressor} | R Documentation |
Create Groups for CV
Description
Create groups for the data by separating them either into 10 fold cross-validation, LOO cross-validation, or k-means grouping.
Usage
create_groups(
formula,
data,
n_folds = 10,
k_mult = NULL,
repl = FALSE,
grouping_formula = NULL
)
Arguments
formula |
A formula object that specifies the model to be fit. |
data |
The data that will be separated into each group. |
n_folds |
An integer value defaulted to 10 fold cross-validation. If NULL uses Leave One Out(LOO) instead. |
k_mult |
When specified, this is passed onto the cv_cluster to fit the data into k_groups. |
repl |
A Boolean value defaulted to 'FALSE', change to 'TRUE' when replicates need to be included in the same group. |
grouping_formula |
A formula object that specifies how the groups will be gathered. |
Details
If 'k_mult' is specified as an integer, the formula object will be used to help determine the features specified by the user. This will be passed to the cv_cluster function, which takes a scaled matrix of features.
This function is called by the cv methods as it forms the groups necessary to perform the cross-validation. If you want to use this, it is a nice function that separates the 'data' into groups for training and testing.
Value
A vector of the length equal to number of rows of data.frame from the data argument.
Examples
# data generation
lm_data <- data_gen_lm(1000)
# 10 Fold CV group
create_groups(Y ~ ., lm_data)
# Spatial CV
create_groups(Y ~ ., lm_data, n_folds = 10, k_mult = 5)
# LOO CV group
create_groups(Y ~ ., lm_data, n_folds = NULL)