cv {stressor}R Documentation

Cross Validation

Description

This is the core of cross-validation- both standard and using k-mean groups. This method is called by other cv methods of classes.

Usage

cv(
  object,
  data,
  n_folds = 10,
  k_mult = NULL,
  repl = FALSE,
  grouping_formula = NULL
)

## S3 method for class 'lm'
cv(
  object,
  data,
  n_folds = 10,
  k_mult = NULL,
  repl = FALSE,
  grouping_formula = NULL
)

## S3 method for class 'mlm_stressor'
cv(
  object,
  data,
  n_folds = 10,
  k_mult = NULL,
  repl = FALSE,
  grouping_formula = NULL
)

## S3 method for class 'reg_asym'
cv(
  object,
  data,
  n_folds = 10,
  k_mult = NULL,
  repl = FALSE,
  grouping_formula = NULL
)

## S3 method for class 'reg_sine'
cv(
  object,
  data,
  n_folds = 10,
  k_mult = NULL,
  repl = FALSE,
  grouping_formula = NULL
)

Arguments

object

One of the four objects that is accepted: mlm_stressor, reg_sine, reg_asym, or lm.

data

A data.frame object that contains all the entries to be cross-validated on.

n_folds

An integer value for the number of folds defaulted to 10. If NULL, it will run LOO cross-validation.

k_mult

Used to specify if k-means clustering is to be used, defaulted to NULL.

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.

Value

If the object is of class mlm_stressor, then a data.frame will be returned. Otherwise, a vector of the predictions will be returned.

Methods (by class)

Examples

 # lm example
 lm_test <- data_gen_lm(20)
 lm <- lm(Y ~ ., lm_test)
 cv(lm, lm_test, n_folds = 2)


 lm_test <- data_gen_lm(20)
 create_virtualenv()
 mlm_lm <- mlm_regressor(Y ~ ., lm_test)
 cv(mlm_lm, lm_test, n_folds = 2)

 # Asymptotic example
 asym_data <- data_gen_asym(10)
 asym_fit <- reg_asym(Y ~ ., asym_data)
 cv(asym_fit, asym_data, n_folds = 2)

 # Sine example
 sine_data <- data_gen_sine(10)
 sine_fit <- reg_sine(Y ~ ., sine_data)
 cv(sine_fit, sine_data, n_folds = 2)

[Package stressor version 0.2.0 Index]