Skip to content

Commit

Permalink
update docs for lfo_cv and ensure trend_map recognises ordering of se…
Browse files Browse the repository at this point in the history
…ries levels
  • Loading branch information
Nicholas Clark committed Sep 12, 2024
1 parent 9f793eb commit 3160f43
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 11 deletions.
23 changes: 17 additions & 6 deletions R/lfo_cv.mvgam.R
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down Expand Up @@ -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){
Expand Down
3 changes: 2 additions & 1 deletion R/validations.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
}

Expand Down
10 changes: 6 additions & 4 deletions man/lfo_cv.mvgam.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified src/mvgam.dll
Binary file not shown.

0 comments on commit 3160f43

Please sign in to comment.