-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support for exogenous variables and minor improvements to core …
…functions.
- Loading branch information
Showing
9 changed files
with
138 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#' Validate exogenous variables (if applicable) | ||
#' This is a private function of nixtlar | ||
#' | ||
#' @param df A tsibble or a data frame with time series data. | ||
#' @param h Forecast horizon. | ||
#' @param X_df A tsibble or a data frame with future exogenous variables. | ||
#' | ||
#' @return A list with the result of the validation (TRUE/FALSE) and an error message (if applicable) | ||
#' @export | ||
#' | ||
.validate_exogenous <- function(df, h, X_df){ | ||
|
||
status <- list(validation = TRUE, | ||
message = NULL | ||
) | ||
|
||
# Check if df and X_df contain the same exogenous variables | ||
vals_df <- setdiff(names(df), c("unique_id", "ds", "y")) | ||
vals_X_df <- setdiff(names(X_df), c("unique_id", "ds")) | ||
|
||
if(!setequal(vals_df, vals_X_df)){ | ||
status$valdiation <- FALSE | ||
status$message <- "df and X_df must contain the same exogenous variables." | ||
} | ||
|
||
# Check if the future values of the exogenous variables cover the forecast horizon | ||
future_vals <- X_df |> | ||
dplyr::group_by(.data$unique_id) |> | ||
dplyr::filter(dplyr::n() == h) | ||
|
||
if(length(unique(future_vals$unique_id)) != length(unique(X_df$unique_id))){ | ||
status$validation <- FALSE | ||
status$message <- "The future values of the exogenous variables must cover the forecast horizon" | ||
} | ||
|
||
return(status) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.