Skip to contents

Apply leave-group-out (or Monte Carlo) cross-validation.

Usage

crossval(object, ...)

# S4 method for ProgressModel
crossval(
  object,
  fun = rmspe,
  test = 0.25,
  maxsam = 500,
  seed = 1,
  simplify = TRUE,
  .id = NULL
)

# S4 method for ProgressModelList
crossval(object, ...)

Arguments

object

an object of class ProgressModel or ProgressModelList.

...

extra arguments.

fun

function. The function to apply on the train-test split.

test

numeric. The proportion of seasons to be used for testing

maxsam

numeric. The maximum number of Monte - Carlo samples to use.

seed

numeric. The seed to be used in Monte - Carlo sampling.

simplify

logical. Should the resulting list be simplified into a data.frame?

.id

The data.frame identifier (see dplyr::bind_rows). Only used if simplify = TRUE.

Value

A list containing the calculated metrics.

Examples

if (FALSE) {
# Create a Region object
library(cronus)
region <- Region(name = "nebraska", type = "us state",
                 div = c(country = "United States", state = "Nebraska"))

# Create a model
object1 <- new("ProgressBM",
               region = region,
               crop = "Corn",
               data = data_progress$Corn,
               formula = "CumPercentage ~ Time + agdd") # ProgressModel

# Create another model
object2 <- new("ProgressCLM",
               region = region,
               crop = "Soybeans",
               data = data_progress$Soybeans,
               formula = "Stage ~ Time + agdd + adayl") # ProgressModel

# Concatenate the models
object <- c(object1, object2) # ProgressModelList

# Fit
object <- fit(object)

# Plot
plot(object, cumulative = TRUE, seasons = 2002)

# Predict
predict(object, data_progress)

# Evaluate
object <- evaluate(object, maxsam = 100, seed = 1)
plot_metrics(object)

# Summarize
summary(object)

# Report
report(object, name = "example_report", path = getwd())
}