Title: | Prophet Modelling Interface for 'fable' |
---|---|
Description: | Allows prophet models from the 'prophet' package to be used in a tidy workflow with the modelling interface of 'fabletools'. This extends 'prophet' to provide enhanced model specification and management, performance evaluation methods, and model combination tools. |
Authors: | Mitchell O'Hara-Wild [aut, cre], Sean Taylor [ctb] (Prophet library, https://facebook.github.io/prophet/), Ben Letham [ctb] (Prophet library, https://facebook.github.io/prophet/) |
Maintainer: | Mitchell O'Hara-Wild <[email protected]> |
License: | GPL-3 |
Version: | 0.1.0.9000 |
Built: | 2024-11-06 03:28:06 UTC |
Source: | https://github.com/mitchelloharawild/fable.prophet |
Allows prophet models from the 'prophet' package to be used in a tidy workflow with the modelling interface of 'fabletools'. This extends 'prophet' to provide enhanced model specification and management, performance evaluation methods, and model combination tools.
Maintainer: Mitchell O'Hara-Wild [email protected]
Other contributors:
Sean Taylor (Prophet library, https://facebook.github.io/prophet/) [contributor]
Ben Letham (Prophet library, https://facebook.github.io/prophet/) [contributor]
Useful links:
Report bugs at https://github.com/mitchelloharawild/fable.prophet/issues
A prophet model consists of terms which are additively or multiplicatively included in the model. Multiplicative terms are scaled proportionally to the estimated trend, while additive terms are not.
## S3 method for class 'fbl_prophet' components(object, ...)
## S3 method for class 'fbl_prophet' components(object, ...)
object |
An estimated model. |
... |
Unused. |
Extracting a prophet model's components using this function allows you to
visualise the components in a similar way to prophet::prophet_plot_components()
.
A fabletools::dable()
containing estimated states.
if (requireNamespace("tsibbledata")) { library(tsibble) beer_components <- tsibbledata::aus_production %>% model( prophet = prophet(Beer ~ season("year", 4, type = "multiplicative")) ) %>% components() beer_components autoplot(beer_components) library(ggplot2) library(lubridate) beer_components %>% ggplot(aes(x = quarter(Quarter), y = year, group = year(Quarter))) + geom_line() }
if (requireNamespace("tsibbledata")) { library(tsibble) beer_components <- tsibbledata::aus_production %>% model( prophet = prophet(Beer ~ season("year", 4, type = "multiplicative")) ) %>% components() beer_components autoplot(beer_components) library(ggplot2) library(lubridate) beer_components %>% ggplot(aes(x = quarter(Quarter), y = year, group = year(Quarter))) + geom_line() }
Extracts the fitted values from an estimated Prophet model.
## S3 method for class 'fbl_prophet' fitted(object, ...)
## S3 method for class 'fbl_prophet' fitted(object, ...)
object |
The time series model used to produce the forecasts |
... |
Additional arguments for forecast model methods. |
A vector of fitted values.
If additional future information is required (such as exogenous variables or
carrying capacities) by the model, then they should be included as variables
of the new_data
argument.
## S3 method for class 'fbl_prophet' forecast(object, new_data, specials = NULL, times = 1000, ...)
## S3 method for class 'fbl_prophet' forecast(object, new_data, specials = NULL, times = 1000, ...)
object |
The time series model used to produce the forecasts |
new_data |
A |
specials |
(passed by |
times |
The number of sample paths to use in estimating the forecast distribution when |
... |
Additional arguments passed to |
A list of forecasts.
if (requireNamespace("tsibbledata")) { library(tsibble) tsibbledata::aus_production %>% model( prophet = prophet(Beer ~ season("year", 4, type = "multiplicative")) ) %>% forecast() }
if (requireNamespace("tsibbledata")) { library(tsibble) tsibbledata::aus_production %>% model( prophet = prophet(Beer ~ season("year", 4, type = "multiplicative")) ) %>% forecast() }
A glance of a prophet provides the residual's standard deviation (sigma), and a tibble containing the selected changepoints with their trend adjustments.
## S3 method for class 'fbl_prophet' glance(x, ...)
## S3 method for class 'fbl_prophet' glance(x, ...)
x |
model or other R object to convert to single-row data frame |
... |
other arguments passed to methods |
A one row tibble summarising the model's fit.
if (requireNamespace("tsibbledata")) { library(tsibble) library(dplyr) fit <- tsibbledata::aus_production %>% model( prophet = prophet(Beer ~ season("year", 4, type = "multiplicative")) ) glance(fit) }
if (requireNamespace("tsibbledata")) { library(tsibble) library(dplyr) fit <- tsibbledata::aus_production %>% model( prophet = prophet(Beer ~ season("year", 4, type = "multiplicative")) ) glance(fit) }
Prepares a prophet model specification for use within the fable
package.
prophet(formula, ...)
prophet(formula, ...)
formula |
A symbolic description of the model to be fitted of class |
... |
Additional arguments passed to the |
The prophet modelling interface uses a formula
based model specification
(y ~ x
), where the left of the formula specifies the response variable,
and the right specifies the model's predictive terms. Like any model in the
fable framework, it is possible to specify transformations on the response.
A prophet model supports piecewise linear or exponential growth (trend),
additive or multiplicative seasonality, holiday effects and exogenous
regressors. These can be specified using the 'specials' functions detailed
below. The introduction vignette provides more details on how to model data
using this interface to prophet: vignette("intro", package="fable.prophet")
.
The growth
special is used to specify the trend parameters.
growth(type = c("linear", "logistic"), capacity = NULL, floor = NULL, changepoints = NULL, n_changepoints = 25, changepoint_range = 0.8, changepoint_prior_scale = 0.05)
type |
The type of trend (linear or logistic). |
capacity |
The carrying capacity for when type is "logistic". |
floor |
The saturating minimum for when type is "logistic". |
changepoints |
A vector of dates/times for changepoints. If NULL , changepoints are automatically selected. |
n_changepoints |
The total number of changepoints to be selected if changepoints is NULL
|
changepoint_range |
Proportion of the start of the time series where changepoints are automatically selected. |
changepoint_prior_scale |
Controls the flexibility of the trend. |
The season
special is used to specify a seasonal component. This special can be used multiple times for different seasonalities.
Warning: The inputs controlling the seasonal period
is specified is different than prophet::prophet()
. Numeric inputs are treated as the number of observations in each seasonal period, not the number of days.
season(period = NULL, order = NULL, prior_scale = 10, type = c("additive", "multiplicative"), name = NULL)
period |
The periodic nature of the seasonality. If a number is given, it will specify the number of observations in each seasonal period. If a character is given, it will be parsed using lubridate::as.period , allowing seasonal periods such as "2 years". |
order |
The number of terms in the partial Fourier sum. The higher the order , the more flexible the seasonality can be. |
prior_scale |
Used to control the amount of regularisation applied. Reducing this will dampen the seasonal effect. |
type |
The nature of the seasonality. If "additive", the variability in the seasonal pattern is fixed. If "multiplicative", the seasonal pattern varies proportionally to the level of the series. |
name |
The name of the seasonal term (allowing you to name an annual pattern as 'annual' instead of 'year' or 365.25 for example). |
The holiday
special is used to specify a tsibble
containing holidays for the model.
holiday(holidays = NULL, prior_scale = 10L)
holidays |
A tsibble containing a set of holiday events. The event name is given in the 'holiday' column, and the event date is given via the index. Additionally, "lower_window" and "upper_window" columns can be used to include days before and after the holiday. |
prior_scale |
Used to control the amount of regularisation applied. Reducing this will dampen the holiday effect. |
The xreg
special is used to include exogenous regressors in the model. This special can be used multiple times for different regressors with different arguments.
Exogenous regressors can also be used in the formula without explicitly using the xreg()
special, which will then use the default arguments.
xreg(..., prior_scale = NULL, standardize = "auto", type = NULL)
... |
A set of bare expressions that are evaluated as exogenous regressors |
prior_scale |
Used to control the amount of regularisation applied. Reducing this will dampen the regressor effect. |
standardize |
Should the regressor be standardised before fitting? If "auto", it will standardise if the regressor is not binary. |
type |
Does the effect of the regressor vary proportionally to the level of the series? If so, "multiplicative" is best. Otherwise, use "additive" |
library(tsibble) as_tsibble(USAccDeaths) %>% model( prophet = prophet(value ~ season("year", 4, type = "multiplicative")) )
library(tsibble) as_tsibble(USAccDeaths) %>% model( prophet = prophet(value ~ season("year", 4, type = "multiplicative")) )
Extracts the residuals from an estimated Prophet model.
## S3 method for class 'fbl_prophet' residuals(object, ...)
## S3 method for class 'fbl_prophet' residuals(object, ...)
object |
The time series model used to produce the forecasts |
... |
Additional arguments for forecast model methods. |
A vector of residuals.
Extract estimated coefficients from a prophet model
## S3 method for class 'fbl_prophet' tidy(x, ...)
## S3 method for class 'fbl_prophet' tidy(x, ...)
x |
An object to be converted into a tidy |
... |
Additional arguments to tidying method. |
A tibble containing the model's estimated parameters.
if (requireNamespace("tsibbledata")) { library(tsibble) library(dplyr) fit <- tsibbledata::aus_production %>% model( prophet = prophet(Beer ~ season("year", 4, type = "multiplicative")) ) tidy(fit) # coef(fit) or coefficients(fit) can also be used }
if (requireNamespace("tsibbledata")) { library(tsibble) library(dplyr) fit <- tsibbledata::aus_production %>% model( prophet = prophet(Beer ~ season("year", 4, type = "multiplicative")) ) tidy(fit) # coef(fit) or coefficients(fit) can also be used }