### Install fasster R Package from GitHub Source: https://github.com/tidyverts/fasster/blob/master/README.md This snippet demonstrates how to install the development version of the `fasster` R package directly from GitHub using the `devtools` package. This method is suitable for users who want to access the latest features or contribute to the project. ```R # install.packages("devtools") devtools::install_github("tidyverts/fasster") ``` -------------------------------- ### Specify a Basic FASSTER Model in R Source: https://github.com/tidyverts/fasster/blob/master/README.md This example illustrates how to specify a simple FASSTER model using standard R formula conventions. It loads essential `tidyverts` ecosystem libraries, prepares `lung_deaths` time-series data, and fits a model where `fdeaths` is explained by `mdeaths`. The `report()` function is then used to display a summary, including estimated variances. ```R library(fasster) library(tidyverse) library(lubridate) library(tsibble) library(fable) lung_deaths <- as_tsibble(cbind(mdeaths, fdeaths), pivot_longer = FALSE) fit <- lung_deaths %>% model(fasster = FASSTER(fdeaths ~ mdeaths)) fit %>% report() ``` -------------------------------- ### Decompose a simple FASSTER model to view components in R Source: https://github.com/tidyverts/fasster/blob/master/README.md Access underlying states of a fitted FASSTER model using `components()`. This R example shows how to extract aggregates like trends and seasonalities from a basic `fit` object, providing a detailed breakdown of its structure. ```R fit %>% components() #> # A dable: 72 x 5 [1M] #> # Key: .model [1] #> # FASSTER Decomposition: value = `fourier(12)` + `trend(1)` #> .model index value `fourier(12)` `trend(1)` #> #> 1 fasster 1973 Jan 9007 -795. 9740. #> 2 fasster 1973 Feb 8106 -1546. 9754. #> 3 fasster 1973 Mar 8928 -758. 9719. #> 4 fasster 1973 Apr 9137 -536. 9706. #> 5 fasster 1973 May 10017 322. 9693. #> 6 fasster 1973 Jun 10826 802. 9694. #> 7 fasster 1973 Jul 11317 1669. 9830. #> 8 fasster 1973 Aug 10744 974. 9755. #> 9 fasster 1973 Sep 9713 -65.7 9761. #> 10 fasster 1973 Oct 9938 233. 9768. #> # … with 62 more rows ``` -------------------------------- ### FASSTER Model with Switch Operator for Multiple Seasonality in R Source: https://github.com/tidyverts/fasster/blob/master/README.md This advanced example showcases the `fasster` package's `%S%` (switch operator) for modeling complex patterns such as multiple seasonality. It allows the model to dynamically switch between different seasonal and trend components based on a 'WorkDay' indicator. The model also includes exogenous regressors like `Temperature` and its squared term. ```R elec_tr <- tsibbledata::vic_elec %>% filter( Time < lubridate::ymd("2012-03-01") ) %>% mutate(WorkDay = wday(Time) %in% 2:6 & !Holiday) elec_fit <- elec_tr %>% model( fasster = fasster(log(Demand) ~ WorkDay %S% (fourier(48, 16) + trend(1)) + Temperature + I(Temperature^2) ) ) ``` -------------------------------- ### Decompose a complex FASSTER model with multiple regressors in R Source: https://github.com/tidyverts/fasster/blob/master/README.md Illustrates decomposing a more intricate FASSTER model (`elec_fit`) that incorporates external regressors like `WorkDay` and `Temperature`. The output details how each component contributes to the modeled `log(Demand)`. ```R elec_fit %>% components() #> # A dable: 2,880 x 9 [30m] #> # Key: .model [1] #> # FASSTER Decomposition: log(Demand) = `WorkDay_FALSE/fourier(48, 16)` + #> # `WorkDay_FALSE/trend(1)` + `WorkDay_TRUE/fourier(48, 16)` + #> # `WorkDay_TRUE/trend(1)` + Temperature + `I(Temperature^2)` #> .model Time `log(Demand)` `WorkDay_FALSE/… `WorkDay_FALSE/… #> #> 1 fasst… 2012-01-01 00:00:00 8.39 -0.00345 8.75 #> 2 fasst… 2012-01-01 00:30:00 8.36 -0.0234 8.75 #> 3 fasst… 2012-01-01 01:00:00 8.31 -0.0971 8.75 #> 4 fasst… 2012-01-01 01:30:00 8.26 -0.105 8.76 #> 5 fasst… 2012-01-01 02:00:00 8.30 -0.117 8.76 #> 6 fasst… 2012-01-01 02:30:00 8.26 -0.0812 8.78 #> 7 fasst… 2012-01-01 03:00:00 8.21 -0.251 8.76 #> 8 fasst… 2012-01-01 03:30:00 8.18 -0.144 8.82 #> 9 fasst… 2012-01-01 04:00:00 8.14 -0.374 8.68 #> 10 fasst… 2012-01-01 04:30:00 8.12 -0.202 8.81 #> # … with 2,870 more rows, and 4 more variables: `WorkDay_TRUE/fourier(48, #> # 16)` , `WorkDay_TRUE/trend(1)` , Temperature , #> # `I(Temperature^2)` ``` -------------------------------- ### Forecast future values from a FASSTER model using fable in R Source: https://github.com/tidyverts/fasster/blob/master/README.md Demonstrates generating future predictions from a fitted FASSTER model. This R snippet utilizes the `forecast()` function from the *fable* package, allowing seamless visualization of the forecasts against historical data using `autoplot`. ```R fit %>% forecast(h=24) %>% autoplot(as_tsibble(USAccDeaths)) ``` -------------------------------- ### FASSTER Model with Trend and Fourier Seasonality in R Source: https://github.com/tidyverts/fasster/blob/master/README.md This snippet demonstrates how to incorporate common state space components like trend and seasonality into a FASSTER model using convenience functions. It applies a first-order polynomial trend (`trend(1)`) and monthly seasonal Fourier terms (`fourier(12)`) to the `USAccDeaths` dataset. The `report()` function provides a summary of the fitted model, including estimated variances. ```R fit <- as_tsibble(USAccDeaths) %>% model(fasster = FASSTER(value ~ trend(1) + fourier(12))) fit %>% report() ``` -------------------------------- ### Forecast FASSTER model with new external data in R Source: https://github.com/tidyverts/fasster/blob/master/README.md Shows how to provide additional future information, such as `WorkDay` and `Temperature`, to the `forecast()` function. This is crucial for models requiring external regressors, ensuring accurate predictions by passing a `tsibble` of future values via `new_data`. ```R elec_ts <- tsibbledata::vic_elec %>% filter( yearmonth(Time) == yearmonth("2012 Mar") ) %>% mutate(WorkDay = wday(Time) %in% 2:6 & !Holiday) %>% select(-Demand) elec_fit %>% forecast(new_data = elec_ts) %>% autoplot(elec_tr) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.