Skip to contents

This function takes in a time series data and generates a forecast for specified number of periods. The function fits an ARIMA model to the data and uses it to generate the forecast. If the data has a clear seasonal pattern, the function fits a seasonal ARIMA model. The function returns two lists: obs_fitted (the fitted values over the observation period) and pred_trend (the predicted trend for the forecast horizon).

Usage

forecast_time_series(ts_data, forecast_horizon, season_period = NULL)

Arguments

ts_data

a time series object or a numeric vector

forecast_horizon

a positive integer specifying the number of periods to forecast

season_period

an optional parameter specifying the seasonal period of the time series

Value

a list containing the observations and predicted trend for the forecast horizon

Examples

# generate a time series data
ts_data <- ts(rnorm(100), frequency = 12, start = c(2014, 1))
# generate a forecast for next 6 periods using auto.arima() with default settings
forecast_time_series(ts_data, 6)
#> Error in forecast_time_series(ts_data, 6): object 'su_yaml' not found