Split data into training and test sets to assess whether equivalence generalizes to held-out data.
Usage
cross_validate_equivalence(
pair,
y,
n_folds = 5,
n_points = 50,
tol = 1e-06,
method = c("grid", "optimization"),
progress = interactive()
)Value
An S3 object of class cv_equiv containing:
- fold_results
Data frame with results for each fold
- prop_equivalent
Proportion of folds showing equivalence
- mean_discrepancy
Mean max discrepancy across folds
- n_folds
Number of folds
Details
For each fold, a portion of the data is held out and the equivalence test is performed on the remaining data. Consistent results across folds suggest the conclusion generalizes.
Examples
# \donttest{
exp_spec <- model_spec(
loglik_fn = function(y, lambda) sum(dexp(y, rate = lambda, log = TRUE)),
par_names = "lambda",
par_bounds = list(lambda = c(1e-6, 100)),
name = "Exponential"
)
gamma_spec <- model_spec(
loglik_fn = function(y, rate) sum(dgamma(y, shape = 1, rate = rate, log = TRUE)),
par_names = "rate",
par_bounds = list(rate = c(1e-6, 100)),
name = "Gamma(1)"
)
pair <- equivalence_pair(exp_spec, gamma_spec)
set.seed(123)
y <- rexp(100, rate = 2)
# Cross-validation test
cv <- cross_validate_equivalence(pair, y, n_folds = 5, n_points = 20)
print(cv)
# }