From 3160f43031ecd2ab379644abff1837cca913b285 Mon Sep 17 00:00:00 2001 From: Nicholas Clark Date: Thu, 12 Sep 2024 17:18:49 +1000 Subject: [PATCH] update docs for lfo_cv and ensure trend_map recognises ordering of series levels --- R/lfo_cv.mvgam.R | 23 +++++++++++++++++------ R/validations.R | 3 ++- man/lfo_cv.mvgam.Rd | 10 ++++++---- src/mvgam.dll | Bin 1091584 -> 1091584 bytes 4 files changed, 25 insertions(+), 11 deletions(-) diff --git a/R/lfo_cv.mvgam.R b/R/lfo_cv.mvgam.R index ff8fb705..25519a3f 100644 --- a/R/lfo_cv.mvgam.R +++ b/R/lfo_cv.mvgam.R @@ -8,10 +8,12 @@ #''time' (numeric index of the time point for each observation). #'Any other variables to be included in the linear predictor of \code{formula} must also be present #'@param min_t Integer specifying the minimum training time required before making predictions -#'from the data. Default is either `30`, or whatever training time allows for at least -#'`10` lfo-cv calculations (i.e. `pmin(max(data$time) - 10, 30)`). This value is essentially -#'arbitrary so it is highly recommended to change it to something that is more suitable to the -#'data and models being evaluated +#'from the data. Default is either the `30`th timepoint in the observational data, +#'or whatever training time allows for at least +#'`10` lfo-cv calculations, if possible. +#'This value is essentially arbitrary so it is highly recommended to change it +#'to something that is more suitable to the +#'data and models being evaluated. #'@param fc_horizon Integer specifying the number of time steps ahead for evaluating forecasts #'@param pareto_k_threshold Proportion specifying the threshold over which the Pareto shape parameter #'is considered unstable, triggering a model refit. Default is `0.7` @@ -139,11 +141,20 @@ lfo_cv.mvgam = function(object, trend_model = attr(object$model_data, 'trend_model')) } N <- max(all_data$index..time..index) + all_unique_times <- sort(unique(all_data$index..time..index)) - # Default minimum training time is 30, or + # Default minimum training time is the 30th timepoint, or # whatever training time allows for at least 10 lfo_cv calculations if(missing(min_t)){ - min_t <- pmin(N - 10 - fc_horizon, 30) + if(length(all_unique_times) > 30){ + min_t <- pmin(max(1, N - 10 - fc_horizon), all_unique_times[30]) + } else if(length(all_unique_times) < 30 & length(all_unique_times) > 20){ + min_t <- pmin(max(1, N - 10 - fc_horizon), all_unique_times[20]) + } else if(length(all_unique_times) < 20 & length(all_unique_times) > 10) { + min_t <- pmin(max(1, N - 10 - fc_horizon), all_unique_times[10]) + } else { + min_t <- 1 + } } if(min_t < 0){ diff --git a/R/validations.R b/R/validations.R index 584f6ee5..64d547da 100644 --- a/R/validations.R +++ b/R/validations.R @@ -567,7 +567,8 @@ validate_trend_restrictions = function(trend_model, if(!missing(trend_formula)){ validate_trend_formula(trend_formula) if(missing(trend_map)){ - trend_map <- data.frame(series = unique(data_train$series), + trend_map <- data.frame(series = factor(levels(data_train$series), + levels = levels(data_train$series)), trend = 1:length(unique(data_train$series))) } diff --git a/man/lfo_cv.mvgam.Rd b/man/lfo_cv.mvgam.Rd index e586e50f..ea6b0de3 100644 --- a/man/lfo_cv.mvgam.Rd +++ b/man/lfo_cv.mvgam.Rd @@ -29,10 +29,12 @@ required by the GAM \code{formula}. Should include columns: Any other variables to be included in the linear predictor of \code{formula} must also be present} \item{min_t}{Integer specifying the minimum training time required before making predictions -from the data. Default is either \code{30}, or whatever training time allows for at least -\code{10} lfo-cv calculations (i.e. \code{pmin(max(data$time) - 10, 30)}). This value is essentially -arbitrary so it is highly recommended to change it to something that is more suitable to the -data and models being evaluated} +from the data. Default is either the \code{30}th timepoint in the observational data, +or whatever training time allows for at least +\code{10} lfo-cv calculations, if possible. +This value is essentially arbitrary so it is highly recommended to change it +to something that is more suitable to the +data and models being evaluated.} \item{fc_horizon}{Integer specifying the number of time steps ahead for evaluating forecasts} diff --git a/src/mvgam.dll b/src/mvgam.dll index 3d666673515bd0fb31928c1ee5a8747ff02643a3..5d623bf08165651b2342a098bd047d0c1aa75971 100644 GIT binary patch delta 81 zcmWm5yA4240EW?Uy`OgtYiKcnWhnkcqG1x1SVO1yI#bYz)1Tq2hqGQL^Q`wecV@fn ih;W1}jPQgn0uhQx#3B)?$V4s*QSR8P`TG&J_U%7z6eke? delta 81 zcmV-X0IvUl&_aOFLXe09t=8a?i%kO*VG)7bh1&sz+X98#1BKfJh1&&%+XjW(2Zh@R nh1&^*+X{u-3x(SZh1(5<+YW`>54GD6DN6&a*5J1XOc427CS@h?