| Title: | R Interface to ForecastBaselines.jl |
|---|---|
| Description: | Provides an R interface to the ForecastBaselines.jl Julia package, enabling access to 10 baseline forecasting models including ARMA, ETS, STL, and others. Supports probabilistic forecasting with multiple interval methods and seamless integration with the scoringutils evaluation framework. |
| Authors: | Manuel Stapper [aut], Sebastian Funk [aut, cre] (ORCID: <https://orcid.org/0000-0002-2842-3406>) |
| Maintainer: | Sebastian Funk <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.0 |
| Built: | 2026-06-04 07:15:56 UTC |
| Source: | https://github.com/epiforecasts/forecastbaselines |
Add Intervals to Forecast
add_intervals(forecast, intervals)add_intervals(forecast, intervals)
forecast |
A Forecast object |
intervals |
Interval data structure |
Updated Forecast object
Add Median to Forecast
add_median(forecast, median)add_median(forecast, median)
forecast |
A Forecast object |
median |
Numeric vector of median forecasts |
Updated Forecast object
Add Temporal Information to Forecast
add_temporal_info(forecast, reference_date, target_date, resolution)add_temporal_info(forecast, reference_date, target_date, resolution)
forecast |
A Forecast object |
reference_date |
Reference date |
target_date |
Target date |
resolution |
Time resolution |
Updated Forecast object
Add Trajectories to Forecast
add_trajectories(forecast, trajectories)add_trajectories(forecast, trajectories)
forecast |
A Forecast object |
trajectories |
Matrix of trajectories |
Updated Forecast object
Add Truth Values to Forecast
add_truth(forecast, truth)add_truth(forecast, truth)
forecast |
A Forecast object |
truth |
Numeric vector of observed values |
Updated Forecast object
Creates an AutoRegressive Moving Average model.
ARMAModel(p = 0L, q = 0L, s = 0L, include_mean = TRUE, include_drift = FALSE)ARMAModel(p = 0L, q = 0L, s = 0L, include_mean = TRUE, include_drift = FALSE)
p |
AR order (default: 0) |
q |
MA order (default: 0) |
s |
Seasonal period (default: 0 for no seasonality) |
include_mean |
Whether to include a mean term (default: TRUE) |
include_drift |
Whether to include a drift term (default: FALSE) |
An ARMAModel object
## Not run: # AR(1) model <- ARMAModel(p = 1) # MA(1) model <- ARMAModel(q = 1) # ARMA(2,1) with seasonality model <- ARMAModel(p = 2, q = 1, s = 12) ## End(Not run)## Not run: # AR(1) model <- ARMAModel(p = 1) # MA(1) model <- ARMAModel(q = 1) # ARMA(2,1) with seasonality model <- ARMAModel(p = 2, q = 1, s = 12) ## End(Not run)
S3 method to convert a ForecastBaselines_Forecast object to a scoringutils forecast_point object. This allows seamless integration with scoringutils.
## S3 method for class 'ForecastBaselines_Forecast' as_forecast_point(data, ...)## S3 method for class 'ForecastBaselines_Forecast' as_forecast_point(data, ...)
data |
A ForecastBaselines_Forecast object |
... |
Additional arguments (not used) |
A forecast_point object from scoringutils
## Not run: # Convert and validate as point forecast fc_point <- scoringutils::as_forecast_point(forecast) ## End(Not run)## Not run: # Convert and validate as point forecast fc_point <- scoringutils::as_forecast_point(forecast) ## End(Not run)
S3 method to convert a ForecastBaselines_Forecast object to a scoringutils forecast_quantile object. This allows seamless integration with scoringutils.
## S3 method for class 'ForecastBaselines_Forecast' as_forecast_quantile(data, ...)## S3 method for class 'ForecastBaselines_Forecast' as_forecast_quantile(data, ...)
data |
A ForecastBaselines_Forecast object with quantiles |
... |
Additional arguments (not used) |
A forecast_quantile object from scoringutils
## Not run: # Convert and validate as quantile forecast fc_quantile <- scoringutils::as_forecast_quantile(forecast) ## End(Not run)## Not run: # Convert and validate as quantile forecast fc_quantile <- scoringutils::as_forecast_quantile(forecast) ## End(Not run)
Converts a ForecastBaselines_Forecast object to the hubverse format used by hubVis for visualization. Returns a list with model_output and target_data data frames.
as_hubverse( data, start_date = NULL, horizon_unit = c("day", "week", "month"), observed_data = NULL )as_hubverse( data, start_date = NULL, horizon_unit = c("day", "week", "month"), observed_data = NULL )
data |
A ForecastBaselines_Forecast object with quantiles, or a scoringutils forecast_quantile object |
start_date |
Optional start date for the time series. If NULL (default), uses horizon numbers as target_date values. Can be a Date object or character string in "YYYY-MM-DD" format. |
horizon_unit |
Character string specifying the time unit for horizons. One of "day" (default), "week", or "month". Used when start_date is provided. |
observed_data |
Optional numeric vector of all observed values (training + test). If provided, will be used to populate target_data with complete historical context. |
The hubVis and hubUtils packages are not on CRAN and must be installed from GitHub:
remotes::install_github(c("hubverse-org/hubUtils", "hubverse-org/hubVis"))
A list with two elements:
Data frame (model_out_tbl) with columns: target_date, value, model_id, output_type, output_type_id
Data frame with columns: date, observation
## Not run: # With observed data for complete visualization context hubverse_data <- as_hubverse(forecast, start_date = "2024-01-01", horizon_unit = "week", observed_data = full_data ) # Install hubVis/hubUtils from GitHub for visualization # remotes::install_github(c("hubverse-org/hubUtils", "hubverse-org/hubVis")) # Visualize with hubVis (if installed) # Note: as_hubverse() automatically converts model_output to model_out_tbl if (requireNamespace("hubVis", quietly = TRUE)) { hubVis::plot_step_ahead_model_output( hubverse_data$model_output, hubverse_data$target_data ) } ## End(Not run)## Not run: # With observed data for complete visualization context hubverse_data <- as_hubverse(forecast, start_date = "2024-01-01", horizon_unit = "week", observed_data = full_data ) # Install hubVis/hubUtils from GitHub for visualization # remotes::install_github(c("hubverse-org/hubUtils", "hubverse-org/hubVis")) # Visualize with hubVis (if installed) # Note: as_hubverse() automatically converts model_output to model_out_tbl if (requireNamespace("hubVis", quietly = TRUE)) { hubVis::plot_step_ahead_model_output( hubverse_data$model_output, hubverse_data$target_data ) } ## End(Not run)
Creates a naive forecast model that uses the last observed value as the forecast for all future horizons.
ConstantModel()ConstantModel()
A ConstantModel object
## Not run: model <- ConstantModel() ## End(Not run)## Not run: model <- ConstantModel() ## End(Not run)
Creates prediction intervals by bootstrapping from historical forecast errors. This is a non-parametric method that doesn't assume any particular distribution.
EmpiricalInterval( n_trajectories = 1000L, min_observation = 1L, bootstrap_distribution = NULL, seed = NULL, positivity_correction = "none", symmetry_correction = FALSE, stepwise = FALSE, return_trajectories = FALSE )EmpiricalInterval( n_trajectories = 1000L, min_observation = 1L, bootstrap_distribution = NULL, seed = NULL, positivity_correction = "none", symmetry_correction = FALSE, stepwise = FALSE, return_trajectories = FALSE )
n_trajectories |
Number of bootstrap samples to generate (default: 1000) |
min_observation |
Minimum number of observations required (default: 1) |
bootstrap_distribution |
Optional distribution to sample from (default: NULL) |
seed |
Random seed for reproducibility (default: NULL) |
positivity_correction |
Method to ensure positive forecasts: "none", "post_clip", "truncate", or "zero_floor" (default: "none") |
symmetry_correction |
Whether to apply symmetry correction (default: FALSE) |
stepwise |
Whether to use stepwise intervals (default: FALSE) |
return_trajectories |
Whether to return forecast trajectories (default: FALSE) |
An EmpiricalInterval object
## Not run: # Basic empirical intervals method <- EmpiricalInterval() # With more trajectories and seed method <- EmpiricalInterval(n_trajectories = 2000, seed = 123) # With positivity correction for count data method <- EmpiricalInterval( n_trajectories = 1000, positivity_correction = "post_clip" ) # Return trajectories for visualization method <- EmpiricalInterval(return_trajectories = TRUE) ## End(Not run)## Not run: # Basic empirical intervals method <- EmpiricalInterval() # With more trajectories and seed method <- EmpiricalInterval(n_trajectories = 2000, seed = 123) # With positivity correction for count data method <- EmpiricalInterval( n_trajectories = 1000, positivity_correction = "post_clip" ) # Return trajectories for visualization method <- EmpiricalInterval(return_trajectories = TRUE) ## End(Not run)
Creates an Error-Trend-Season exponential smoothing model.
ETSModel( error_type = "A", trend_type = "N", season_type = "N", s = NULL, damped = FALSE )ETSModel( error_type = "A", trend_type = "N", season_type = "N", s = NULL, damped = FALSE )
error_type |
Error type: "A" (additive), "M" (multiplicative), or "N" (none) |
trend_type |
Trend type: "A" (additive), "M" (multiplicative), "Ad" (damped additive), "Md" (damped multiplicative), or "N" (none) |
season_type |
Season type: "A" (additive), "M" (multiplicative), or "N" (none) |
s |
Seasonal period (required if season_type is not "N") |
damped |
Whether to use damped trend (default: FALSE) |
An ETSModel object
## Not run: # Simple exponential smoothing (A,N,N) model <- ETSModel(error_type = "A", trend_type = "N", season_type = "N") # Holt's linear trend (A,A,N) model <- ETSModel(error_type = "A", trend_type = "A", season_type = "N") # Holt-Winters additive (A,A,A) model <- ETSModel( error_type = "A", trend_type = "A", season_type = "A", s = 12 ) # Holt-Winters multiplicative (M,M,M) model <- ETSModel( error_type = "M", trend_type = "M", season_type = "M", s = 12 ) ## End(Not run)## Not run: # Simple exponential smoothing (A,N,N) model <- ETSModel(error_type = "A", trend_type = "N", season_type = "N") # Holt's linear trend (A,A,N) model <- ETSModel(error_type = "A", trend_type = "A", season_type = "N") # Holt-Winters additive (A,A,A) model <- ETSModel( error_type = "A", trend_type = "A", season_type = "A", s = 12 ) # Holt-Winters multiplicative (M,M,M) model <- ETSModel( error_type = "M", trend_type = "M", season_type = "M", s = 12 ) ## End(Not run)
Filter Forecast to Specific Horizons
filter_horizons(forecast, horizons)filter_horizons(forecast, horizons)
forecast |
A Forecast object |
horizons |
Vector of horizons to keep |
Filtered Forecast object
Filter Forecast to Specific Confidence Levels
filter_levels(forecast, levels)filter_levels(forecast, levels)
forecast |
A Forecast object |
levels |
Vector of confidence levels to keep |
Filtered Forecast object
Fits a baseline forecasting model to observed data.
fit_baseline(x, model, temporal_info = NULL)fit_baseline(x, model, temporal_info = NULL)
x |
Numeric vector of time series data |
model |
A model created using ConstantModel(), ARMAModel(), ETSModel(), or other model functions (see ?ConstantModel for available models) |
temporal_info |
Optional TemporalInfo object with start date and resolution |
A fitted model object that can be used for forecasting
## Not run: data <- c(1.2, 2.3, 3.1, 2.8, 3.5, 4.2, 3.9) model <- ARMAModel(p = 1, q = 1) fitted <- fit_baseline(data, model) ## End(Not run)## Not run: data <- c(1.2, 2.3, 3.1, 2.8, 3.5, 4.2, 3.9) model <- ARMAModel(p = 1, q = 1) fitted <- fit_baseline(data, model) ## End(Not run)
Generates a complete forecast including point forecasts, prediction intervals, and optionally trajectories.
forecast( fitted, interval_method = NoInterval(), horizon = 1L, levels = 0.95, include_median = TRUE, truth = NULL, model_name = "" )forecast( fitted, interval_method = NoInterval(), horizon = 1L, levels = 0.95, include_median = TRUE, truth = NULL, model_name = "" )
fitted |
A fitted model object from fit_baseline() |
interval_method |
Interval method object (NoInterval, EmpiricalInterval, etc.) |
horizon |
Integer or vector of integers specifying forecast horizons |
levels |
Numeric vector of confidence levels (default: 0.95) |
include_median |
Whether to include median forecast (default: TRUE) |
truth |
Optional vector of true values for evaluation |
model_name |
Optional name for the model |
A Forecast object (list) containing forecasts and metadata
## Not run: # Point forecast only fc <- forecast(fitted, interval_method = NoInterval(), horizon = 1:12) # With prediction intervals fc <- forecast(fitted, interval_method = EmpiricalInterval(n_trajectories = 1000), horizon = 1:12, levels = c(0.80, 0.95) ) # With truth for evaluation fc <- forecast(fitted, interval_method = EmpiricalInterval(), horizon = 1:12, truth = c(3.6, 3.8, 4.1, ...) ) ## End(Not run)## Not run: # Point forecast only fc <- forecast(fitted, interval_method = NoInterval(), horizon = 1:12) # With prediction intervals fc <- forecast(fitted, interval_method = EmpiricalInterval(n_trajectories = 1000), horizon = 1:12, levels = c(0.80, 0.95) ) # With truth for evaluation fc <- forecast(fitted, interval_method = EmpiricalInterval(), horizon = 1:12, truth = c(3.6, 3.8, 4.1, ...) ) ## End(Not run)
Check if Forecast has Horizon
has_horizon(forecast)has_horizon(forecast)
forecast |
A Forecast object |
Logical TRUE/FALSE
Check if Forecast has Intervals
has_intervals(forecast)has_intervals(forecast)
forecast |
A Forecast object |
Logical TRUE/FALSE
Check if Forecast has Mean
has_mean(forecast)has_mean(forecast)
forecast |
A Forecast object |
Logical TRUE/FALSE
Check if Forecast has Median
has_median(forecast)has_median(forecast)
forecast |
A Forecast object |
Logical TRUE/FALSE
Check if Forecast has Trajectories
has_trajectories(forecast)has_trajectories(forecast)
forecast |
A Forecast object |
Logical TRUE/FALSE
Check if Forecast has Truth Values
has_truth(forecast)has_truth(forecast)
forecast |
A Forecast object |
Logical TRUE/FALSE
Creates an Increase-Decrease-Stable model for trend detection.
IDSModel(threshold = 0, window_size = 3L)IDSModel(threshold = 0, window_size = 3L)
threshold |
Threshold for trend detection (default: 0.0) |
window_size |
Window size for trend calculation (default: 3) |
An IDSModel object
## Not run: model <- IDSModel() model <- IDSModel(threshold = 0.1, window_size = 5) ## End(Not run)## Not run: model <- IDSModel() model <- IDSModel(threshold = 0.1, window_size = 5) ## End(Not run)
Creates an Integer-valued ARCH model for count time series.
INARCHModel(p = 1L)INARCHModel(p = 1L)
p |
Order of the INARCH model |
An INARCHModel object
## Not run: model <- INARCHModel(p = 1) ## End(Not run)## Not run: model <- INARCHModel(p = 1) ## End(Not run)
Generates prediction intervals from a fitted model.
interval_forecast(fitted, method, horizon = 1L, levels = 0.95)interval_forecast(fitted, method, horizon = 1L, levels = 0.95)
fitted |
A fitted model object from fit_baseline() |
method |
Interval method object |
horizon |
Integer or vector of integers specifying forecast horizons |
levels |
Numeric vector of confidence levels |
List containing point forecasts, median, intervals, and trajectories
## Not run: intervals <- interval_forecast(fitted, method = EmpiricalInterval(), horizon = 1:12, levels = c(0.80, 0.95) ) ## End(Not run)## Not run: intervals <- interval_forecast(fitted, method = EmpiricalInterval(), horizon = 1:12, levels = c(0.80, 0.95) ) ## End(Not run)
Applies the inverse of a transformation to data (e.g., exp for log).
inverse_transform_data(y, transformation)inverse_transform_data(y, transformation)
y |
Numeric vector of transformed data |
transformation |
A transformation object |
Original-scale numeric vector
## Not run: transformed <- c(0, 0.693, 1.099, 1.386, 1.609) trans <- LogTransform() original <- inverse_transform_data(transformed, trans) ## End(Not run)## Not run: transformed <- c(0, 0.693, 1.099, 1.386, 1.609) trans <- LogTransform() original <- inverse_transform_data(transformed, trans) ## End(Not run)
Tests whether Julia is configured and ForecastBaselines.jl is accessible.
is_setup()is_setup()
TRUE if setup is complete, FALSE otherwise
## Not run: if (is_setup()) { # Use forecasting functions } else { setup_ForecastBaselines() } ## End(Not run)## Not run: if (is_setup()) { # Use forecasting functions } else { setup_ForecastBaselines() } ## End(Not run)
Creates a kernel density estimation model for non-parametric forecasting.
KDEModel(bandwidth = NULL, kernel = "gaussian")KDEModel(bandwidth = NULL, kernel = "gaussian")
bandwidth |
Bandwidth for KDE (default: NULL for automatic selection) |
kernel |
Kernel function to use (default: "gaussian") |
A KDEModel object
## Not run: model <- KDEModel() model <- KDEModel(bandwidth = 0.5) ## End(Not run)## Not run: model <- KDEModel() model <- KDEModel(bandwidth = 0.5) ## End(Not run)
Creates a log(x + c) transformation. Useful for data with zeros.
LogPlusOneTransform(c = 1)LogPlusOneTransform(c = 1)
c |
Constant to add before taking log (default: 1) |
A LogPlusOneTransform object
## Not run: # Standard log(x + 1) trans <- LogPlusOneTransform() # Custom constant trans <- LogPlusOneTransform(c = 0.5) ## End(Not run)## Not run: # Standard log(x + 1) trans <- LogPlusOneTransform() # Custom constant trans <- LogPlusOneTransform(c = 0.5) ## End(Not run)
Creates a natural logarithm transformation. Data must be positive.
LogTransform()LogTransform()
A LogTransform object
## Not run: trans <- LogTransform() ## End(Not run)## Not run: trans <- LogTransform() ## End(Not run)
Creates a seasonal forecasting model based on similar historical dates.
LSDModel(s, window_width = 1L, trend_correction = FALSE)LSDModel(s, window_width = 1L, trend_correction = FALSE)
s |
Seasonal period (e.g., 7 for weekly, 12 for monthly) |
window_width |
Width of the window for averaging similar dates (default: 1) |
trend_correction |
Whether to apply trend correction (default: FALSE) |
An LSDModel object
## Not run: # Weekly seasonality model <- LSDModel(s = 7) # Monthly seasonality with window model <- LSDModel(s = 12, window_width = 2) ## End(Not run)## Not run: # Weekly seasonality model <- LSDModel(s = 7) # Monthly seasonality with window model <- LSDModel(s = 12, window_width = 2) ## End(Not run)
Creates a forecast based on the empirical marginal distribution using the mean of the p most recent observations.
MarginalModel(p = NULL)MarginalModel(p = NULL)
p |
Number of most recent observations to use (default: all observations) |
A MarginalModel object
## Not run: model <- MarginalModel(p = 10) ## End(Not run)## Not run: model <- MarginalModel(p = 10) ## End(Not run)
Creates prediction intervals by simulating trajectories from the fitted model. This method uses the model's own simulation mechanism.
ModelTrajectoryInterval( n_trajectories = 1000L, seed = NULL, positivity_correction = "none", return_trajectories = FALSE )ModelTrajectoryInterval( n_trajectories = 1000L, seed = NULL, positivity_correction = "none", return_trajectories = FALSE )
n_trajectories |
Number of trajectories to simulate (default: 1000) |
seed |
Random seed for reproducibility (default: NULL) |
positivity_correction |
Method to ensure positive forecasts: "none", "post_clip", "truncate", or "zero_floor" (default: "none") |
return_trajectories |
Whether to return forecast trajectories (default: FALSE) |
A ModelTrajectoryInterval object
## Not run: # Basic model-based intervals method <- ModelTrajectoryInterval() # With more trajectories method <- ModelTrajectoryInterval(n_trajectories = 2000, seed = 456) # Return trajectories for analysis method <- ModelTrajectoryInterval( n_trajectories = 1000, return_trajectories = TRUE ) ## End(Not run)## Not run: # Basic model-based intervals method <- ModelTrajectoryInterval() # With more trajectories method <- ModelTrajectoryInterval(n_trajectories = 2000, seed = 456) # Return trajectories for analysis method <- ModelTrajectoryInterval( n_trajectories = 1000, return_trajectories = TRUE ) ## End(Not run)
Creates an interval method that produces only point forecasts without prediction intervals.
NoInterval()NoInterval()
A NoInterval object
## Not run: method <- NoInterval() fc <- forecast(fitted, interval_method = method, horizon = 1:12) ## End(Not run)## Not run: method <- NoInterval() fc <- forecast(fitted, interval_method = method, horizon = 1:12) ## End(Not run)
Creates a transformation that applies no changes to the data.
NoTransform()NoTransform()
A NoTransform object
## Not run: trans <- NoTransform() ## End(Not run)## Not run: trans <- NoTransform() ## End(Not run)
Creates an ordinary least squares model with polynomial trend.
OLSModel(degree = 1L, differencing = 0L)OLSModel(degree = 1L, differencing = 0L)
degree |
Polynomial degree (default: 1 for linear trend) |
s |
Seasonal period (default: NULL for no seasonality) |
An OLSModel object
## Not run: # Linear trend model <- OLSModel(degree = 1) # Quadratic trend with seasonality model <- OLSModel(degree = 2, s = 12) ## End(Not run)## Not run: # Linear trend model <- OLSModel(degree = 1) # Quadratic trend with seasonality model <- OLSModel(degree = 2, s = 12) ## End(Not run)
Creates prediction intervals using parametric assumptions based on the model's distribution (e.g., assuming normality for ARMA models).
ParametricInterval(positivity_correction = "none")ParametricInterval(positivity_correction = "none")
positivity_correction |
Method to ensure positive forecasts: "none" or "post_clip" (default: "none") |
A ParametricInterval object
## Not run: # Standard parametric intervals method <- ParametricInterval() # With positivity correction method <- ParametricInterval(positivity_correction = "post_clip") ## End(Not run)## Not run: # Standard parametric intervals method <- ParametricInterval() # With positivity correction method <- ParametricInterval(positivity_correction = "post_clip") ## End(Not run)
Generates point forecasts from a fitted model.
point_forecast(fitted, horizon = 1L)point_forecast(fitted, horizon = 1L)
fitted |
A fitted model object from fit_baseline() |
horizon |
Integer or vector of integers specifying forecast horizons |
Numeric vector of point forecasts
## Not run: forecasts <- point_forecast(fitted, horizon = 1:12) ## End(Not run)## Not run: forecasts <- point_forecast(fitted, horizon = 1:12) ## End(Not run)
Creates a power transformation with a constant: (x + c)^lambda. Useful for Box-Cox transformations with zeros.
PowerPlusOneTransform(lambda, constant = 1)PowerPlusOneTransform(lambda, constant = 1)
lambda |
Power parameter |
constant |
Constant to add before transformation (default: 1.0) |
A PowerPlusOneTransform object
## Not run: # Box-Cox transformation trans <- PowerPlusOneTransform(lambda = 0.3) # Custom constant trans <- PowerPlusOneTransform(lambda = 0.5, constant = 0.5) ## End(Not run)## Not run: # Box-Cox transformation trans <- PowerPlusOneTransform(lambda = 0.3) # Custom constant trans <- PowerPlusOneTransform(lambda = 0.5, constant = 0.5) ## End(Not run)
Creates a power transformation: x^lambda (Box-Cox family).
PowerTransform(lambda)PowerTransform(lambda)
lambda |
Power parameter (lambda = 0 is log, lambda = 0.5 is sqrt) |
A PowerTransform object
## Not run: # Square root (equivalent to SquareRootTransform) trans <- PowerTransform(lambda = 0.5) # Cube root trans <- PowerTransform(lambda = 1 / 3) ## End(Not run)## Not run: # Square root (equivalent to SquareRootTransform) trans <- PowerTransform(lambda = 0.5) # Cube root trans <- PowerTransform(lambda = 1 / 3) ## End(Not run)
Print method for Forecast objects
## S3 method for class 'ForecastBaselines_Forecast' print(x, ...)## S3 method for class 'ForecastBaselines_Forecast' print(x, ...)
x |
A Forecast object |
... |
Additional arguments (ignored) |
This function initializes Julia, installs ForecastBaselines.jl if needed, and loads the package. Must be called before using any forecasting functions.
setup_ForecastBaselines( JULIA_HOME = NULL, install_package = TRUE, rebuild = FALSE, verbose = TRUE )setup_ForecastBaselines( JULIA_HOME = NULL, install_package = TRUE, rebuild = FALSE, verbose = TRUE )
JULIA_HOME |
Path to Julia installation (optional, will auto-detect if not provided) |
install_package |
Whether to install ForecastBaselines.jl if not already installed |
rebuild |
Whether to rebuild the Julia system image |
verbose |
Whether to print verbose output during setup |
Invisibly returns TRUE if setup was successful
## Not run: # Basic setup (auto-detect Julia) setup_ForecastBaselines() # Specify Julia location setup_ForecastBaselines(JULIA_HOME = "/usr/local/julia/bin") ## End(Not run)## Not run: # Basic setup (auto-detect Julia) setup_ForecastBaselines() # Specify Julia location setup_ForecastBaselines(JULIA_HOME = "/usr/local/julia/bin") ## End(Not run)
Creates a square root transformation. Useful for count data and variance stabilization.
SquareRootTransform()SquareRootTransform()
A SquareRootTransform object
## Not run: trans <- SquareRootTransform() ## End(Not run)## Not run: trans <- SquareRootTransform() ## End(Not run)
Creates a Seasonal-Trend decomposition using Loess model.
STLModel(s, trend = TRUE, robust = FALSE)STLModel(s, trend = TRUE, robust = FALSE)
s |
Seasonal period |
trend |
Whether to include trend component (default: TRUE) |
robust |
Whether to use robust fitting (default: FALSE) |
An STLModel object
## Not run: # Monthly seasonality model <- STLModel(s = 12) # Robust STL model <- STLModel(s = 12, robust = TRUE) ## End(Not run)## Not run: # Monthly seasonality model <- STLModel(s = 12) # Robust STL model <- STLModel(s = 12, robust = TRUE) ## End(Not run)
Creates a TemporalInfo object to track dates and time resolution.
TemporalInfo(start = 1, resolution = 1)TemporalInfo(start = 1, resolution = 1)
start |
Start date (Date, POSIXct, or integer) |
resolution |
Time resolution (integer for generic, or period object) |
A TemporalInfo object
## Not run: # Simple integer indexing temp_info <- TemporalInfo(start = 1, resolution = 1) # Date-based temp_info <- TemporalInfo(start = as.Date("2024-01-01"), resolution = 1) ## End(Not run)## Not run: # Simple integer indexing temp_info <- TemporalInfo(start = 1, resolution = 1) # Date-based temp_info <- TemporalInfo(start = as.Date("2024-01-01"), resolution = 1) ## End(Not run)
Applies a transformation to data.
transform_data(x, transformation)transform_data(x, transformation)
x |
Numeric vector of data |
transformation |
A transformation object |
**Recommended:** Use R's built-in transformation functions instead for better reliability and flexibility. This function has limitations due to bugs in ForecastBaselines.jl (e.g., SquareRootTransform fails).
See 'vignette("transformations")' for the recommended R approach.
Transformed numeric vector
## Not run: # Julia approach (limited): data <- c(1, 2, 3, 4, 5) trans <- LogTransform() transformed <- transform_data(data, trans) # Recommended R approach: transformed <- log(data) ## End(Not run)## Not run: # Julia approach (limited): data <- c(1, 2, 3, 4, 5) trans <- LogTransform() transformed <- transform_data(data, trans) # Recommended R approach: transformed <- log(data) ## End(Not run)
Wraps a model with a data transformation.
transform_model(model, transformation)transform_model(model, transformation)
model |
A model object |
transformation |
A transformation object |
**Not Implemented:** This function does not work because ForecastBaselines.jl does not implement 'transform()' for model types.
**Recommended approach:** Transform your data manually in R before fitting:
“'r # Instead of transform_model(): log_data <- log(data) fitted <- fit_baseline(log_data, model) fc <- forecast(fitted, ...) fc$mean <- exp(fc$mean) # Back-transform “'
See 'vignette("transformations")' for complete examples.
A transformed model object
## Not run: # This will fail - not implemented in Julia package model <- ARMAModel(p = 1, q = 1) trans <- LogTransform() transformed_model <- transform_model(model, trans) # Error! # Use manual transformation instead: log_data <- log(data) fitted <- fit_baseline(log_data, model) fc <- forecast(fitted, interval_method = NoInterval(), horizon = 1:5) fc$mean <- exp(fc$mean) ## End(Not run)## Not run: # This will fail - not implemented in Julia package model <- ARMAModel(p = 1, q = 1) trans <- LogTransform() transformed_model <- transform_model(model, trans) # Error! # Use manual transformation instead: log_data <- log(data) fitted <- fit_baseline(log_data, model) fc <- forecast(fitted, interval_method = NoInterval(), horizon = 1:5) fc$mean <- exp(fc$mean) ## End(Not run)
Truncate Forecast Horizon
truncate_horizon(forecast, max_h)truncate_horizon(forecast, max_h)
forecast |
A Forecast object |
max_h |
Maximum horizon to keep |
Truncated Forecast object