Compare growth curve models on the valid weight records of each pig, in two ways:

  • blocked k-fold cross-validation: the days of each pig are cut into blocks of block_days consecutive days, and the blocks are split into k folds at random; each fold in turn is left out, the curve is fitted on the others and predicts the valid weights of the left-out days;

  • truncation: the first (late entry) or last (early exit) trim_days days are hidden, ADG is computed again and compared with the ADG from all records of the same model.

In both, all weight records of the hidden days are removed before cleaning: the remaining records are cleaned again with the settings of qc (clean_weight()), so the hidden days do not decide which of the other records are kept (before 1.5.0 the records were cleaned on all days, and folds were single random days, whose neighbours stayed in the training data).

validate_adg(
  weight,
  models = c("poly1", "poly2", "poly3", "gompertz"),
  extrap = NULL,
  k = 5,
  block_days = 7,
  cv_limit = 10,
  trim_days = c(10, 20),
  qc = weight$settings,
  max_pigs = NULL,
  seed = 1,
  verbose = 1,
  cores = 1
)

Arguments

weight

Result of clean_weight().

models

Curve models to compare (values of curve_model).

extrap

Extrapolations to compare (values of curve_extrap): "start", "curve", "tangent" or several. Default: the one of qc. Other than "curve", a model is labelled e.g. "poly2+tangent". Mainly the truncation results differ; in cross-validation, only the folds with the first or last block of days are extrapolated.

k

Number of folds. Default 5.

block_days

Length of the blocks of days for the folds. Default 7; 1 gives single random days (more optimistic: a left-out day is close to its neighbours).

cv_limit

Cross-validation error (kg) above which a pig counts as badly predicted, in cv_share_over. Default 10.

trim_days

Days hidden at the start or the end of the test. Default c(10, 20).

qc

QC settings: the weight cleaning rules and stage_range, max_extrap_days.

max_pigs

Use a random sample of at most this many pigs. Default NULL: all.

seed

Random seed for the folds.

verbose

0 (silent), 1 (summary and progress, default).

cores

Number of CPU cores. Default 1.

Value

A list of class ppt_validation with

  • summary: one row per model (and extrapolation): cv_rmse and cv_mae, the median over pigs of each pig's prediction error (kg, weight of the left-out records; a few pigs with an absurd extrapolation, e.g. poly3 over a left-out block, would dominate a mean), cv_share_over the share of pigs with an error above cv_limit kg, and for each truncation (late10, early10, ...) the ADG bias, rmse (g/d) and Spearman rank correlation spearman with the full-data ADG, and how many pigs still get an ADG (n);

  • cv: cross-validation error of every pig and model;

  • truncation: ADG of every pig, model and truncation;

  • settings.