diff --git a/docs/404.html b/docs/404.html deleted file mode 100644 index d7ab004..0000000 --- a/docs/404.html +++ /dev/null @@ -1,124 +0,0 @@ - - - - - - - -Page not found (404) • sweep - - - - - - - - - - - - - - - - - Skip to contents - - -
-
-
- -Content not found. Please use links in the navbar. - -
-
- - - -
- - - - - - - diff --git a/docs/articles/SW00_Introduction_to_sweep.html b/docs/articles/SW00_Introduction_to_sweep.html deleted file mode 100644 index 6dea8cf..0000000 --- a/docs/articles/SW00_Introduction_to_sweep.html +++ /dev/null @@ -1,738 +0,0 @@ - - - - - - - - -Introduction to sweep • sweep - - - - - - - - - - - - - - - - - - Skip to contents - - -
- - - - -
-
- - - -
-

Extending broom to time series forecasting

-
-

The sweep package extends the broom tools -(tidy, glance, and augment) for performing forecasts and time series -analysis in the “tidyverse”. The package is geared towards the workflow -required to perform forecasts using Rob Hyndman’s forecast -package, and contains the following elements:

-
    -
  1. model tidiers: sw_tidy, -sw_glance, sw_augment, -sw_tidy_decomp functions extend tidy, -glance, and augment from the -broom package specifically for models (ets(), -Arima(), bats(), etc) used for -forecasting.

  2. -
  3. forecast tidier: sw_sweep converts -a forecast object to a tibble that can be easily -manipulated in the “tidyverse”.

  4. -
-

To illustrate, let’s take a basic forecasting workflow starting from -data collected in a tibble format and then performing a forecast to -achieve the end result in tibble format.

-
-

Prerequisites -

-

Before we get started, load the following packages.

- -
-
-

Forecasting Sales of Beer, Wine, and Distilled Alcohol -Beverages -

-

We’ll use the tidyquant package to get the US alcohol -sales, which comes from the FRED data base (the origin is the US Bureau -of the Census, one of the 80+ data sources FRED connects to). The FRED -code is “S4248SM144NCEN” and the data set can be found here.

-
-alcohol_sales_tbl <- tq_get("S4248SM144NCEN", 
-                            get  = "economic.data", 
-                            from = "2007-01-01",
-                            to   = "2016-12-31")
-alcohol_sales_tbl
-
## # A tibble: 120 × 3
-##    symbol         date       price
-##    <chr>          <date>     <int>
-##  1 S4248SM144NCEN 2007-01-01  6627
-##  2 S4248SM144NCEN 2007-02-01  6743
-##  3 S4248SM144NCEN 2007-03-01  8195
-##  4 S4248SM144NCEN 2007-04-01  7828
-##  5 S4248SM144NCEN 2007-05-01  9570
-##  6 S4248SM144NCEN 2007-06-01  9484
-##  7 S4248SM144NCEN 2007-07-01  8608
-##  8 S4248SM144NCEN 2007-08-01  9543
-##  9 S4248SM144NCEN 2007-09-01  8123
-## 10 S4248SM144NCEN 2007-10-01  9649
-## # ℹ 110 more rows
-

We can quickly visualize using the ggplot2 package. We -can see that there appears to be some seasonality and an upward -trend.

-
-alcohol_sales_tbl %>%
-    ggplot(aes(x = date, y = price)) +
-    geom_line(linewidth = 1, color = palette_light()[[1]]) +
-    geom_smooth(method = "loess") +
-    labs(title = "US Alcohol Sales: Monthly", x = "", y = "Millions") +
-    scale_y_continuous(labels = scales::dollar) +
-    scale_x_date(date_breaks = "1 year", date_labels = "%Y") +
-    theme_tq()
-
## `geom_smooth()` using formula = 'y ~ x'
-

-
-
-

Forecasting Workflow -

-

The forecasting workflow involves a few basic steps:

-
    -
  1. Step 1: Coerce to a ts object class.
  2. -
  3. Step 2: Apply a model (or set of models)
  4. -
  5. Step 3: Forecast the models (similar to predict)
  6. -
  7. Step 4: Use sw_sweep() to tidy the forecast.
  8. -
-

Note that we purposely omit other steps such as testing the -series for stationarity (Box.test(type = "Ljung")) and -analysis of autocorrelations (Acf, Pacf) for -brevity purposes. We recommend the analyst to follow the forecasting -workflow in “Forecasting: principles -and practice”

-
-

Step 1: Coerce to a ts object class -

-

The forecast package uses the ts data -structure, which is quite a bit different than tibbles that we are -currently using. Fortunately, it’s easy to get to the correct structure -with tk_ts() from the timetk package. The -start and freq variables are required for the -regularized time series (ts) class, and these specify how -to treat the time series. For monthly, the frequency should be specified -as 12. This results in a nice calendar view. The -silent = TRUE tells the tk_ts() function to -skip the warning notifying us that the “date” column is being dropped. -Non-numeric columns must be dropped for ts class, which is -matrix based and a homogeneous data class.

-
-alcohol_sales_ts <- tk_ts(alcohol_sales_tbl, start = 2007, freq = 12, silent = TRUE)
-alcohol_sales_ts
-
##        Jan   Feb   Mar   Apr   May   Jun   Jul   Aug   Sep   Oct   Nov   Dec
-## 2007  6627  6743  8195  7828  9570  9484  8608  9543  8123  9649  9390 10065
-## 2008  7093  7483  8365  8895  9794  9977  9553  9375  9225  9948  8758 10839
-## 2009  7266  7578  8688  9162  9369 10167  9507  8923  9272  9075  8949 10843
-## 2010  6558  7481  9475  9424  9351 10552  9077  9273  9420  9413  9866 11455
-## 2011  6901  8014  9832  9281  9967 11344  9106 10469 10085  9612 10328 11483
-## 2012  7486  8641  9709  9423 11342 11274  9845 11163  9532 10754 10953 11922
-## 2013  8383  8870 10085 10462 12177 11342 11139 11409 10442 11479 11077 12636
-## 2014  8506  9003  9991 10903 11709 11815 10875 10884 10725 11697 10353 13153
-## 2015  8279  8926 10557 10933 11330 12708 11700 11079 11882 11865 11420 14100
-## 2016  8556 10199 11949 11253 12046 13453 10755 12465 12038 11674 12761 14137
-

A significant benefit is that the resulting ts object -maintains a “timetk index”, which will help with forecasting dates -later. We can verify this using has_timetk_idx() from the -timetk package.

-
-has_timetk_idx(alcohol_sales_ts)
-
## [1] TRUE
-

Now that a time series has been coerced, let’s proceed with -modeling.

-
-
-

Step 2: Modeling a time series -

-

The modeling workflow takes a time series object and applies a model. -Nothing new here: we’ll simply use the ets() function from -the forecast package to get an Exponential Smoothing ETS -(Error, Trend, Seasonal) model.

-
-fit_ets <- alcohol_sales_ts %>%
-    ets()
-

Where sweep can help is in the evaluation of a model. -Expanding on the broom package there are four -functions:

- -

The guide below shows which model object compatibility with -sweep tidier functions.

- - -------- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Function Compatibility
Objectsw_tidy()sw_glance()sw_augment()sw_tidy_decomp()sw_sweep()
ar
arimaXXX
ArimaXXX
etsXXXX
baggedETS
batsXXXX
tbatsXXXX
nnetarXXX
stlX
HoltWintersXXXX
StructTSXXXX
tslmXXX
decomposeX
adf.testXX
Box.testXX
kpss.testXX
forecastX
-

Going through the tidiers, we can get useful model -information.

-
-

sw_tidy -

-

sw_tidy() returns the model parameters.

-
-sw_tidy(fit_ets)
-
## # A tibble: 17 × 2
-##    term     estimate
-##    <chr>       <dbl>
-##  1 alpha    0.159   
-##  2 beta     0.0180  
-##  3 gamma    0.000107
-##  4 phi      0.970   
-##  5 l     8389.      
-##  6 b       38.9     
-##  7 s0       1.17    
-##  8 s1       1.02    
-##  9 s2       1.04    
-## 10 s3       0.995   
-## 11 s4       1.04    
-## 12 s5       0.993   
-## 13 s6       1.12    
-## 14 s7       1.07    
-## 15 s8       0.982   
-## 16 s9       0.975   
-## 17 s10      0.837
-
-
-

sw_glance -

-

sw_glance() returns the model quality parameters.

-
-sw_glance(fit_ets)
-
## # A tibble: 1 × 12
-##   model.desc   sigma logLik   AIC   BIC    ME  RMSE   MAE   MPE  MAPE  MASE
-##   <chr>        <dbl>  <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
-## 1 ETS(M,Ad,M) 0.0458 -1012. 2060. 2111.  40.7  431.  357. 0.223  3.54 0.705
-## # ℹ 1 more variable: ACF1 <dbl>
-
-
-

sw_augment -

-

sw_augment() returns the actual, fitted and residual -values.

-
-augment_fit_ets <- sw_augment(fit_ets)
-augment_fit_ets
-
## # A tibble: 120 × 4
-##    index     .actual .fitted   .resid
-##    <yearmon>   <dbl>   <dbl>    <dbl>
-##  1 Jan 2007     6627   6446.  0.0280 
-##  2 Feb 2007     6743   7122. -0.0532 
-##  3 Mar 2007     8195   8255. -0.00730
-##  4 Apr 2007     7828   8330. -0.0603 
-##  5 May 2007     9570   8986.  0.0650 
-##  6 Jun 2007     9484   9541. -0.00597
-##  7 Jul 2007     8608   8500.  0.0127 
-##  8 Aug 2007     9543   8932.  0.0684 
-##  9 Sep 2007     8123   8694. -0.0657 
-## 10 Oct 2007     9649   8977.  0.0749 
-## # ℹ 110 more rows
-

We can review the residuals to determine if their are any underlying -patterns left. Note that the index is class yearmon, which -is a regularized date format.

-
-augment_fit_ets %>%
-    ggplot(aes(x = index, y = .resid)) +
-    geom_hline(yintercept = 0, color = "grey40") +
-    geom_point(color = palette_light()[[1]], alpha = 0.5) +
-    geom_smooth(method = "loess") +
-    scale_x_yearmon(n = 10) +
-    labs(title = "US Alcohol Sales: ETS Residuals", x = "") + 
-    theme_tq()
-
## `geom_smooth()` using formula = 'y ~ x'
-

-
-
-

sw_tidy_decomp -

-

sw_tidy_decomp() returns the decomposition of the ETS -model.

-
-decomp_fit_ets <- sw_tidy_decomp(fit_ets)
-decomp_fit_ets 
-
## # A tibble: 121 × 5
-##    index     observed level slope season
-##    <yearmon>    <dbl> <dbl> <dbl>  <dbl>
-##  1 Dec 2006        NA 8389.  38.9  1.17 
-##  2 Jan 2007      6627 8464.  42.0  0.765
-##  3 Feb 2007      6743 8433.  32.6  0.837
-##  4 Mar 2007      8195 8455.  30.5  0.975
-##  5 Apr 2007      7828 8404.  20.4  0.982
-##  6 May 2007      9570 8510.  29.6  1.07 
-##  7 Jun 2007      9484 8531.  27.8  1.12 
-##  8 Jul 2007      8608 8575.  29.0  0.993
-##  9 Aug 2007      9543 8697.  38.7  1.04 
-## 10 Sep 2007      8123 8643.  27.2  0.995
-## # ℹ 111 more rows
-

We can review the decomposition using ggplot2 as well. -The data will need to be manipulated slightly for the facet -visualization. The gather() function from the -tidyr package is used to reshape the data into a long -format data frame with column names “key” and “value” indicating all -columns except for index are to be reshaped. The “key” column is then -mutated using mutate() to a factor which preserves the -order of the keys so “observed” comes first when plotting.

-
-decomp_fit_ets %>%
-    tidyr::gather(key = key, value = value, -index) %>%
-    dplyr::mutate(key = as.factor(key)) %>%
-    ggplot(aes(x = index, y = value, group = key)) +
-    geom_line(color = palette_light()[[2]]) +
-    geom_ma(ma_fun = SMA, n = 12, size = 1) +
-    facet_wrap(~ key, scales = "free_y") +
-    scale_x_yearmon(n = 10) +
-    labs(title = "US Alcohol Sales: ETS Decomposition", x = "") + 
-    theme_tq() +
-    theme(axis.text.x = element_text(angle = 45, hjust = 1))
-
## Warning: Using the `size` aesthetic in this geom was deprecated in ggplot2 3.4.0.
-##  Please use `linewidth` in the `default_aes` field and elsewhere instead.
-## This warning is displayed once every 8 hours.
-## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
-## generated.
-
## Warning: Removed 1 row containing missing values (`geom_line()`).
-

-

Under normal circumstances it would make sense to refine the model at -this point. However, in the interest of showing capabilities (rather -than how to forecast) we move onto forecasting the model. For more -information on how to forecast, please refer to the online book “Forecasting: principles and -practices”.

-
-
-
-

Step 3: Forecasting the model -

-

Next we forecast the ETS model using the forecast() -function. The returned forecast object isn’t in a “tidy” -format (i.e. data frame). This is where the sw_sweep() -function helps.

-
-fcast_ets <- fit_ets %>%
-    forecast(h = 12) 
-
-
-

Step 4: Tidy the forecast object -

-

We’ll use the sw_sweep() function to coerce a -forecast into a “tidy” data frame. The -sw_sweep() function then coerces the forecast -object into a tibble that can be sent to ggplot for -visualization. Let’s inspect the result.

-
-sw_sweep(fcast_ets, fitted = TRUE)
-
## # A tibble: 252 × 7
-##    index     key    price lo.80 lo.95 hi.80 hi.95
-##    <yearmon> <chr>  <dbl> <dbl> <dbl> <dbl> <dbl>
-##  1 Jan 2007  actual  6627    NA    NA    NA    NA
-##  2 Feb 2007  actual  6743    NA    NA    NA    NA
-##  3 Mar 2007  actual  8195    NA    NA    NA    NA
-##  4 Apr 2007  actual  7828    NA    NA    NA    NA
-##  5 May 2007  actual  9570    NA    NA    NA    NA
-##  6 Jun 2007  actual  9484    NA    NA    NA    NA
-##  7 Jul 2007  actual  8608    NA    NA    NA    NA
-##  8 Aug 2007  actual  9543    NA    NA    NA    NA
-##  9 Sep 2007  actual  8123    NA    NA    NA    NA
-## 10 Oct 2007  actual  9649    NA    NA    NA    NA
-## # ℹ 242 more rows
-

The tibble returned contains “index”, “key” and “value” (or in this -case “price”) columns in a long or “tidy” format that is ideal for -visualization with ggplot2. The “index” is in a regularized -format (in this case yearmon) because the -forecast package uses ts objects. We’ll see -how we can get back to the original irregularized format (in this case -date) later. The “key” and “price” columns contains three -groups of key-value pairs:

-
    -
  1. -actual: the actual values from the original -data
  2. -
  3. -fitted: the model values returned from the -ets() function (excluded by default)
  4. -
  5. -forecast: the predicted values from the -forecast() function
  6. -
-

The sw_sweep() function contains an argument -fitted = FALSE by default meaning that the model “fitted” -values are not returned. We can toggle this on if desired. The remaining -columns are the forecast confidence intervals (typically 80 and 95, but -this can be changed with forecast(level = c(80, 95))). -These columns are setup in a wide format to enable using the -geom_ribbon().

-

Let’s visualize the forecast with ggplot2. We’ll use a -combination of geom_line() and geom_ribbon(). -The fitted values are toggled off by default to reduce the complexity of -the plot, but these can be added if desired. Note that because we are -using a regular time index of the yearmon class, we need to -add scale_x_yearmon().

-
-sw_sweep(fcast_ets) %>%
-    ggplot(aes(x = index, y = price, color = key)) +
-    geom_ribbon(aes(ymin = lo.95, ymax = hi.95), 
-                fill = "#D5DBFF", color = NA, linewidth = 0) +
-    geom_ribbon(aes(ymin = lo.80, ymax = hi.80, fill = key), 
-                fill = "#596DD5", color = NA, linewidth = 0, alpha = 0.8) +
-    geom_line(linewidth = 1) +
-    labs(title = "US Alcohol Sales, ETS Model Forecast", x = "", y = "Millions",
-         subtitle = "Regular Time Index") +
-    scale_y_continuous(labels = scales::label_dollar()) +
-    scale_x_yearmon(n = 12, format = "%Y") +
-    scale_color_tq() +
-    scale_fill_tq() +
-    theme_tq() 
-

-

Because the ts object was created with the -tk_ts() function, it contained a timetk index that was -carried with it throughout the forecasting workflow. As a result, we can -use the timetk_idx argument, which maps the original -irregular index (dates) and a generated future index to the regularized -time series (yearmon). This results in the ability to return an index of -date and datetime, which is not currently possible with the -forecast objects. Notice that the index is returned as -date class.

-
-sw_sweep(fcast_ets, timetk_idx = TRUE) %>%
-    head()
-
## Warning in .check_tzones(e1, e2): 'tzone' attributes are inconsistent
-
## # A tibble: 6 × 7
-##   index      key    price lo.80 lo.95 hi.80 hi.95
-##   <date>     <chr>  <dbl> <dbl> <dbl> <dbl> <dbl>
-## 1 2007-01-01 actual  6627    NA    NA    NA    NA
-## 2 2007-02-01 actual  6743    NA    NA    NA    NA
-## 3 2007-03-01 actual  8195    NA    NA    NA    NA
-## 4 2007-04-01 actual  7828    NA    NA    NA    NA
-## 5 2007-05-01 actual  9570    NA    NA    NA    NA
-## 6 2007-06-01 actual  9484    NA    NA    NA    NA
-
-sw_sweep(fcast_ets, timetk_idx = TRUE) %>%
-    tail()
-
## Warning in .check_tzones(e1, e2): 'tzone' attributes are inconsistent
-
## # A tibble: 6 × 7
-##   index      key       price  lo.80  lo.95  hi.80  hi.95
-##   <date>     <chr>     <dbl>  <dbl>  <dbl>  <dbl>  <dbl>
-## 1 2017-07-01 forecast 12117. 11309. 10882. 12924. 13351.
-## 2 2017-08-01 forecast 12697. 11828. 11367. 13566. 14027.
-## 3 2017-09-01 forecast 12203. 11343. 10888. 13063. 13518.
-## 4 2017-10-01 forecast 12723. 11800. 11311. 13647. 14136.
-## 5 2017-11-01 forecast 12559. 11619. 11122. 13499. 13996.
-## 6 2017-12-01 forecast 14499. 13380. 12788. 15618. 16211.
-

We can build the same plot with dates in the x-axis now.

-
-sw_sweep(fcast_ets, timetk_idx = TRUE) %>%
-    ggplot(aes(x = index, y = price, color = key)) +
-    geom_ribbon(aes(ymin = lo.95, ymax = hi.95), 
-                fill = "#D5DBFF", color = NA, linewidth = 0) +
-    geom_ribbon(aes(ymin = lo.80, ymax = hi.80, fill = key), 
-                fill = "#596DD5", color = NA, linewidth = 0, alpha = 0.8) +
-    geom_line(linewidth = 1) +
-    labs(title = "US Alcohol Sales, ETS Model Forecast", x = "", y = "Millions", 
-         subtitle = "Irregular Time Index") +
-    scale_y_continuous(labels = scales::dollar) +
-    scale_x_date(date_breaks = "1 year", date_labels = "%Y") +
-    scale_color_tq() +
-    scale_fill_tq() +
-    theme_tq() 
-
## Warning in .check_tzones(e1, e2): 'tzone' attributes are inconsistent
-

-

In this example, there is not much benefit to returning an irregular -time series. However, when working with frequencies below monthly, the -ability to return irregular index values becomes more apparent.

-
-
-
-

Recap -

-

This was an overview of how various functions within the -sweep package can be used to assist in forecast analysis. -In the next vignette, we discuss some more powerful concepts including -forecasting at scale with grouped time series analysis.

-
-
-
- - - - -
- - - - - - - diff --git a/docs/articles/SW00_Introduction_to_sweep_files/accessible-code-block-0.0.1/empty-anchor.js b/docs/articles/SW00_Introduction_to_sweep_files/accessible-code-block-0.0.1/empty-anchor.js deleted file mode 100644 index ca349fd..0000000 --- a/docs/articles/SW00_Introduction_to_sweep_files/accessible-code-block-0.0.1/empty-anchor.js +++ /dev/null @@ -1,15 +0,0 @@ -// Hide empty tag within highlighted CodeBlock for screen reader accessibility (see https://github.com/jgm/pandoc/issues/6352#issuecomment-626106786) --> -// v0.0.1 -// Written by JooYoung Seo (jooyoung@psu.edu) and Atsushi Yasumoto on June 1st, 2020. - -document.addEventListener('DOMContentLoaded', function() { - const codeList = document.getElementsByClassName("sourceCode"); - for (var i = 0; i < codeList.length; i++) { - var linkList = codeList[i].getElementsByTagName('a'); - for (var j = 0; j < linkList.length; j++) { - if (linkList[j].innerHTML === "") { - linkList[j].setAttribute('aria-hidden', 'true'); - } - } - } -}); diff --git a/docs/articles/SW00_Introduction_to_sweep_files/figure-html/unnamed-chunk-12-1.png b/docs/articles/SW00_Introduction_to_sweep_files/figure-html/unnamed-chunk-12-1.png deleted file mode 100644 index d7d6835..0000000 Binary files a/docs/articles/SW00_Introduction_to_sweep_files/figure-html/unnamed-chunk-12-1.png and /dev/null differ diff --git a/docs/articles/SW00_Introduction_to_sweep_files/figure-html/unnamed-chunk-14-1.png b/docs/articles/SW00_Introduction_to_sweep_files/figure-html/unnamed-chunk-14-1.png deleted file mode 100644 index e7619a6..0000000 Binary files a/docs/articles/SW00_Introduction_to_sweep_files/figure-html/unnamed-chunk-14-1.png and /dev/null differ diff --git a/docs/articles/SW00_Introduction_to_sweep_files/figure-html/unnamed-chunk-17-1.png b/docs/articles/SW00_Introduction_to_sweep_files/figure-html/unnamed-chunk-17-1.png deleted file mode 100644 index 1ccf56b..0000000 Binary files a/docs/articles/SW00_Introduction_to_sweep_files/figure-html/unnamed-chunk-17-1.png and /dev/null differ diff --git a/docs/articles/SW00_Introduction_to_sweep_files/figure-html/unnamed-chunk-20-1.png b/docs/articles/SW00_Introduction_to_sweep_files/figure-html/unnamed-chunk-20-1.png deleted file mode 100644 index 69a3935..0000000 Binary files a/docs/articles/SW00_Introduction_to_sweep_files/figure-html/unnamed-chunk-20-1.png and /dev/null differ diff --git a/docs/articles/SW00_Introduction_to_sweep_files/figure-html/unnamed-chunk-4-1.png b/docs/articles/SW00_Introduction_to_sweep_files/figure-html/unnamed-chunk-4-1.png deleted file mode 100644 index 3a6e4d4..0000000 Binary files a/docs/articles/SW00_Introduction_to_sweep_files/figure-html/unnamed-chunk-4-1.png and /dev/null differ diff --git a/docs/articles/SW00_Introduction_to_sweep_files/header-attrs-2.1/header-attrs.js b/docs/articles/SW00_Introduction_to_sweep_files/header-attrs-2.1/header-attrs.js deleted file mode 100644 index dd57d92..0000000 --- a/docs/articles/SW00_Introduction_to_sweep_files/header-attrs-2.1/header-attrs.js +++ /dev/null @@ -1,12 +0,0 @@ -// Pandoc 2.9 adds attributes on both header and div. We remove the former (to -// be compatible with the behavior of Pandoc < 2.8). -document.addEventListener('DOMContentLoaded', function(e) { - var hs = document.querySelectorAll("div.section[class*='level'] > :first-child"); - var i, h, a; - for (i = 0; i < hs.length; i++) { - h = hs[i]; - if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6 - a = h.attributes; - while (a.length > 0) h.removeAttribute(a[0].name); - } -}); diff --git a/docs/articles/SW00_Introduction_to_sweep_files/header-attrs-2.3/header-attrs.js b/docs/articles/SW00_Introduction_to_sweep_files/header-attrs-2.3/header-attrs.js deleted file mode 100644 index dd57d92..0000000 --- a/docs/articles/SW00_Introduction_to_sweep_files/header-attrs-2.3/header-attrs.js +++ /dev/null @@ -1,12 +0,0 @@ -// Pandoc 2.9 adds attributes on both header and div. We remove the former (to -// be compatible with the behavior of Pandoc < 2.8). -document.addEventListener('DOMContentLoaded', function(e) { - var hs = document.querySelectorAll("div.section[class*='level'] > :first-child"); - var i, h, a; - for (i = 0; i < hs.length; i++) { - h = hs[i]; - if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6 - a = h.attributes; - while (a.length > 0) h.removeAttribute(a[0].name); - } -}); diff --git a/docs/articles/SW01_Forecasting_Time_Series_Groups.html b/docs/articles/SW01_Forecasting_Time_Series_Groups.html deleted file mode 100644 index f93a90a..0000000 --- a/docs/articles/SW01_Forecasting_Time_Series_Groups.html +++ /dev/null @@ -1,622 +0,0 @@ - - - - - - - - -Forecasting Time Series Groups in the tidyverse • sweep - - - - - - - - - - - - - - - - - - Skip to contents - - -
- - - - -
-
- - - -
-

Extending broom to time series forecasting

-
-

One of the most powerful benefits of sweep is that it -helps forecasting at scale within the “tidyverse”. There are two common -situations:

-
    -
  1. Applying a model to groups of time series
  2. -
  3. Applying multiple models to a time series
  4. -
-

In this vignette we’ll review how sweep can help the -first situation: Applying a model to groups of time -series.

-
-

Prerequisites -

-

Before we get started, load the following packages.

- -
-
-

Bike Sales -

-

We’ll use the bike sales data set, bike_sales, provided -with the sweep package for this tutorial. The -bike_sales data set is a fictional daily order -history that spans 2011 through 2015. It simulates a sales database that -is typical of a business. The customers are the “bike shops” and the -products are the “models”.

-
-bike_sales
-
## # A tibble: 15,644 × 17
-##    order.date order.id order.line quantity price price.ext customer.id
-##    <date>        <dbl>      <int>    <dbl> <dbl>     <dbl>       <dbl>
-##  1 2011-01-07        1          1        1  6070      6070           2
-##  2 2011-01-07        1          2        1  5970      5970           2
-##  3 2011-01-10        2          1        1  2770      2770          10
-##  4 2011-01-10        2          2        1  5970      5970          10
-##  5 2011-01-10        3          1        1 10660     10660           6
-##  6 2011-01-10        3          2        1  3200      3200           6
-##  7 2011-01-10        3          3        1 12790     12790           6
-##  8 2011-01-10        3          4        1  5330      5330           6
-##  9 2011-01-10        3          5        1  1570      1570           6
-## 10 2011-01-11        4          1        1  4800      4800          22
-## # ℹ 15,634 more rows
-## # ℹ 10 more variables: bikeshop.name <chr>, bikeshop.city <chr>,
-## #   bikeshop.state <chr>, latitude <dbl>, longitude <dbl>, product.id <dbl>,
-## #   model <chr>, category.primary <chr>, category.secondary <chr>, frame <chr>
-

We’ll analyse the monthly sales trends for the bicycle manufacturer. -Let’s transform the data set by aggregating by month.

-
-bike_sales_monthly <- bike_sales %>%
-    mutate(month = month(order.date, label = TRUE),
-           year  = year(order.date)) %>%
-    group_by(year, month) %>%
-    summarise(total.qty = sum(quantity)) 
-
## `summarise()` has grouped output by 'year'. You can override using the
-## `.groups` argument.
-
-bike_sales_monthly
-
## # A tibble: 60 × 3
-## # Groups:   year [5]
-##     year month total.qty
-##    <dbl> <ord>     <dbl>
-##  1  2011 Jan         440
-##  2  2011 Feb        2017
-##  3  2011 Mar        1584
-##  4  2011 Apr        4478
-##  5  2011 May        4112
-##  6  2011 Jun        4251
-##  7  2011 Jul        1550
-##  8  2011 Aug        1470
-##  9  2011 Sep         975
-## 10  2011 Oct         697
-## # ℹ 50 more rows
-

We can visualize package with a month plot using the -ggplot2 .

-
-bike_sales_monthly %>%
-    ggplot(aes(x = month, y = total.qty, group = year)) +
-    geom_area(aes(fill = year), position = "stack") +
-    labs(title = "Quantity Sold: Month Plot", x = "", y = "Sales",
-         subtitle = "March through July tend to be most active") +
-    scale_y_continuous() +
-    theme_tq()
-

-

Suppose Manufacturing wants a more granular forecast because the bike -components are related to the secondary category. In the next section we -discuss how sweep can help to perform a forecast on each -sub-category.

-
-
-

Performing Forecasts on Groups -

-

First, we need to get the data organized into groups by month of the -year. We’ll create a new “order.month” date using -zoo::as.yearmon() that captures the year and month -information from the “order.date” and then passing this to -lubridate::as_date() to convert to date format.

-
-monthly_qty_by_cat2 <- bike_sales %>%
-    mutate(order.month = as_date(as.yearmon(order.date))) %>%
-    group_by(category.secondary, order.month) %>%
-    summarise(total.qty = sum(quantity))
-
## `summarise()` has grouped output by 'category.secondary'. You can override
-## using the `.groups` argument.
-
-monthly_qty_by_cat2
-
## # A tibble: 538 × 3
-## # Groups:   category.secondary [9]
-##    category.secondary order.month total.qty
-##    <chr>              <date>          <dbl>
-##  1 Cross Country Race 2011-01-01        122
-##  2 Cross Country Race 2011-02-01        489
-##  3 Cross Country Race 2011-03-01        505
-##  4 Cross Country Race 2011-04-01        343
-##  5 Cross Country Race 2011-05-01        263
-##  6 Cross Country Race 2011-06-01        735
-##  7 Cross Country Race 2011-07-01        183
-##  8 Cross Country Race 2011-08-01         66
-##  9 Cross Country Race 2011-09-01         97
-## 10 Cross Country Race 2011-10-01        189
-## # ℹ 528 more rows
-

Next, we use the nest() function from the -tidyr package to consolidate each time series by group. The -newly created list-column, “data.tbl”, contains the “order.month” and -“total.qty” columns by group from the previous step. The -nest() function just bundles the data together which is -very useful for iterative functional programming.

-
-monthly_qty_by_cat2_nest <- monthly_qty_by_cat2 %>%
-    group_by(category.secondary) %>%
-    nest()
-monthly_qty_by_cat2_nest
-
## # A tibble: 9 × 2
-## # Groups:   category.secondary [9]
-##   category.secondary data             
-##   <chr>              <list>           
-## 1 Cross Country Race <tibble [60 × 2]>
-## 2 Cyclocross         <tibble [60 × 2]>
-## 3 Elite Road         <tibble [60 × 2]>
-## 4 Endurance Road     <tibble [60 × 2]>
-## 5 Fat Bike           <tibble [58 × 2]>
-## 6 Over Mountain      <tibble [60 × 2]>
-## 7 Sport              <tibble [60 × 2]>
-## 8 Trail              <tibble [60 × 2]>
-## 9 Triathalon         <tibble [60 × 2]>
-
-

Forecasting Workflow -

-

The forecasting workflow involves a few basic steps:

-
    -
  1. Step 1: Coerce to a ts object class.
  2. -
  3. Step 2: Apply a model (or set of models)
  4. -
  5. Step 3: Forecast the models (similar to predict)
  6. -
  7. Step 4: Tidy the forecast
  8. -
-
-
-

Step 1: Coerce to a ts object class -

-

In this step we map the tk_ts() function into a new -column “data.ts”. The procedure is performed using the combination of -dplyr::mutate() and purrr::map(), which works -really well for the data science workflow where analyses are built -progressively. As a result, this combination will be used in many of the -subsequent steps in this vignette as we build the analysis.

-
-

mutate and map -

-

The mutate() function adds a column, and the -map() function maps the contents of a list-column -(.x) to a function (.f). In our case, -.x = data.tbl and .f = tk_ts. The arguments -select = -order.month, start = 2011, and -freq = 12 are passed to the ... parameters in -map, which are passed through to the function. The select -statement is used to drop the “order.month” from the final output so we -don’t get a bunch of warning messages. We specify -start = 2011 and freq = 12 to return a monthly -frequency.

-
-monthly_qty_by_cat2_ts <- monthly_qty_by_cat2_nest %>%
-    mutate(data.ts = map(.x       = data, 
-                         .f       = tk_ts, 
-                         select   = -order.month, 
-                         start    = 2011,
-                         freq     = 12))
-monthly_qty_by_cat2_ts
-
## # A tibble: 9 × 3
-## # Groups:   category.secondary [9]
-##   category.secondary data              data.ts      
-##   <chr>              <list>            <list>       
-## 1 Cross Country Race <tibble [60 × 2]> <ts [60 × 1]>
-## 2 Cyclocross         <tibble [60 × 2]> <ts [60 × 1]>
-## 3 Elite Road         <tibble [60 × 2]> <ts [60 × 1]>
-## 4 Endurance Road     <tibble [60 × 2]> <ts [60 × 1]>
-## 5 Fat Bike           <tibble [58 × 2]> <ts [58 × 1]>
-## 6 Over Mountain      <tibble [60 × 2]> <ts [60 × 1]>
-## 7 Sport              <tibble [60 × 2]> <ts [60 × 1]>
-## 8 Trail              <tibble [60 × 2]> <ts [60 × 1]>
-## 9 Triathalon         <tibble [60 × 2]> <ts [60 × 1]>
-
-
-
-

Step 2: Modeling a time series -

-

Next, we map the Exponential Smoothing ETS (Error, Trend, Seasonal) -model function, ets, from the forecast -package. Use the combination of mutate to add a column and -map to interatively apply a function rowwise to a -list-column. In this instance, the function to map the ets -function and the list-column is “data.ts”. We rename the resultant -column “fit.ets” indicating an ETS model was fit to the time series -data.

-
-monthly_qty_by_cat2_fit <- monthly_qty_by_cat2_ts %>%
-    mutate(fit.ets = map(data.ts, ets))
-monthly_qty_by_cat2_fit
-
## # A tibble: 9 × 4
-## # Groups:   category.secondary [9]
-##   category.secondary data              data.ts       fit.ets
-##   <chr>              <list>            <list>        <list> 
-## 1 Cross Country Race <tibble [60 × 2]> <ts [60 × 1]> <ets>  
-## 2 Cyclocross         <tibble [60 × 2]> <ts [60 × 1]> <ets>  
-## 3 Elite Road         <tibble [60 × 2]> <ts [60 × 1]> <ets>  
-## 4 Endurance Road     <tibble [60 × 2]> <ts [60 × 1]> <ets>  
-## 5 Fat Bike           <tibble [58 × 2]> <ts [58 × 1]> <ets>  
-## 6 Over Mountain      <tibble [60 × 2]> <ts [60 × 1]> <ets>  
-## 7 Sport              <tibble [60 × 2]> <ts [60 × 1]> <ets>  
-## 8 Trail              <tibble [60 × 2]> <ts [60 × 1]> <ets>  
-## 9 Triathalon         <tibble [60 × 2]> <ts [60 × 1]> <ets>
-

At this point, we can do some model inspection with the -sweep tidiers.

-
-

sw_tidy -

-

To get the model parameters for each nested list, we can combine -sw_tidy within the mutate and map -combo. The only real difference is now we unnest the -generated column (named “tidy”). Last, because it’s easier to compare -the model parameters side by side, we add one additional call to -spread() from the tidyr package.

-
-monthly_qty_by_cat2_fit %>%
-    mutate(tidy = map(fit.ets, sw_tidy)) %>%
-    unnest(tidy) %>%
-    spread(key = category.secondary, value = estimate)
-
## # A tibble: 128 × 13
-##    data     data.ts fit.ets term  `Cross Country Race` Cyclocross `Elite Road`
-##    <list>   <list>  <list>  <chr>                <dbl>      <dbl>        <dbl>
-##  1 <tibble> <ts[…]> <ets>   alpha             0.0398           NA           NA
-##  2 <tibble> <ts[…]> <ets>   gamma             0.000101         NA           NA
-##  3 <tibble> <ts[…]> <ets>   l               321.               NA           NA
-##  4 <tibble> <ts[…]> <ets>   s0                0.503            NA           NA
-##  5 <tibble> <ts[…]> <ets>   s1                1.10             NA           NA
-##  6 <tibble> <ts[…]> <ets>   s10               0.643            NA           NA
-##  7 <tibble> <ts[…]> <ets>   s2                0.375            NA           NA
-##  8 <tibble> <ts[…]> <ets>   s3                1.12             NA           NA
-##  9 <tibble> <ts[…]> <ets>   s4                0.630            NA           NA
-## 10 <tibble> <ts[…]> <ets>   s5                2.06             NA           NA
-## # ℹ 118 more rows
-## # ℹ 6 more variables: `Endurance Road` <dbl>, `Fat Bike` <dbl>,
-## #   `Over Mountain` <dbl>, Sport <dbl>, Trail <dbl>, Triathalon <dbl>
-
-
-

sw_glance -

-

We can view the model accuracies also by mapping -sw_glance within the mutate and -map combo.

-
-monthly_qty_by_cat2_fit %>%
-    mutate(glance = map(fit.ets, sw_glance)) %>%
-    unnest(glance)
-
## # A tibble: 9 × 16
-## # Groups:   category.secondary [9]
-##   category.secondary data     data.ts fit.ets model.desc sigma logLik   AIC
-##   <chr>              <list>   <list>  <list>  <chr>      <dbl>  <dbl> <dbl>
-## 1 Cross Country Race <tibble> <ts[…]> <ets>   ETS(M,N,M) 1.06   -464.  957.
-## 2 Cyclocross         <tibble> <ts[…]> <ets>   ETS(M,N,M) 1.12   -409.  848.
-## 3 Elite Road         <tibble> <ts[…]> <ets>   ETS(M,N,M) 0.895  -471.  972.
-## 4 Endurance Road     <tibble> <ts[…]> <ets>   ETS(M,N,M) 0.759  -439.  909.
-## 5 Fat Bike           <tibble> <ts[…]> <ets>   ETS(M,N,M) 2.73   -343.  715.
-## 6 Over Mountain      <tibble> <ts[…]> <ets>   ETS(M,N,M) 0.910  -423.  877.
-## 7 Sport              <tibble> <ts[…]> <ets>   ETS(M,N,M) 0.872  -427.  884.
-## 8 Trail              <tibble> <ts[…]> <ets>   ETS(M,A,M) 0.741  -411.  855.
-## 9 Triathalon         <tibble> <ts[…]> <ets>   ETS(M,N,M) 1.52   -410.  850.
-## # ℹ 8 more variables: BIC <dbl>, ME <dbl>, RMSE <dbl>, MAE <dbl>, MPE <dbl>,
-## #   MAPE <dbl>, MASE <dbl>, ACF1 <dbl>
-
-
-

sw_augment -

-

The augmented fitted and residual values can be achieved in much the -same manner. This returns nine groups data. Note that we pass -timetk_idx = TRUE to return the date format times as -opposed to the regular (yearmon or numeric) time series.

-
-augment_fit_ets <- monthly_qty_by_cat2_fit %>%
-    mutate(augment = map(fit.ets, sw_augment, timetk_idx = TRUE, rename_index = "date")) %>%
-    unnest(augment)
-
## Warning: There were 9 warnings in `mutate()`.
-## The first warning was:
-##  In argument: `augment = map(fit.ets, sw_augment, timetk_idx = TRUE,
-##   rename_index = "date")`.
-##  In group 1: `category.secondary = "Cross Country Race"`.
-## Caused by warning in `.check_tzones()`:
-## ! 'tzone' attributes are inconsistent
-##  Run `dplyr::last_dplyr_warnings()` to see the 8 remaining warnings.
-
-augment_fit_ets
-
## # A tibble: 538 × 8
-## # Groups:   category.secondary [9]
-##    category.secondary data     data.ts       fit.ets date       .actual .fitted
-##    <chr>              <list>   <list>        <list>  <date>       <dbl>   <dbl>
-##  1 Cross Country Race <tibble> <ts [60 × 1]> <ets>   2011-01-01     122    373.
-##  2 Cross Country Race <tibble> <ts [60 × 1]> <ets>   2011-02-01     489    201.
-##  3 Cross Country Race <tibble> <ts [60 × 1]> <ets>   2011-03-01     505    465.
-##  4 Cross Country Race <tibble> <ts [60 × 1]> <ets>   2011-04-01     343    161.
-##  5 Cross Country Race <tibble> <ts [60 × 1]> <ets>   2011-05-01     263    567.
-##  6 Cross Country Race <tibble> <ts [60 × 1]> <ets>   2011-06-01     735    296.
-##  7 Cross Country Race <tibble> <ts [60 × 1]> <ets>   2011-07-01     183    741.
-##  8 Cross Country Race <tibble> <ts [60 × 1]> <ets>   2011-08-01      66    220.
-##  9 Cross Country Race <tibble> <ts [60 × 1]> <ets>   2011-09-01      97    381.
-## 10 Cross Country Race <tibble> <ts [60 × 1]> <ets>   2011-10-01     189    123.
-## # ℹ 528 more rows
-## # ℹ 1 more variable: .resid <dbl>
-

We can plot the residuals for the nine categories like so. -Unfortunately we do see some very high residuals (especially with “Fat -Bike”). This is often the case with realworld data.

-
-augment_fit_ets %>%
-    ggplot(aes(x = date, y = .resid, group = category.secondary)) +
-    geom_hline(yintercept = 0, color = "grey40") +
-    geom_line(color = palette_light()[[2]]) +
-    geom_smooth(method = "loess") +
-    labs(title = "Bike Quantity Sold By Secondary Category",
-         subtitle = "ETS Model Residuals", x = "") + 
-    theme_tq() +
-    facet_wrap(~ category.secondary, scale = "free_y", ncol = 3) +
-    scale_x_date(date_labels = "%Y")
-
## `geom_smooth()` using formula = 'y ~ x'
-

-
-
-

sw_tidy_decomp -

-

We can create decompositions using the same procedure with -sw_tidy_decomp() and the mutate and -map combo.

-
-monthly_qty_by_cat2_fit %>%
-    mutate(decomp = map(fit.ets, sw_tidy_decomp, timetk_idx = TRUE, rename_index = "date")) %>%
-    unnest(decomp)
-
## Warning: There were 9 warnings in `mutate()`.
-## The first warning was:
-##  In argument: `decomp = map(fit.ets, sw_tidy_decomp, timetk_idx = TRUE,
-##   rename_index = "date")`.
-##  In group 1: `category.secondary = "Cross Country Race"`.
-## Caused by warning in `.check_tzones()`:
-## ! 'tzone' attributes are inconsistent
-##  Run `dplyr::last_dplyr_warnings()` to see the 8 remaining warnings.
-
## # A tibble: 538 × 9
-## # Groups:   category.secondary [9]
-##    category.secondary data     data.ts fit.ets date       observed level season
-##    <chr>              <list>   <list>  <list>  <date>        <dbl> <dbl>  <dbl>
-##  1 Cross Country Race <tibble> <ts[…]> <ets>   2011-01-01      122  313.  1.16 
-##  2 Cross Country Race <tibble> <ts[…]> <ets>   2011-02-01      489  331.  0.643
-##  3 Cross Country Race <tibble> <ts[…]> <ets>   2011-03-01      505  332.  1.41 
-##  4 Cross Country Race <tibble> <ts[…]> <ets>   2011-04-01      343  347.  0.487
-##  5 Cross Country Race <tibble> <ts[…]> <ets>   2011-05-01      263  339.  1.64 
-##  6 Cross Country Race <tibble> <ts[…]> <ets>   2011-06-01      735  359.  0.873
-##  7 Cross Country Race <tibble> <ts[…]> <ets>   2011-07-01      183  348.  2.06 
-##  8 Cross Country Race <tibble> <ts[…]> <ets>   2011-08-01       66  339.  0.630
-##  9 Cross Country Race <tibble> <ts[…]> <ets>   2011-09-01       97  329.  1.12 
-## 10 Cross Country Race <tibble> <ts[…]> <ets>   2011-10-01      189  336.  0.375
-## # ℹ 528 more rows
-## # ℹ 1 more variable: slope <dbl>
-
-
-
-

Step 3: Forecasting the model -

-

We can also forecast the multiple models again using a very similar -approach with the forecast function. We want a 12 month -forecast so we add the argument for the h = 12 (refer to -?forecast for all of the parameters you can add, there’s -quite a few).

-
-monthly_qty_by_cat2_fcast <- monthly_qty_by_cat2_fit %>%
-    mutate(fcast.ets = map(fit.ets, forecast, h = 12))
-monthly_qty_by_cat2_fcast
-
## # A tibble: 9 × 5
-## # Groups:   category.secondary [9]
-##   category.secondary data              data.ts       fit.ets fcast.ets 
-##   <chr>              <list>            <list>        <list>  <list>    
-## 1 Cross Country Race <tibble [60 × 2]> <ts [60 × 1]> <ets>   <forecast>
-## 2 Cyclocross         <tibble [60 × 2]> <ts [60 × 1]> <ets>   <forecast>
-## 3 Elite Road         <tibble [60 × 2]> <ts [60 × 1]> <ets>   <forecast>
-## 4 Endurance Road     <tibble [60 × 2]> <ts [60 × 1]> <ets>   <forecast>
-## 5 Fat Bike           <tibble [58 × 2]> <ts [58 × 1]> <ets>   <forecast>
-## 6 Over Mountain      <tibble [60 × 2]> <ts [60 × 1]> <ets>   <forecast>
-## 7 Sport              <tibble [60 × 2]> <ts [60 × 1]> <ets>   <forecast>
-## 8 Trail              <tibble [60 × 2]> <ts [60 × 1]> <ets>   <forecast>
-## 9 Triathalon         <tibble [60 × 2]> <ts [60 × 1]> <ets>   <forecast>
-
-
-

Step 4: Tidy the forecast -

-

Next, we can apply sw_sweep to get the forecast in a -nice “tidy” data frame. We use the argument fitted = FALSE -to remove the fitted values from the forecast (leave off if fitted -values are desired). We set timetk_idx = TRUE to use dates -instead of numeric values for the index. We’ll use unnest() -to drop the left over list-columns and return an unnested data -frame.

-
-monthly_qty_by_cat2_fcast_tidy <- monthly_qty_by_cat2_fcast %>%
-    mutate(sweep = map(fcast.ets, sw_sweep, fitted = FALSE, timetk_idx = TRUE)) %>%
-    unnest(sweep)
-
## Warning: There were 9 warnings in `mutate()`.
-## The first warning was:
-##  In argument: `sweep = map(fcast.ets, sw_sweep, fitted = FALSE, timetk_idx =
-##   TRUE)`.
-##  In group 1: `category.secondary = "Cross Country Race"`.
-## Caused by warning in `.check_tzones()`:
-## ! 'tzone' attributes are inconsistent
-##  Run `dplyr::last_dplyr_warnings()` to see the 8 remaining warnings.
-
-monthly_qty_by_cat2_fcast_tidy
-
## # A tibble: 646 × 12
-## # Groups:   category.secondary [9]
-##    category.secondary data     data.ts       fit.ets fcast.ets  index      key  
-##    <chr>              <list>   <list>        <list>  <list>     <date>     <chr>
-##  1 Cross Country Race <tibble> <ts [60 × 1]> <ets>   <forecast> 2011-01-01 actu…
-##  2 Cross Country Race <tibble> <ts [60 × 1]> <ets>   <forecast> 2011-02-01 actu…
-##  3 Cross Country Race <tibble> <ts [60 × 1]> <ets>   <forecast> 2011-03-01 actu…
-##  4 Cross Country Race <tibble> <ts [60 × 1]> <ets>   <forecast> 2011-04-01 actu…
-##  5 Cross Country Race <tibble> <ts [60 × 1]> <ets>   <forecast> 2011-05-01 actu…
-##  6 Cross Country Race <tibble> <ts [60 × 1]> <ets>   <forecast> 2011-06-01 actu…
-##  7 Cross Country Race <tibble> <ts [60 × 1]> <ets>   <forecast> 2011-07-01 actu…
-##  8 Cross Country Race <tibble> <ts [60 × 1]> <ets>   <forecast> 2011-08-01 actu…
-##  9 Cross Country Race <tibble> <ts [60 × 1]> <ets>   <forecast> 2011-09-01 actu…
-## 10 Cross Country Race <tibble> <ts [60 × 1]> <ets>   <forecast> 2011-10-01 actu…
-## # ℹ 636 more rows
-## # ℹ 5 more variables: total.qty <dbl>, lo.80 <dbl>, lo.95 <dbl>, hi.80 <dbl>,
-## #   hi.95 <dbl>
-

Visualization is just one final step.

-
-monthly_qty_by_cat2_fcast_tidy %>%
-    ggplot(aes(x = index, y = total.qty, color = key, group = category.secondary)) +
-    geom_ribbon(aes(ymin = lo.95, ymax = hi.95), 
-                fill = "#D5DBFF", color = NA, linewidth = 0) +
-    geom_ribbon(aes(ymin = lo.80, ymax = hi.80, fill = key), 
-                fill = "#596DD5", color = NA, linewidth = 0, alpha = 0.8) +
-    geom_line() +
-    labs(title = "Bike Quantity Sold By Secondary Category",
-         subtitle = "ETS Model Forecasts",
-         x = "", y = "Units") +
-    scale_x_date(date_breaks = "1 year", date_labels = "%Y") +
-    scale_color_tq() +
-    scale_fill_tq() +
-    facet_wrap(~ category.secondary, scales = "free_y", ncol = 3) +
-    theme_tq() +
-    theme(axis.text.x = element_text(angle = 45, hjust = 1))
-

-
-
-
-

Recap -

-

The sweep package has a several tools to analyze grouped -time series. In the next vignette we will review how to apply multiple -models to a time series.

-
-
-
- - - - -
- - - - - - - diff --git a/docs/articles/SW01_Forecasting_Time_Series_Groups_files/accessible-code-block-0.0.1/empty-anchor.js b/docs/articles/SW01_Forecasting_Time_Series_Groups_files/accessible-code-block-0.0.1/empty-anchor.js deleted file mode 100644 index ca349fd..0000000 --- a/docs/articles/SW01_Forecasting_Time_Series_Groups_files/accessible-code-block-0.0.1/empty-anchor.js +++ /dev/null @@ -1,15 +0,0 @@ -// Hide empty tag within highlighted CodeBlock for screen reader accessibility (see https://github.com/jgm/pandoc/issues/6352#issuecomment-626106786) --> -// v0.0.1 -// Written by JooYoung Seo (jooyoung@psu.edu) and Atsushi Yasumoto on June 1st, 2020. - -document.addEventListener('DOMContentLoaded', function() { - const codeList = document.getElementsByClassName("sourceCode"); - for (var i = 0; i < codeList.length; i++) { - var linkList = codeList[i].getElementsByTagName('a'); - for (var j = 0; j < linkList.length; j++) { - if (linkList[j].innerHTML === "") { - linkList[j].setAttribute('aria-hidden', 'true'); - } - } - } -}); diff --git a/docs/articles/SW01_Forecasting_Time_Series_Groups_files/figure-html/unnamed-chunk-13-1.png b/docs/articles/SW01_Forecasting_Time_Series_Groups_files/figure-html/unnamed-chunk-13-1.png deleted file mode 100644 index 4b6310f..0000000 Binary files a/docs/articles/SW01_Forecasting_Time_Series_Groups_files/figure-html/unnamed-chunk-13-1.png and /dev/null differ diff --git a/docs/articles/SW01_Forecasting_Time_Series_Groups_files/figure-html/unnamed-chunk-17-1.png b/docs/articles/SW01_Forecasting_Time_Series_Groups_files/figure-html/unnamed-chunk-17-1.png deleted file mode 100644 index 2abe0e4..0000000 Binary files a/docs/articles/SW01_Forecasting_Time_Series_Groups_files/figure-html/unnamed-chunk-17-1.png and /dev/null differ diff --git a/docs/articles/SW01_Forecasting_Time_Series_Groups_files/figure-html/unnamed-chunk-5-1.png b/docs/articles/SW01_Forecasting_Time_Series_Groups_files/figure-html/unnamed-chunk-5-1.png deleted file mode 100644 index a0b3cd9..0000000 Binary files a/docs/articles/SW01_Forecasting_Time_Series_Groups_files/figure-html/unnamed-chunk-5-1.png and /dev/null differ diff --git a/docs/articles/SW01_Forecasting_Time_Series_Groups_files/header-attrs-2.1/header-attrs.js b/docs/articles/SW01_Forecasting_Time_Series_Groups_files/header-attrs-2.1/header-attrs.js deleted file mode 100644 index dd57d92..0000000 --- a/docs/articles/SW01_Forecasting_Time_Series_Groups_files/header-attrs-2.1/header-attrs.js +++ /dev/null @@ -1,12 +0,0 @@ -// Pandoc 2.9 adds attributes on both header and div. We remove the former (to -// be compatible with the behavior of Pandoc < 2.8). -document.addEventListener('DOMContentLoaded', function(e) { - var hs = document.querySelectorAll("div.section[class*='level'] > :first-child"); - var i, h, a; - for (i = 0; i < hs.length; i++) { - h = hs[i]; - if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6 - a = h.attributes; - while (a.length > 0) h.removeAttribute(a[0].name); - } -}); diff --git a/docs/articles/SW01_Forecasting_Time_Series_Groups_files/header-attrs-2.3/header-attrs.js b/docs/articles/SW01_Forecasting_Time_Series_Groups_files/header-attrs-2.3/header-attrs.js deleted file mode 100644 index dd57d92..0000000 --- a/docs/articles/SW01_Forecasting_Time_Series_Groups_files/header-attrs-2.3/header-attrs.js +++ /dev/null @@ -1,12 +0,0 @@ -// Pandoc 2.9 adds attributes on both header and div. We remove the former (to -// be compatible with the behavior of Pandoc < 2.8). -document.addEventListener('DOMContentLoaded', function(e) { - var hs = document.querySelectorAll("div.section[class*='level'] > :first-child"); - var i, h, a; - for (i = 0; i < hs.length; i++) { - h = hs[i]; - if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6 - a = h.attributes; - while (a.length > 0) h.removeAttribute(a[0].name); - } -}); diff --git a/docs/articles/SW02_Forecasting_Multiple_Models.html b/docs/articles/SW02_Forecasting_Multiple_Models.html deleted file mode 100644 index b8a8d93..0000000 --- a/docs/articles/SW02_Forecasting_Multiple_Models.html +++ /dev/null @@ -1,625 +0,0 @@ - - - - - - - - -Forecasting Using Multiple Models • sweep - - - - - - - - - - - - - - - - - - Skip to contents - - -
- - - - -
-
- - - -
-

Extending broom to time series forecasting

-
-

One of the most powerful benefits of sweep is that it -helps forecasting at scale within the “tidyverse”. There are two common -situations:

-
    -
  1. Applying a model to groups of time series
  2. -
  3. Applying multiple models to a time series
  4. -
-

In this vignette we’ll review how sweep can help the -second situation: Applying multiple models to a -time series.

-
-

Prerequisites -

-

Before we get started, load the following packages.

- -
-
-

Forecasting Gasoline Prices -

-

To start, let’s get some data from the FRED data base using -tidyquant. We’ll use tq_get() to retrieve the -Gasoline Prices from 1990 through today (2023-12-08).

-
-gas_prices_monthly_raw <- tq_get(
-    x    = "GASREGCOVM", 
-    get  = "economic.data", 
-    from = "1990-01-01", 
-    to   = "2016-12-31") 
-gas_prices_monthly_raw
-
## # A tibble: 316 × 3
-##    symbol     date       price
-##    <chr>      <date>     <dbl>
-##  1 GASREGCOVM 1990-09-01  1.26
-##  2 GASREGCOVM 1990-10-01  1.34
-##  3 GASREGCOVM 1990-11-01  1.32
-##  4 GASREGCOVM 1990-12-01 NA   
-##  5 GASREGCOVM 1991-01-01 NA   
-##  6 GASREGCOVM 1991-02-01  1.09
-##  7 GASREGCOVM 1991-03-01  1.04
-##  8 GASREGCOVM 1991-04-01  1.08
-##  9 GASREGCOVM 1991-05-01  1.13
-## 10 GASREGCOVM 1991-06-01  1.13
-## # ℹ 306 more rows
-

Upon a brief inspection, the data contains 2 NA values -that will need to be dealt with.

-
-summary(gas_prices_monthly_raw$price)
-
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA's 
-##   0.900   1.138   1.615   1.974   2.697   4.002       2
-

We can use the fill() from the tidyr -package to help deal with these data. We first fill down and then fill -up to use the previous and then post days prices to fill in the missing -data.

-
-gas_prices_monthly <- gas_prices_monthly_raw %>%
-    fill(price, .direction = "down") %>%
-    fill(price, .direction = "up")
-

We can now visualize the data.

-
-gas_prices_monthly %>%
-    ggplot(aes(x = date, y = price)) +
-    geom_line(color = palette_light()[[1]]) +
-    labs(title = "Gasoline Prices, Monthly", x = "", y = "USD") +
-    scale_y_continuous(labels = scales::dollar) +
-    theme_tq()
-

-

Monthly periodicity might be a bit granular for model fitting. We can -easily switch periodicity to quarterly using tq_transmute() -from the tidyquant package along with the periodicity -aggregation function to.period from the xts -package. We’ll convert the date to yearqtr class which is -regularized.

-
-gas_prices_quarterly <- gas_prices_monthly %>%
-    tq_transmute(mutate_fun = to.period, period = "quarters") 
-gas_prices_quarterly
-
## # A tibble: 106 × 2
-##    date       price
-##    <date>     <dbl>
-##  1 1990-09-01  1.26
-##  2 1990-12-01  1.32
-##  3 1991-03-01  1.04
-##  4 1991-06-01  1.13
-##  5 1991-09-01  1.11
-##  6 1991-12-01  1.08
-##  7 1992-03-01  1.01
-##  8 1992-06-01  1.14
-##  9 1992-09-01  1.12
-## 10 1992-12-01  1.08
-## # ℹ 96 more rows
-

Another quick visualization to show the reduction in granularity.

-
-gas_prices_quarterly %>%
-    ggplot(aes(x = date, y = price)) +
-    geom_line(color = palette_light()[[1]], linewidth = 1) +
-    labs(title = "Gasoline Prices, Quarterly", x = "", y = "USD") +
-    scale_y_continuous(labels = scales::label_dollar()) +
-    scale_x_date(date_breaks = "5 years", date_labels = "%Y") +
-    theme_tq()
-

-
-
-

Performing Forecasts Using Multiple Models -

-

In this section we will use three models to forecast gasoline -prices:

-
    -
  1. ARIMA
  2. -
  3. ETS
  4. -
  5. BATS
  6. -
-
-

Multiple Models Concept -

-

Before we jump into modeling, let’s take a look at the multiple model -process from R for -Data Science, Chapter 25 Many Models. We first create a data frame -from a named list. The example below has two columns: “f” the functions -as text, and “params” a nested list of parameters we will pass to the -respective function in column “f”.

-
-df <- tibble(
-  f = c("runif", "rpois", "rnorm"),
-  params = list(
-    list(n = 10),
-    list(n = 5, lambda = 10),
-    list(n = 10, mean = -3, sd = 10)
-  )
-)
-df
-
## # A tibble: 3 × 2
-##   f     params          
-##   <chr> <list>          
-## 1 runif <named list [1]>
-## 2 rpois <named list [2]>
-## 3 rnorm <named list [3]>
-

We can also view the contents of the df$params column to -understand the underlying structure. Notice that there are three primary -levels and then secondary levels containing the name-value pairs of -parameters. This format is important.

-
-df$params
-
## [[1]]
-## [[1]]$n
-## [1] 10
-## 
-## 
-## [[2]]
-## [[2]]$n
-## [1] 5
-## 
-## [[2]]$lambda
-## [1] 10
-## 
-## 
-## [[3]]
-## [[3]]$n
-## [1] 10
-## 
-## [[3]]$mean
-## [1] -3
-## 
-## [[3]]$sd
-## [1] 10
-

Next we apply the functions to the parameters using a special -function, invoke_map(). The parameter lists in the “params” -column are passed to the function in the “f” column. The output is in a -nested list-column named “out”.

-
-# FIXME invoke_map is deprecated
-df_out <- df %>% 
-    mutate(out = invoke_map(f, params))
-
## Warning: There was 1 warning in `mutate()`.
-##  In argument: `out = invoke_map(f, params)`.
-## Caused by warning:
-## ! `invoke_map()` was deprecated in purrr 1.0.0.
-##  Please use map() + exec() instead.
-
-df_out
-
## # A tibble: 3 × 3
-##   f     params           out       
-##   <chr> <list>           <list>    
-## 1 runif <named list [1]> <dbl [10]>
-## 2 rpois <named list [2]> <int [5]> 
-## 3 rnorm <named list [3]> <dbl [10]>
-

And, here’s the contents of “out”, which is the result of mapping a -list of functions to a list of parameters. Pretty powerful!

-
-df_out$out
-
## [[1]]
-##  [1] 0.12529973 0.21685173 0.08249597 0.76834989 0.63376226 0.30774705
-##  [7] 0.21109112 0.32589788 0.08359866 0.23515630
-## 
-## [[2]]
-## [1] 10 11 11 12  6
-## 
-## [[3]]
-##  [1] -11.06074584  -3.36132264   1.37013110  -9.02433907  -0.47015515
-##  [6]   0.04641386 -14.17989613   1.76384292 -11.52289943  -0.63068203
-

Take a minute to understand the conceptual process of the -invoke_map function and specifically the parameter setup. -Once you are comfortable, we can move on to model implementation.

-
-
-

Multiple Model Implementation -

-

We’ll need to take the following steps to in an actual forecast model -implementation:

-
    -
  1. Coerce the data to time series
  2. -
  3. Build a model list using nested lists
  4. -
  5. Create the the model data frame
  6. -
  7. Invoke a function map
  8. -
-

This is easier than it sounds. Let’s start by coercing the univariate -time series with tk_ts().

-
-gas_prices_quarterly_ts <- gas_prices_quarterly %>% 
-    tk_ts(select = -date, start = c(1990, 3), freq = 4)
-gas_prices_quarterly_ts
-
##       Qtr1  Qtr2  Qtr3  Qtr4
-## 1990             1.258 1.324
-## 1991 1.040 1.128 1.109 1.076
-## 1992 1.013 1.145 1.122 1.078
-## 1993 1.052 1.097 1.050 1.014
-## 1994 1.008 1.078 1.144 1.060
-## 1995 1.059 1.186 1.108 1.066
-## 1996 1.129 1.243 1.200 1.233
-## 1997 1.197 1.189 1.216 1.119
-## 1998 1.014 1.048 0.994 0.923
-## 1999 0.961 1.095 1.239 1.261
-## 2000 1.498 1.612 1.525 1.418
-## 2001 1.384 1.548 1.506 1.072
-## 2002 1.221 1.341 1.363 1.348
-## 2003 1.636 1.452 1.616 1.448
-## 2004 1.689 1.910 1.841 1.800
-## 2005 2.063 2.123 2.862 2.174
-## 2006 2.413 2.808 2.501 2.284
-## 2007 2.503 3.024 2.817 2.984
-## 2008 3.215 3.989 3.709 1.669
-## 2009 1.937 2.597 2.480 2.568
-## 2010 2.742 2.684 2.678 2.951
-## 2011 3.509 3.628 3.573 3.220
-## 2012 3.774 3.465 3.801 3.256
-## 2013 3.648 3.576 3.474 3.209
-## 2014 3.474 3.626 3.354 2.488
-## 2015 2.352 2.700 2.275 1.946
-## 2016 1.895 2.303 2.161 2.192
-

Next, create a nested list using the function names as the -first-level keys (this is important as you’ll see in the next step). -Pass the model parameters as name-value pairs in the second level.

-
-models_list <- list(
-    auto.arima = list(
-        y = gas_prices_quarterly_ts
-        ),
-    ets = list(
-        y = gas_prices_quarterly_ts,
-        damped = TRUE
-    ),
-    bats = list(
-        y = gas_prices_quarterly_ts
-    )
-)
-

Now, convert to a data frame using the function, -enframe() that turns lists into tibbles. Set the arguments -name = "f" and value = "params". In doing so -we get a bonus: the model names are the now conveniently located in -column “f”.

-
-models_tbl <- tibble::enframe(models_list, name = "f", value = "params")
-models_tbl
-
## # A tibble: 3 × 2
-##   f          params          
-##   <chr>      <list>          
-## 1 auto.arima <named list [1]>
-## 2 ets        <named list [2]>
-## 3 bats       <named list [1]>
-

We are ready to invoke the map. Combine mutate() with -invoke_map() as follows. Bada bing, bada boom, we now have -models fitted using the parameters we defined previously.

-
-models_tbl_fit <- models_tbl %>%
-    mutate(fit = purrr::invoke_map(f, params))
-models_tbl_fit
-
## # A tibble: 3 × 3
-##   f          params           fit       
-##   <chr>      <list>           <list>    
-## 1 auto.arima <named list [1]> <fr_ARIMA>
-## 2 ets        <named list [2]> <ets>     
-## 3 bats       <named list [1]> <bats>
-
-
-
-

Inspecting the Model Fit -

-

It’s a good point to review and understand the model output. We can -review the model parameters, accuracy measurements, and the residuals -using sw_tidy(), sw_glance(), and -sw_augment().

-
-

sw_tidy -

-

The tidying function returns the model parameters and estimates. We -use the combination of mutate and map to -iteratively apply the sw_tidy() function as a new column -named “tidy”. Then we unnest and spread to review the terms by model -function.

-
-models_tbl_fit %>%
-    mutate(tidy = map(fit, sw_tidy)) %>%
-    unnest(tidy) %>%
-    spread(key = f, value = estimate)
-
## # A tibble: 20 × 6
-##    params           fit        term              auto.arima       bats       ets
-##    <list>           <list>     <chr>                  <dbl>      <dbl>     <dbl>
-##  1 <named list [1]> <fr_ARIMA> ar1                    0.834 NA         NA       
-##  2 <named list [1]> <fr_ARIMA> ma1                   -0.964 NA         NA       
-##  3 <named list [1]> <fr_ARIMA> sar1                   0.939 NA         NA       
-##  4 <named list [1]> <fr_ARIMA> sma1                  -0.776 NA         NA       
-##  5 <named list [1]> <bats>     alpha                 NA      0.588     NA       
-##  6 <named list [1]> <bats>     ar.coefficients       NA     NA         NA       
-##  7 <named list [1]> <bats>     beta                  NA     NA         NA       
-##  8 <named list [1]> <bats>     damping.parameter     NA     NA         NA       
-##  9 <named list [1]> <bats>     gamma.values          NA     -0.0262    NA       
-## 10 <named list [1]> <bats>     lambda                NA      0.0000605 NA       
-## 11 <named list [1]> <bats>     ma.coefficients       NA      0.256     NA       
-## 12 <named list [2]> <ets>      alpha                 NA     NA          0.831   
-## 13 <named list [2]> <ets>      b                     NA     NA         -0.0524  
-## 14 <named list [2]> <ets>      beta                  NA     NA          0.000100
-## 15 <named list [2]> <ets>      gamma                 NA     NA          0.0521  
-## 16 <named list [2]> <ets>      l                     NA     NA          1.29    
-## 17 <named list [2]> <ets>      phi                   NA     NA          0.837   
-## 18 <named list [2]> <ets>      s0                    NA     NA          0.0469  
-## 19 <named list [2]> <ets>      s1                    NA     NA         -0.0209  
-## 20 <named list [2]> <ets>      s2                    NA     NA         -0.0407
-
-
-

sw_glance -

-

Glance is one of the most powerful tools because it yields the model -accuracies enabling direct comparisons between the fit of each model. We -use the same process for used for tidy, except theres no need to spread -to perform the comparison. We can see that the ARIMA model has the -lowest AIC by far.

-
-models_tbl_fit %>%
-    mutate(glance = map(fit, sw_glance)) %>%
-    unnest(glance, .drop = TRUE)
-
## Warning: The `.drop` argument of `unnest()` is deprecated as of tidyr 1.0.0.
-##  All list-columns are now preserved.
-## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
-## generated.
-
## # A tibble: 3 × 15
-##   f     params       fit        model.desc sigma logLik   AIC   BIC     ME  RMSE
-##   <chr> <list>       <list>     <chr>      <dbl>  <dbl> <dbl> <dbl>  <dbl> <dbl>
-## 1 auto… <named list> <fr_ARIMA> ARIMA(1,1… 0.298  -20.6  51.2  64.4 0.0180 0.291
-## 2 ets   <named list> <ets>      ETS(M,Ad,… 0.118  -76.6 173.  200.  0.0149 0.292
-## 3 bats  <named list> <bats>     BATS(0, {… 0.116  159.  179.  184.  0.0193 0.259
-## # ℹ 5 more variables: MAE <dbl>, MPE <dbl>, MAPE <dbl>, MASE <dbl>, ACF1 <dbl>
-
-
-

sw_augment -

-

We can augment the models to get the residuals following the same -procedure. We can pipe (%>%) the results right into -ggplot() for plotting. Notice the ARIMA model has the -largest residuals especially as the model index increases whereas the -bats model has relatively low residuals.

-
-models_tbl_fit %>%
-    mutate(augment = map(fit, sw_augment, rename_index = "date")) %>%
-    unnest(augment) %>%
-    ggplot(aes(x = date, y = .resid, group = f)) +
-    geom_line(color = palette_light()[[2]]) +
-    geom_point(color = palette_light()[[1]]) +
-    geom_smooth(method = "loess") +
-    facet_wrap(~ f, nrow = 3) +
-    labs(title = "Residuals Plot") +
-    theme_tq()
-
## `geom_smooth()` using formula = 'y ~ x'
-

-
-
-
-

Forecasting the model -

-

Creating the forecast for the models is accomplished by mapping the -forecast function. The next six quarters are forecasted -withe the argument h = 6.

-
-models_tbl_fcast <- models_tbl_fit %>%
-    mutate(fcast = map(fit, forecast, h = 6))
-models_tbl_fcast
-
## # A tibble: 3 × 4
-##   f          params           fit        fcast     
-##   <chr>      <list>           <list>     <list>    
-## 1 auto.arima <named list [1]> <fr_ARIMA> <forecast>
-## 2 ets        <named list [2]> <ets>      <forecast>
-## 3 bats       <named list [1]> <bats>     <forecast>
-
-
-

Tidying the forecast -

-

Next, we map sw_sweep, which coerces the forecast into -the “tidy” tibble format. We set fitted = FALSE to remove -the model fitted values from the output. We set -timetk_idx = TRUE to use dates instead of numeric values -for the index.

-
-models_tbl_fcast_tidy <- models_tbl_fcast %>%
-    mutate(sweep = map(fcast, sw_sweep, fitted = FALSE, timetk_idx = TRUE, rename_index = "date"))
-
## Warning: There were 3 warnings in `mutate()`.
-## The first warning was:
-##  In argument: `sweep = map(fcast, sw_sweep, fitted = FALSE, timetk_idx = TRUE,
-##   rename_index = "date")`.
-## Caused by warning in `.check_tzones()`:
-## ! 'tzone' attributes are inconsistent
-##  Run `dplyr::last_dplyr_warnings()` to see the 2 remaining warnings.
-
-models_tbl_fcast_tidy
-
## # A tibble: 3 × 5
-##   f          params           fit        fcast      sweep             
-##   <chr>      <list>           <list>     <list>     <list>            
-## 1 auto.arima <named list [1]> <fr_ARIMA> <forecast> <tibble [112 × 7]>
-## 2 ets        <named list [2]> <ets>      <forecast> <tibble [112 × 7]>
-## 3 bats       <named list [1]> <bats>     <forecast> <tibble [112 × 7]>
-

We can unnest the “sweep” column to get the results of all three -models.

-
-models_tbl_fcast_tidy %>%
-    unnest(sweep)
-
## # A tibble: 336 × 11
-##    f       params       fit        fcast      date       key   price lo.80 lo.95
-##    <chr>   <list>       <list>     <list>     <date>     <chr> <dbl> <dbl> <dbl>
-##  1 auto.a… <named list> <fr_ARIMA> <forecast> 1990-09-01 actu…  1.26    NA    NA
-##  2 auto.a… <named list> <fr_ARIMA> <forecast> 1990-12-01 actu…  1.32    NA    NA
-##  3 auto.a… <named list> <fr_ARIMA> <forecast> 1991-03-01 actu…  1.04    NA    NA
-##  4 auto.a… <named list> <fr_ARIMA> <forecast> 1991-06-01 actu…  1.13    NA    NA
-##  5 auto.a… <named list> <fr_ARIMA> <forecast> 1991-09-01 actu…  1.11    NA    NA
-##  6 auto.a… <named list> <fr_ARIMA> <forecast> 1991-12-01 actu…  1.08    NA    NA
-##  7 auto.a… <named list> <fr_ARIMA> <forecast> 1992-03-01 actu…  1.01    NA    NA
-##  8 auto.a… <named list> <fr_ARIMA> <forecast> 1992-06-01 actu…  1.14    NA    NA
-##  9 auto.a… <named list> <fr_ARIMA> <forecast> 1992-09-01 actu…  1.12    NA    NA
-## 10 auto.a… <named list> <fr_ARIMA> <forecast> 1992-12-01 actu…  1.08    NA    NA
-## # ℹ 326 more rows
-## # ℹ 2 more variables: hi.80 <dbl>, hi.95 <dbl>
-

Finally, we can plot the forecasts by unnesting the “sweep” column -and piping to ggplot().

-
-models_tbl_fcast_tidy %>%
-    unnest(sweep) %>%
-    ggplot(aes(x = date, y = price, color = key, group = f)) +
-    geom_ribbon(aes(ymin = lo.95, ymax = hi.95), 
-                fill = "#D5DBFF", color = NA, linewidth = 0) +
-    geom_ribbon(aes(ymin = lo.80, ymax = hi.80, fill = key), 
-                fill = "#596DD5", color = NA, linewidth = 0, alpha = 0.8) +
-    geom_line(linewidth = 1) +
-    facet_wrap(~f, nrow = 3) +
-    labs(title = "Gasoline Price Forecasts",
-         subtitle = "Forecasting multiple models with sweep: ARIMA, BATS, ETS",
-         x = "", y = "Price") +
-    scale_y_continuous(labels = scales::label_dollar()) +
-    scale_x_date(date_breaks = "5 years", date_labels = "%Y") +
-    theme_tq() +
-    scale_color_tq()
-

-
-
-

Recap -

-

The sweep package can aid analysis of multiple forecast -models. In the next vignette we will review time series object coercion -with sweep.

-
-
-
- - - - -
- - - - - - - diff --git a/docs/articles/SW02_Forecasting_Multiple_Models_files/accessible-code-block-0.0.1/empty-anchor.js b/docs/articles/SW02_Forecasting_Multiple_Models_files/accessible-code-block-0.0.1/empty-anchor.js deleted file mode 100644 index ca349fd..0000000 --- a/docs/articles/SW02_Forecasting_Multiple_Models_files/accessible-code-block-0.0.1/empty-anchor.js +++ /dev/null @@ -1,15 +0,0 @@ -// Hide empty tag within highlighted CodeBlock for screen reader accessibility (see https://github.com/jgm/pandoc/issues/6352#issuecomment-626106786) --> -// v0.0.1 -// Written by JooYoung Seo (jooyoung@psu.edu) and Atsushi Yasumoto on June 1st, 2020. - -document.addEventListener('DOMContentLoaded', function() { - const codeList = document.getElementsByClassName("sourceCode"); - for (var i = 0; i < codeList.length; i++) { - var linkList = codeList[i].getElementsByTagName('a'); - for (var j = 0; j < linkList.length; j++) { - if (linkList[j].innerHTML === "") { - linkList[j].setAttribute('aria-hidden', 'true'); - } - } - } -}); diff --git a/docs/articles/SW02_Forecasting_Multiple_Models_files/figure-html/unnamed-chunk-19-1.png b/docs/articles/SW02_Forecasting_Multiple_Models_files/figure-html/unnamed-chunk-19-1.png deleted file mode 100644 index 66250d3..0000000 Binary files a/docs/articles/SW02_Forecasting_Multiple_Models_files/figure-html/unnamed-chunk-19-1.png and /dev/null differ diff --git a/docs/articles/SW02_Forecasting_Multiple_Models_files/figure-html/unnamed-chunk-23-1.png b/docs/articles/SW02_Forecasting_Multiple_Models_files/figure-html/unnamed-chunk-23-1.png deleted file mode 100644 index a89ca19..0000000 Binary files a/docs/articles/SW02_Forecasting_Multiple_Models_files/figure-html/unnamed-chunk-23-1.png and /dev/null differ diff --git a/docs/articles/SW02_Forecasting_Multiple_Models_files/figure-html/unnamed-chunk-6-1.png b/docs/articles/SW02_Forecasting_Multiple_Models_files/figure-html/unnamed-chunk-6-1.png deleted file mode 100644 index 4a4010e..0000000 Binary files a/docs/articles/SW02_Forecasting_Multiple_Models_files/figure-html/unnamed-chunk-6-1.png and /dev/null differ diff --git a/docs/articles/SW02_Forecasting_Multiple_Models_files/figure-html/unnamed-chunk-8-1.png b/docs/articles/SW02_Forecasting_Multiple_Models_files/figure-html/unnamed-chunk-8-1.png deleted file mode 100644 index 29f4495..0000000 Binary files a/docs/articles/SW02_Forecasting_Multiple_Models_files/figure-html/unnamed-chunk-8-1.png and /dev/null differ diff --git a/docs/articles/SW02_Forecasting_Multiple_Models_files/header-attrs-2.1/header-attrs.js b/docs/articles/SW02_Forecasting_Multiple_Models_files/header-attrs-2.1/header-attrs.js deleted file mode 100644 index dd57d92..0000000 --- a/docs/articles/SW02_Forecasting_Multiple_Models_files/header-attrs-2.1/header-attrs.js +++ /dev/null @@ -1,12 +0,0 @@ -// Pandoc 2.9 adds attributes on both header and div. We remove the former (to -// be compatible with the behavior of Pandoc < 2.8). -document.addEventListener('DOMContentLoaded', function(e) { - var hs = document.querySelectorAll("div.section[class*='level'] > :first-child"); - var i, h, a; - for (i = 0; i < hs.length; i++) { - h = hs[i]; - if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6 - a = h.attributes; - while (a.length > 0) h.removeAttribute(a[0].name); - } -}); diff --git a/docs/articles/SW02_Forecasting_Multiple_Models_files/header-attrs-2.3/header-attrs.js b/docs/articles/SW02_Forecasting_Multiple_Models_files/header-attrs-2.3/header-attrs.js deleted file mode 100644 index dd57d92..0000000 --- a/docs/articles/SW02_Forecasting_Multiple_Models_files/header-attrs-2.3/header-attrs.js +++ /dev/null @@ -1,12 +0,0 @@ -// Pandoc 2.9 adds attributes on both header and div. We remove the former (to -// be compatible with the behavior of Pandoc < 2.8). -document.addEventListener('DOMContentLoaded', function(e) { - var hs = document.querySelectorAll("div.section[class*='level'] > :first-child"); - var i, h, a; - for (i = 0; i < hs.length; i++) { - h = hs[i]; - if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6 - a = h.attributes; - while (a.length > 0) h.removeAttribute(a[0].name); - } -}); diff --git a/docs/articles/index.html b/docs/articles/index.html deleted file mode 100644 index ebf1c47..0000000 --- a/docs/articles/index.html +++ /dev/null @@ -1,101 +0,0 @@ - -Articles • sweep - Skip to contents - - -
-
-
- - -
- - -
- - - - - - - diff --git a/docs/authors.html b/docs/authors.html deleted file mode 100644 index 7b8fe5f..0000000 --- a/docs/authors.html +++ /dev/null @@ -1,119 +0,0 @@ - -Authors and Citation • sweep - Skip to contents - - -
-
-
- -
-

Authors

- -
  • -

    Matt Dancho. Author, maintainer. -

    -
  • -
  • -

    Davis Vaughan. Author. -

    -
  • -
- -
-

Citation

-

Source: DESCRIPTION

- -

Dancho M, Vaughan D (2023). -sweep: Tidy Tools for Forecasting. -https://business-science.github.io/sweep/, https://github.com/business-science/sweep. -

-
@Manual{,
-  title = {sweep: Tidy Tools for Forecasting},
-  author = {Matt Dancho and Davis Vaughan},
-  year = {2023},
-  note = {https://business-science.github.io/sweep/, https://github.com/business-science/sweep},
-}
-
-
- - -
- - - - - - - diff --git a/docs/bootstrap-toc.css b/docs/bootstrap-toc.css deleted file mode 100644 index 5a85941..0000000 --- a/docs/bootstrap-toc.css +++ /dev/null @@ -1,60 +0,0 @@ -/*! - * Bootstrap Table of Contents v0.4.1 (http://afeld.github.io/bootstrap-toc/) - * Copyright 2015 Aidan Feldman - * Licensed under MIT (https://github.com/afeld/bootstrap-toc/blob/gh-pages/LICENSE.md) */ - -/* modified from https://github.com/twbs/bootstrap/blob/94b4076dd2efba9af71f0b18d4ee4b163aa9e0dd/docs/assets/css/src/docs.css#L548-L601 */ - -/* All levels of nav */ -nav[data-toggle='toc'] .nav > li > a { - display: block; - padding: 4px 20px; - font-size: 13px; - font-weight: 500; - color: #767676; -} -nav[data-toggle='toc'] .nav > li > a:hover, -nav[data-toggle='toc'] .nav > li > a:focus { - padding-left: 19px; - color: #563d7c; - text-decoration: none; - background-color: transparent; - border-left: 1px solid #563d7c; -} -nav[data-toggle='toc'] .nav > .active > a, -nav[data-toggle='toc'] .nav > .active:hover > a, -nav[data-toggle='toc'] .nav > .active:focus > a { - padding-left: 18px; - font-weight: bold; - color: #563d7c; - background-color: transparent; - border-left: 2px solid #563d7c; -} - -/* Nav: second level (shown on .active) */ -nav[data-toggle='toc'] .nav .nav { - display: none; /* Hide by default, but at >768px, show it */ - padding-bottom: 10px; -} -nav[data-toggle='toc'] .nav .nav > li > a { - padding-top: 1px; - padding-bottom: 1px; - padding-left: 30px; - font-size: 12px; - font-weight: normal; -} -nav[data-toggle='toc'] .nav .nav > li > a:hover, -nav[data-toggle='toc'] .nav .nav > li > a:focus { - padding-left: 29px; -} -nav[data-toggle='toc'] .nav .nav > .active > a, -nav[data-toggle='toc'] .nav .nav > .active:hover > a, -nav[data-toggle='toc'] .nav .nav > .active:focus > a { - padding-left: 28px; - font-weight: 500; -} - -/* from https://github.com/twbs/bootstrap/blob/e38f066d8c203c3e032da0ff23cd2d6098ee2dd6/docs/assets/css/src/docs.css#L631-L634 */ -nav[data-toggle='toc'] .nav > .active > ul { - display: block; -} diff --git a/docs/bootstrap-toc.js b/docs/bootstrap-toc.js deleted file mode 100644 index 1cdd573..0000000 --- a/docs/bootstrap-toc.js +++ /dev/null @@ -1,159 +0,0 @@ -/*! - * Bootstrap Table of Contents v0.4.1 (http://afeld.github.io/bootstrap-toc/) - * Copyright 2015 Aidan Feldman - * Licensed under MIT (https://github.com/afeld/bootstrap-toc/blob/gh-pages/LICENSE.md) */ -(function() { - 'use strict'; - - window.Toc = { - helpers: { - // return all matching elements in the set, or their descendants - findOrFilter: function($el, selector) { - // http://danielnouri.org/notes/2011/03/14/a-jquery-find-that-also-finds-the-root-element/ - // http://stackoverflow.com/a/12731439/358804 - var $descendants = $el.find(selector); - return $el.filter(selector).add($descendants).filter(':not([data-toc-skip])'); - }, - - generateUniqueIdBase: function(el) { - var text = $(el).text(); - var anchor = text.trim().toLowerCase().replace(/[^A-Za-z0-9]+/g, '-'); - return anchor || el.tagName.toLowerCase(); - }, - - generateUniqueId: function(el) { - var anchorBase = this.generateUniqueIdBase(el); - for (var i = 0; ; i++) { - var anchor = anchorBase; - if (i > 0) { - // add suffix - anchor += '-' + i; - } - // check if ID already exists - if (!document.getElementById(anchor)) { - return anchor; - } - } - }, - - generateAnchor: function(el) { - if (el.id) { - return el.id; - } else { - var anchor = this.generateUniqueId(el); - el.id = anchor; - return anchor; - } - }, - - createNavList: function() { - return $(''); - }, - - createChildNavList: function($parent) { - var $childList = this.createNavList(); - $parent.append($childList); - return $childList; - }, - - generateNavEl: function(anchor, text) { - var $a = $(''); - $a.attr('href', '#' + anchor); - $a.text(text); - var $li = $('
  • '); - $li.append($a); - return $li; - }, - - generateNavItem: function(headingEl) { - var anchor = this.generateAnchor(headingEl); - var $heading = $(headingEl); - var text = $heading.data('toc-text') || $heading.text(); - return this.generateNavEl(anchor, text); - }, - - // Find the first heading level (`

    `, then `

    `, etc.) that has more than one element. Defaults to 1 (for `

    `). - getTopLevel: function($scope) { - for (var i = 1; i <= 6; i++) { - var $headings = this.findOrFilter($scope, 'h' + i); - if ($headings.length > 1) { - return i; - } - } - - return 1; - }, - - // returns the elements for the top level, and the next below it - getHeadings: function($scope, topLevel) { - var topSelector = 'h' + topLevel; - - var secondaryLevel = topLevel + 1; - var secondarySelector = 'h' + secondaryLevel; - - return this.findOrFilter($scope, topSelector + ',' + secondarySelector); - }, - - getNavLevel: function(el) { - return parseInt(el.tagName.charAt(1), 10); - }, - - populateNav: function($topContext, topLevel, $headings) { - var $context = $topContext; - var $prevNav; - - var helpers = this; - $headings.each(function(i, el) { - var $newNav = helpers.generateNavItem(el); - var navLevel = helpers.getNavLevel(el); - - // determine the proper $context - if (navLevel === topLevel) { - // use top level - $context = $topContext; - } else if ($prevNav && $context === $topContext) { - // create a new level of the tree and switch to it - $context = helpers.createChildNavList($prevNav); - } // else use the current $context - - $context.append($newNav); - - $prevNav = $newNav; - }); - }, - - parseOps: function(arg) { - var opts; - if (arg.jquery) { - opts = { - $nav: arg - }; - } else { - opts = arg; - } - opts.$scope = opts.$scope || $(document.body); - return opts; - } - }, - - // accepts a jQuery object, or an options object - init: function(opts) { - opts = this.helpers.parseOps(opts); - - // ensure that the data attribute is in place for styling - opts.$nav.attr('data-toggle', 'toc'); - - var $topContext = this.helpers.createChildNavList(opts.$nav); - var topLevel = this.helpers.getTopLevel(opts.$scope); - var $headings = this.helpers.getHeadings(opts.$scope, topLevel); - this.helpers.populateNav($topContext, topLevel, $headings); - } - }; - - $(function() { - $('nav[data-toggle="toc"]').each(function(i, el) { - var $nav = $(el); - Toc.init($nav); - }); - }); -})(); diff --git a/docs/docsearch.css b/docs/docsearch.css deleted file mode 100644 index e5f1fe1..0000000 --- a/docs/docsearch.css +++ /dev/null @@ -1,148 +0,0 @@ -/* Docsearch -------------------------------------------------------------- */ -/* - Source: https://github.com/algolia/docsearch/ - License: MIT -*/ - -.algolia-autocomplete { - display: block; - -webkit-box-flex: 1; - -ms-flex: 1; - flex: 1 -} - -.algolia-autocomplete .ds-dropdown-menu { - width: 100%; - min-width: none; - max-width: none; - padding: .75rem 0; - background-color: #fff; - background-clip: padding-box; - border: 1px solid rgba(0, 0, 0, .1); - box-shadow: 0 .5rem 1rem rgba(0, 0, 0, .175); -} - -@media (min-width:768px) { - .algolia-autocomplete .ds-dropdown-menu { - width: 175% - } -} - -.algolia-autocomplete .ds-dropdown-menu::before { - display: none -} - -.algolia-autocomplete .ds-dropdown-menu [class^=ds-dataset-] { - padding: 0; - background-color: rgb(255,255,255); - border: 0; - max-height: 80vh; -} - -.algolia-autocomplete .ds-dropdown-menu .ds-suggestions { - margin-top: 0 -} - -.algolia-autocomplete .algolia-docsearch-suggestion { - padding: 0; - overflow: visible -} - -.algolia-autocomplete .algolia-docsearch-suggestion--category-header { - padding: .125rem 1rem; - margin-top: 0; - font-size: 1.3em; - font-weight: 500; - color: #00008B; - border-bottom: 0 -} - -.algolia-autocomplete .algolia-docsearch-suggestion--wrapper { - float: none; - padding-top: 0 -} - -.algolia-autocomplete .algolia-docsearch-suggestion--subcategory-column { - float: none; - width: auto; - padding: 0; - text-align: left -} - -.algolia-autocomplete .algolia-docsearch-suggestion--content { - float: none; - width: auto; - padding: 0 -} - -.algolia-autocomplete .algolia-docsearch-suggestion--content::before { - display: none -} - -.algolia-autocomplete .ds-suggestion:not(:first-child) .algolia-docsearch-suggestion--category-header { - padding-top: .75rem; - margin-top: .75rem; - border-top: 1px solid rgba(0, 0, 0, .1) -} - -.algolia-autocomplete .ds-suggestion .algolia-docsearch-suggestion--subcategory-column { - display: block; - padding: .1rem 1rem; - margin-bottom: 0.1; - font-size: 1.0em; - font-weight: 400 - /* display: none */ -} - -.algolia-autocomplete .algolia-docsearch-suggestion--title { - display: block; - padding: .25rem 1rem; - margin-bottom: 0; - font-size: 0.9em; - font-weight: 400 -} - -.algolia-autocomplete .algolia-docsearch-suggestion--text { - padding: 0 1rem .5rem; - margin-top: -.25rem; - font-size: 0.8em; - font-weight: 400; - line-height: 1.25 -} - -.algolia-autocomplete .algolia-docsearch-footer { - width: 110px; - height: 20px; - z-index: 3; - margin-top: 10.66667px; - float: right; - font-size: 0; - line-height: 0; -} - -.algolia-autocomplete .algolia-docsearch-footer--logo { - background-image: url("data:image/svg+xml;utf8,"); - background-repeat: no-repeat; - background-position: 50%; - background-size: 100%; - overflow: hidden; - text-indent: -9000px; - width: 100%; - height: 100%; - display: block; - transform: translate(-8px); -} - -.algolia-autocomplete .algolia-docsearch-suggestion--highlight { - color: #FF8C00; - background: rgba(232, 189, 54, 0.1) -} - - -.algolia-autocomplete .algolia-docsearch-suggestion--text .algolia-docsearch-suggestion--highlight { - box-shadow: inset 0 -2px 0 0 rgba(105, 105, 105, .5) -} - -.algolia-autocomplete .ds-suggestion.ds-cursor .algolia-docsearch-suggestion--content { - background-color: rgba(192, 192, 192, .15) -} diff --git a/docs/docsearch.js b/docs/docsearch.js deleted file mode 100644 index b35504c..0000000 --- a/docs/docsearch.js +++ /dev/null @@ -1,85 +0,0 @@ -$(function() { - - // register a handler to move the focus to the search bar - // upon pressing shift + "/" (i.e. "?") - $(document).on('keydown', function(e) { - if (e.shiftKey && e.keyCode == 191) { - e.preventDefault(); - $("#search-input").focus(); - } - }); - - $(document).ready(function() { - // do keyword highlighting - /* modified from https://jsfiddle.net/julmot/bL6bb5oo/ */ - var mark = function() { - - var referrer = document.URL ; - var paramKey = "q" ; - - if (referrer.indexOf("?") !== -1) { - var qs = referrer.substr(referrer.indexOf('?') + 1); - var qs_noanchor = qs.split('#')[0]; - var qsa = qs_noanchor.split('&'); - var keyword = ""; - - for (var i = 0; i < qsa.length; i++) { - var currentParam = qsa[i].split('='); - - if (currentParam.length !== 2) { - continue; - } - - if (currentParam[0] == paramKey) { - keyword = decodeURIComponent(currentParam[1].replace(/\+/g, "%20")); - } - } - - if (keyword !== "") { - $(".contents").unmark({ - done: function() { - $(".contents").mark(keyword); - } - }); - } - } - }; - - mark(); - }); -}); - -/* Search term highlighting ------------------------------*/ - -function matchedWords(hit) { - var words = []; - - var hierarchy = hit._highlightResult.hierarchy; - // loop to fetch from lvl0, lvl1, etc. - for (var idx in hierarchy) { - words = words.concat(hierarchy[idx].matchedWords); - } - - var content = hit._highlightResult.content; - if (content) { - words = words.concat(content.matchedWords); - } - - // return unique words - var words_uniq = [...new Set(words)]; - return words_uniq; -} - -function updateHitURL(hit) { - - var words = matchedWords(hit); - var url = ""; - - if (hit.anchor) { - url = hit.url_without_anchor + '?q=' + escape(words.join(" ")) + '#' + hit.anchor; - } else { - url = hit.url + '?q=' + escape(words.join(" ")); - } - - return url; -} diff --git a/docs/index.html b/docs/index.html deleted file mode 100644 index b51da2b..0000000 --- a/docs/index.html +++ /dev/null @@ -1,421 +0,0 @@ - - - - - - - - -Tidy Tools for Forecasting • sweep - - - - - - - - - - - - - - - - - - Skip to contents - - -
    -
    -
    - -
    -

    Extending broom to time series forecasting

    -
    - - -

    The sweep package extends the broom tools (tidy, glance, and augment) for performing forecasts and time series analysis in the “tidyverse”. The package is geared towards “tidying” the forecast workflow used with Rob Hyndman’s forecast package.

    -
    -

    Benefits -

    -
      -
    • Designed for modeling and scaling forecasts using the the tidyverse tools in R for Data Science
    • -
    • Extends broom for model analysis (ARIMA, ETS, BATS, etc)
    • -
    • Tidies the forecast objects for easy plotting and “tidy” data manipulation
    • -
    • Integrates timetk to enable dates and datetimes (irregular time series) in the tidied forecast output
    • -
    -
    -
    -

    Tools -

    -

    The package contains the following elements:

    -
      -
    1. model tidiers: sw_tidy, sw_glance, sw_augment, sw_tidy_decomp functions extend tidy, glance, and augment from the broom package specifically for models (ets(), Arima(), bats(), etc) used for forecasting.

    2. -
    3. forecast tidier: sw_sweep converts a forecast object to a tibble that can be easily manipulated in the “tidyverse”.

    4. -
    -
    -
    -

    Making forecasts in the tidyverse -

    -

    sweep enables converting a forecast object to tibble. The result is ability to use dplyr, tidyr, and ggplot natively to manipulate, analyze and visualize forecasts.

    -

    -
    -
    -

    Forecasting multiple time series groups at scale -

    -

    Often forecasts are required on grouped data to analyse trends in sub-categories. The good news is scaling from one time series to many is easy with the various sw_ functions in combination with dplyr and purrr.

    -

    -
    -
    -

    Forecasting multiple models for accuracy -

    -

    A common goal in forecasting is to compare different forecast models against each other. sweep helps in this area as well.

    -

    -
    -
    -

    broom extensions for forecasting -

    -

    If you are familiar with broom, you know how useful it is for retrieving “tidy” format model components. sweep extends this benefit to the forecast package workflow with the following functions:

    -
      -
    • -sw_tidy: Returns model coefficients (single column)
    • -
    • -sw_glance: Returns accuracy statistics (single row)
    • -
    • -sw_augment: Returns residuals
    • -
    • -sw_tidy_decomp: Returns seasonal decompositions
    • -
    • -sw_sweep: Returns tidy forecast outputs.
    • -
    -

    The compatibility chart is listed below.

    - -------- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    Objectsw_tidy()sw_glance()sw_augment()sw_tidy_decomp()sw_sweep()
    ar
    arimaXXX
    ArimaXXX
    etsXXXX
    baggedETS
    batsXXXX
    tbatsXXXX
    nnetarXXX
    stlX
    HoltWintersXXXX
    StructTSXXXX
    tslmXXX
    decomposeX
    adf.testXX
    Box.testXX
    kpss.testXX
    forecastX
    -

    Function Compatibility

    -
    -
    -

    Installation -

    -

    Here’s how to get started.

    -

    Development version with latest features:

    -
    -# install.packages("remotes")
    -remotes::install_github("business-science/sweep")
    - - - - -
    -
    -

    Further Information -

    -

    The sweep package includes several vignettes to help users get up to speed quickly:

    -
      -
    • SW00 - Introduction to sweep -
    • -
    • SW01 - Forecasting Time Series Groups in the tidyverse
    • -
    • SW02 - Forecasting Using Multiple Models
    • -
    - -
    -
    -
    -
    - - -
    - - - -
    -
    - - - - - - - diff --git a/docs/link.svg b/docs/link.svg deleted file mode 100644 index 88ad827..0000000 --- a/docs/link.svg +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - diff --git a/docs/news/index.html b/docs/news/index.html deleted file mode 100644 index aa75b74..0000000 --- a/docs/news/index.html +++ /dev/null @@ -1,128 +0,0 @@ - -Changelog • sweep - Skip to contents - - -
    -
    -
    - -
    -

    sweep (development version)

    -
    -
    -

    sweep 0.2.5

    CRAN release: 2023-07-06

    -
    • Fixes to get sweep back on CRAN following inadvertent timetk archival.
    • -
    -
    -

    sweep 0.2.4

    -
    • Remove support for robets.
    • -
    -
    -

    sweep 0.2.3

    CRAN release: 2020-07-10

    -
    • Fixes for compatability with broom v0.7.0
    • -
    • Add tidiers for stlm() models
    • -
    -
    -

    sweep 0.2.2

    CRAN release: 2019-10-08

    -
    • Fixes for compatability with tidyquant v0.5.7
    • -
    -
    -

    sweep 0.2.1

    CRAN release: 2018-03-03

    -
    -
    -

    sweep 0.2.0

    CRAN release: 2017-07-26

    -
    • Change to timetk from timekit.
    • -
    • Fix Issue #2 - sw_tidy fails when auto.arima() returns no terms (coefficients).
    • -
    -
    -

    sweep 0.1.0

    CRAN release: 2017-07-03

    -
    • Initial release of sweep, a tool to “tidy” the forecast modeling and prediction workflow.
    • -
    -
    - - -
    - - - -
    - - - - - - - diff --git a/docs/pkgdown.css b/docs/pkgdown.css deleted file mode 100644 index 80ea5b8..0000000 --- a/docs/pkgdown.css +++ /dev/null @@ -1,384 +0,0 @@ -/* Sticky footer */ - -/** - * Basic idea: https://philipwalton.github.io/solved-by-flexbox/demos/sticky-footer/ - * Details: https://github.com/philipwalton/solved-by-flexbox/blob/master/assets/css/components/site.css - * - * .Site -> body > .container - * .Site-content -> body > .container .row - * .footer -> footer - * - * Key idea seems to be to ensure that .container and __all its parents__ - * have height set to 100% - * - */ - -html, body { - height: 100%; -} - -body { - position: relative; -} - -body > .container { - display: flex; - height: 100%; - flex-direction: column; -} - -body > .container .row { - flex: 1 0 auto; -} - -footer { - margin-top: 45px; - padding: 35px 0 36px; - border-top: 1px solid #e5e5e5; - color: #666; - display: flex; - flex-shrink: 0; -} -footer p { - margin-bottom: 0; -} -footer div { - flex: 1; -} -footer .pkgdown { - text-align: right; -} -footer p { - margin-bottom: 0; -} - -img.icon { - float: right; -} - -/* Ensure in-page images don't run outside their container */ -.contents img { - max-width: 100%; - height: auto; -} - -/* Fix bug in bootstrap (only seen in firefox) */ -summary { - display: list-item; -} - -/* Typographic tweaking ---------------------------------*/ - -.contents .page-header { - margin-top: calc(-60px + 1em); -} - -dd { - margin-left: 3em; -} - -/* Section anchors ---------------------------------*/ - -a.anchor { - display: none; - margin-left: 5px; - width: 20px; - height: 20px; - - background-image: url(./link.svg); - background-repeat: no-repeat; - background-size: 20px 20px; - background-position: center center; -} - -h1:hover .anchor, -h2:hover .anchor, -h3:hover .anchor, -h4:hover .anchor, -h5:hover .anchor, -h6:hover .anchor { - display: inline-block; -} - -/* Fixes for fixed navbar --------------------------*/ - -.contents h1, .contents h2, .contents h3, .contents h4 { - padding-top: 60px; - margin-top: -40px; -} - -/* Navbar submenu --------------------------*/ - -.dropdown-submenu { - position: relative; -} - -.dropdown-submenu>.dropdown-menu { - top: 0; - left: 100%; - margin-top: -6px; - margin-left: -1px; - border-radius: 0 6px 6px 6px; -} - -.dropdown-submenu:hover>.dropdown-menu { - display: block; -} - -.dropdown-submenu>a:after { - display: block; - content: " "; - float: right; - width: 0; - height: 0; - border-color: transparent; - border-style: solid; - border-width: 5px 0 5px 5px; - border-left-color: #cccccc; - margin-top: 5px; - margin-right: -10px; -} - -.dropdown-submenu:hover>a:after { - border-left-color: #ffffff; -} - -.dropdown-submenu.pull-left { - float: none; -} - -.dropdown-submenu.pull-left>.dropdown-menu { - left: -100%; - margin-left: 10px; - border-radius: 6px 0 6px 6px; -} - -/* Sidebar --------------------------*/ - -#pkgdown-sidebar { - margin-top: 30px; - position: -webkit-sticky; - position: sticky; - top: 70px; -} - -#pkgdown-sidebar h2 { - font-size: 1.5em; - margin-top: 1em; -} - -#pkgdown-sidebar h2:first-child { - margin-top: 0; -} - -#pkgdown-sidebar .list-unstyled li { - margin-bottom: 0.5em; -} - -/* bootstrap-toc tweaks ------------------------------------------------------*/ - -/* All levels of nav */ - -nav[data-toggle='toc'] .nav > li > a { - padding: 4px 20px 4px 6px; - font-size: 1.5rem; - font-weight: 400; - color: inherit; -} - -nav[data-toggle='toc'] .nav > li > a:hover, -nav[data-toggle='toc'] .nav > li > a:focus { - padding-left: 5px; - color: inherit; - border-left: 1px solid #878787; -} - -nav[data-toggle='toc'] .nav > .active > a, -nav[data-toggle='toc'] .nav > .active:hover > a, -nav[data-toggle='toc'] .nav > .active:focus > a { - padding-left: 5px; - font-size: 1.5rem; - font-weight: 400; - color: inherit; - border-left: 2px solid #878787; -} - -/* Nav: second level (shown on .active) */ - -nav[data-toggle='toc'] .nav .nav { - display: none; /* Hide by default, but at >768px, show it */ - padding-bottom: 10px; -} - -nav[data-toggle='toc'] .nav .nav > li > a { - padding-left: 16px; - font-size: 1.35rem; -} - -nav[data-toggle='toc'] .nav .nav > li > a:hover, -nav[data-toggle='toc'] .nav .nav > li > a:focus { - padding-left: 15px; -} - -nav[data-toggle='toc'] .nav .nav > .active > a, -nav[data-toggle='toc'] .nav .nav > .active:hover > a, -nav[data-toggle='toc'] .nav .nav > .active:focus > a { - padding-left: 15px; - font-weight: 500; - font-size: 1.35rem; -} - -/* orcid ------------------------------------------------------------------- */ - -.orcid { - font-size: 16px; - color: #A6CE39; - /* margins are required by official ORCID trademark and display guidelines */ - margin-left:4px; - margin-right:4px; - vertical-align: middle; -} - -/* Reference index & topics ----------------------------------------------- */ - -.ref-index th {font-weight: normal;} - -.ref-index td {vertical-align: top; min-width: 100px} -.ref-index .icon {width: 40px;} -.ref-index .alias {width: 40%;} -.ref-index-icons .alias {width: calc(40% - 40px);} -.ref-index .title {width: 60%;} - -.ref-arguments th {text-align: right; padding-right: 10px;} -.ref-arguments th, .ref-arguments td {vertical-align: top; min-width: 100px} -.ref-arguments .name {width: 20%;} -.ref-arguments .desc {width: 80%;} - -/* Nice scrolling for wide elements --------------------------------------- */ - -table { - display: block; - overflow: auto; -} - -/* Syntax highlighting ---------------------------------------------------- */ - -pre, code, pre code { - background-color: #f8f8f8; - color: #333; -} -pre, pre code { - white-space: pre-wrap; - word-break: break-all; - overflow-wrap: break-word; -} - -pre { - border: 1px solid #eee; -} - -pre .img, pre .r-plt { - margin: 5px 0; -} - -pre .img img, pre .r-plt img { - background-color: #fff; -} - -code a, pre a { - color: #375f84; -} - -a.sourceLine:hover { - text-decoration: none; -} - -.fl {color: #1514b5;} -.fu {color: #000000;} /* function */ -.ch,.st {color: #036a07;} /* string */ -.kw {color: #264D66;} /* keyword */ -.co {color: #888888;} /* comment */ - -.error {font-weight: bolder;} -.warning {font-weight: bolder;} - -/* Clipboard --------------------------*/ - -.hasCopyButton { - position: relative; -} - -.btn-copy-ex { - position: absolute; - right: 0; - top: 0; - visibility: hidden; -} - -.hasCopyButton:hover button.btn-copy-ex { - visibility: visible; -} - -/* headroom.js ------------------------ */ - -.headroom { - will-change: transform; - transition: transform 200ms linear; -} -.headroom--pinned { - transform: translateY(0%); -} -.headroom--unpinned { - transform: translateY(-100%); -} - -/* mark.js ----------------------------*/ - -mark { - background-color: rgba(255, 255, 51, 0.5); - border-bottom: 2px solid rgba(255, 153, 51, 0.3); - padding: 1px; -} - -/* vertical spacing after htmlwidgets */ -.html-widget { - margin-bottom: 10px; -} - -/* fontawesome ------------------------ */ - -.fab { - font-family: "Font Awesome 5 Brands" !important; -} - -/* don't display links in code chunks when printing */ -/* source: https://stackoverflow.com/a/10781533 */ -@media print { - code a:link:after, code a:visited:after { - content: ""; - } -} - -/* Section anchors --------------------------------- - Added in pandoc 2.11: https://github.com/jgm/pandoc-templates/commit/9904bf71 -*/ - -div.csl-bib-body { } -div.csl-entry { - clear: both; -} -.hanging-indent div.csl-entry { - margin-left:2em; - text-indent:-2em; -} -div.csl-left-margin { - min-width:2em; - float:left; -} -div.csl-right-inline { - margin-left:2em; - padding-left:1em; -} -div.csl-indent { - margin-left: 2em; -} diff --git a/docs/pkgdown.js b/docs/pkgdown.js deleted file mode 100644 index 5fccd9c..0000000 --- a/docs/pkgdown.js +++ /dev/null @@ -1,156 +0,0 @@ -/* http://gregfranko.com/blog/jquery-best-practices/ */ -(function($) { - $(function() { - - $('nav.navbar').headroom(); - - Toc.init({ - $nav: $("#toc"), - $scope: $("main h2, main h3, main h4, main h5, main h6") - }); - - if ($('#toc').length) { - $('body').scrollspy({ - target: '#toc', - offset: $("nav.navbar").outerHeight() + 1 - }); - } - - // Activate popovers - $('[data-bs-toggle="popover"]').popover({ - container: 'body', - html: true, - trigger: 'focus', - placement: "top", - sanitize: false, - }); - - $('[data-bs-toggle="tooltip"]').tooltip(); - - /* Clipboard --------------------------*/ - - function changeTooltipMessage(element, msg) { - var tooltipOriginalTitle=element.getAttribute('data-original-title'); - element.setAttribute('data-original-title', msg); - $(element).tooltip('show'); - element.setAttribute('data-original-title', tooltipOriginalTitle); - } - - if(ClipboardJS.isSupported()) { - $(document).ready(function() { - var copyButton = ""; - - $("div.sourceCode").addClass("hasCopyButton"); - - // Insert copy buttons: - $(copyButton).prependTo(".hasCopyButton"); - - // Initialize tooltips: - $('.btn-copy-ex').tooltip({container: 'body'}); - - // Initialize clipboard: - var clipboard = new ClipboardJS('[data-clipboard-copy]', { - text: function(trigger) { - return trigger.parentNode.textContent.replace(/\n#>[^\n]*/g, ""); - } - }); - - clipboard.on('success', function(e) { - changeTooltipMessage(e.trigger, 'Copied!'); - e.clearSelection(); - }); - - clipboard.on('error', function() { - changeTooltipMessage(e.trigger,'Press Ctrl+C or Command+C to copy'); - }); - - }); - } - - /* Search marking --------------------------*/ - var url = new URL(window.location.href); - var toMark = url.searchParams.get("q"); - var mark = new Mark("main#main"); - if (toMark) { - mark.mark(toMark, { - accuracy: { - value: "complementary", - limiters: [",", ".", ":", "/"], - } - }); - } - - /* Search --------------------------*/ - /* Adapted from https://github.com/rstudio/bookdown/blob/2d692ba4b61f1e466c92e78fd712b0ab08c11d31/inst/resources/bs4_book/bs4_book.js#L25 */ - // Initialise search index on focus - var fuse; - $("#search-input").focus(async function(e) { - if (fuse) { - return; - } - - $(e.target).addClass("loading"); - var response = await fetch($("#search-input").data("search-index")); - var data = await response.json(); - - var options = { - keys: ["what", "text", "code"], - ignoreLocation: true, - threshold: 0.1, - includeMatches: true, - includeScore: true, - }; - fuse = new Fuse(data, options); - - $(e.target).removeClass("loading"); - }); - - // Use algolia autocomplete - var options = { - autoselect: true, - debug: true, - hint: false, - minLength: 2, - }; - var q; -async function searchFuse(query, callback) { - await fuse; - - var items; - if (!fuse) { - items = []; - } else { - q = query; - var results = fuse.search(query, { limit: 20 }); - items = results - .filter((x) => x.score <= 0.75) - .map((x) => x.item); - if (items.length === 0) { - items = [{dir:"Sorry 😿",previous_headings:"",title:"No results found.",what:"No results found.",path:window.location.href}]; - } - } - callback(items); -} - $("#search-input").autocomplete(options, [ - { - name: "content", - source: searchFuse, - templates: { - suggestion: (s) => { - if (s.title == s.what) { - return `${s.dir} >
    ${s.title}
    `; - } else if (s.previous_headings == "") { - return `${s.dir} >
    ${s.title}
    > ${s.what}`; - } else { - return `${s.dir} >
    ${s.title}
    > ${s.previous_headings} > ${s.what}`; - } - }, - }, - }, - ]).on('autocomplete:selected', function(event, s) { - window.location.href = s.path + "?q=" + q + "#" + s.id; - }); - }); -})(window.jQuery || window.$) - - diff --git a/docs/pkgdown.yml b/docs/pkgdown.yml deleted file mode 100644 index 198845b..0000000 --- a/docs/pkgdown.yml +++ /dev/null @@ -1,12 +0,0 @@ -pandoc: 3.1.1 -pkgdown: 2.0.7 -pkgdown_sha: ~ -articles: - SW00_Introduction_to_sweep: SW00_Introduction_to_sweep.html - SW01_Forecasting_Time_Series_Groups: SW01_Forecasting_Time_Series_Groups.html - SW02_Forecasting_Multiple_Models: SW02_Forecasting_Multiple_Models.html -last_built: 2023-12-08T16:55Z -urls: - reference: https://business-science.github.io/sweep/reference - article: https://business-science.github.io/sweep/articles - diff --git a/docs/reference/Rplot001.png b/docs/reference/Rplot001.png deleted file mode 100644 index 17a3580..0000000 Binary files a/docs/reference/Rplot001.png and /dev/null differ diff --git a/docs/reference/add_index.html b/docs/reference/add_index.html deleted file mode 100644 index 999dd61..0000000 --- a/docs/reference/add_index.html +++ /dev/null @@ -1,114 +0,0 @@ - -Adds a sequential index column to a data frame — add_index • sweep - Skip to contents - - -
    -
    -
    - -
    -

    Adds a sequential index column to a data frame

    -
    - -
    -

    Usage

    -
    add_index(ret, rename_index)
    -
    - -
    -

    Arguments

    -
    ret
    -

    An object of class tibble

    - - -
    rename_index
    -

    A variable indicating the index name to be used in the -tibble returned

    - -
    - -
    - - -
    - - - -
    - - - - - - - diff --git a/docs/reference/arima_string.html b/docs/reference/arima_string.html deleted file mode 100644 index 7cc622c..0000000 --- a/docs/reference/arima_string.html +++ /dev/null @@ -1,116 +0,0 @@ - -Print the ARIMA model parameters — arima_string • sweep - Skip to contents - - -
    -
    -
    - -
    -

    Refer to forecast:::arima.string. -forecast arima.R

    -
    - -
    -

    Usage

    -
    arima_string(object, padding = FALSE)
    -
    - -
    -

    Arguments

    -
    object
    -

    An object of class Arima

    - - -
    padding
    -

    Add padding to the name returned

    - -
    - -
    - - -
    - - - -
    - - - - - - - diff --git a/docs/reference/bats_string.html b/docs/reference/bats_string.html deleted file mode 100644 index 7eb97b8..0000000 --- a/docs/reference/bats_string.html +++ /dev/null @@ -1,112 +0,0 @@ - -Print the BATS model parameters — bats_string • sweep - Skip to contents - - -
    -
    -
    - -
    -

    Refer to forecast:::makeText. -forecast bats.R

    -
    - -
    -

    Usage

    -
    bats_string(object)
    -
    - -
    -

    Arguments

    -
    object
    -

    An object of class bats

    - -
    - -
    - - -
    - - - -
    - - - - - - - diff --git a/docs/reference/bike_sales.html b/docs/reference/bike_sales.html deleted file mode 100644 index a75a70b..0000000 --- a/docs/reference/bike_sales.html +++ /dev/null @@ -1,183 +0,0 @@ - -Fictional sales data for bike shops purchasing Cannondale bikes — bike_sales • sweep - Skip to contents - - -
    -
    -
    - -
    -

    A dataset containing the fictional bicycle orders spanning 2011 through 2015. -Hypothetically, the bike_sales data are similar to sales data mainatained -in a business' sales data base. The unit price and model names come from -data provided by model for the bicycle manufacturer, Cannondale (2016). -The customers (bicycle shops) including name, location, etc and -the orders including quantity purchased and order dates are fictional. -The data is intended for implementing business analytics techniques -(e.g. forecast, clustering, etc) to identify underlying trends.

    -
    - -
    -

    Usage

    -
    bike_sales
    -
    - -
    -

    Format

    -

    A data frame with 15644 rows and 17 variables:

    order.date
    -

    Date the order was placed

    - -
    order.id
    -

    A unique order identification number

    - -
    order.line
    -

    The sequential identification number for products on and order

    - -
    quantity
    -

    Number of units purchased

    - -
    price
    -

    The unit price of the bicycle

    - -
    price.ext
    -

    The extended price = price x quantity

    - -
    customer.id
    -

    A unique customer identification number

    - -
    bikeshop.name
    -

    The customer name

    - -
    bikeshop.city
    -

    The city that the bike shop is located

    - -
    bikeshop.state
    -

    The state that the bike shop is located

    - -
    latitude
    -

    The geograhpic latitude of the customer location

    - -
    longitude
    -

    The geograhpic longitude of the customer location

    - -
    product.id
    -

    A unique product identification number

    - -
    model
    -

    The model name of the bicycle

    - -
    category.primary
    -

    The main bicycle category, either "Mountain" or "Road"

    - -
    category.secondary
    -

    One of nine more specific bicycle categories

    - -
    frame
    -

    The bicycle frame material, either "Carbon" or "Aluminum"

    - - -
    -
    -

    Source

    -

    The 2016 bicycle model names and prices originated from https://www.cannondale.com/en-us

    -
    - -
    - - -
    - - - -
    - - - - - - - diff --git a/docs/reference/figures/forecast.png b/docs/reference/figures/forecast.png deleted file mode 100644 index 5db3365..0000000 Binary files a/docs/reference/figures/forecast.png and /dev/null differ diff --git a/docs/reference/figures/multiple_models.png b/docs/reference/figures/multiple_models.png deleted file mode 100644 index 862618e..0000000 Binary files a/docs/reference/figures/multiple_models.png and /dev/null differ diff --git a/docs/reference/figures/sweep-logo.png b/docs/reference/figures/sweep-logo.png deleted file mode 100644 index 564a9a5..0000000 Binary files a/docs/reference/figures/sweep-logo.png and /dev/null differ diff --git a/docs/reference/figures/time_series_groups.png b/docs/reference/figures/time_series_groups.png deleted file mode 100644 index 07733d6..0000000 Binary files a/docs/reference/figures/time_series_groups.png and /dev/null differ diff --git a/docs/reference/index.html b/docs/reference/index.html deleted file mode 100644 index e7edebb..0000000 --- a/docs/reference/index.html +++ /dev/null @@ -1,220 +0,0 @@ - -Function reference • sweep - Skip to contents - - -
    -
    -
    - -
    -

    All functions

    - - - - -
    - - - - -
    - - add_index() -
    -
    Adds a sequential index column to a data frame
    -
    - - arima_string() -
    -
    Print the ARIMA model parameters
    -
    - - bats_string() -
    -
    Print the BATS model parameters
    -
    - - bike_sales -
    -
    Fictional sales data for bike shops purchasing Cannondale bikes
    -
    - - sw_augment() -
    -
    Augment data according to a tidied model
    -
    - - sw_augment(<default>) -
    -
    Default augment method
    -
    - - sw_augment_columns() -
    -
    Augments data
    -
    - - sw_glance() -
    -
    Construct a single row summary "glance" of a model, fit, or other -object
    -
    - - sw_glance(<default>) -
    -
    Default glance method
    -
    - - sw_sweep() -
    -
    Tidy forecast objects
    -
    - - sw_tidy() -
    -
    Tidy the result of a time-series model into a summary tibble
    -
    - - sw_tidy(<default>) -
    -
    Default tidying method
    -
    - - sw_tidy_decomp() -
    -
    Coerces decomposed time-series objects to tibble format.
    -
    - - tbats_string() -
    -
    Print the TBATS model parameters
    -
    - - sw_tidy(<HoltWinters>) sw_glance(<HoltWinters>) sw_augment(<HoltWinters>) sw_tidy_decomp(<HoltWinters>) -
    -
    Tidying methods for HoltWinters modeling of time series
    -
    - - sw_tidy(<StructTS>) sw_glance(<StructTS>) sw_augment(<StructTS>) -
    -
    Tidying methods for StructTS (Error, Trend, Seasonal) / exponential smoothing -modeling of time series
    -
    - - sw_tidy(<Arima>) sw_glance(<Arima>) sw_augment(<Arima>) sw_tidy(<stlm>) -
    -
    Tidying methods for ARIMA modeling of time series
    -
    - - sw_tidy(<bats>) sw_glance(<bats>) sw_augment(<bats>) sw_tidy_decomp(<bats>) -
    -
    Tidying methods for BATS and TBATS modeling of time series
    -
    - - sw_tidy_decomp(<decomposed.ts>) -
    -
    Tidying methods for decomposed time series
    -
    - - sw_tidy(<ets>) sw_glance(<ets>) sw_augment(<ets>) sw_tidy_decomp(<ets>) -
    -
    Tidying methods for ETS (Error, Trend, Seasonal) exponential smoothing -modeling of time series
    -
    - - sw_tidy(<nnetar>) sw_glance(<nnetar>) sw_augment(<nnetar>) -
    -
    Tidying methods for Nural Network Time Series models
    -
    - - sw_tidy(<stl>) sw_tidy_decomp(<stl>) sw_tidy_decomp(<stlm>) sw_glance(<stlm>) sw_augment(<stlm>) -
    -
    Tidying methods for STL (Seasonal, Trend, Level) decomposition of time series
    -
    - - validate_index() -
    -
    Validates data frame has column named the same name as variable rename_index
    -
    -
    - - -
    - - - -
    - - - - - - - diff --git a/docs/reference/reexports.html b/docs/reference/reexports.html deleted file mode 100644 index dc7e639..0000000 --- a/docs/reference/reexports.html +++ /dev/null @@ -1,117 +0,0 @@ - -Objects exported from other packages — reexports • sweep - Skip to contents - - -
    -
    -
    - -
    -

    These objects are imported from other packages. Follow the links -below to see their documentation.

    -
    dplyr
    -

    %>%

    - - -
    - - - -
    - - -
    - - - -
    - - - - - - - diff --git a/docs/reference/sw_augment.default.html b/docs/reference/sw_augment.default.html deleted file mode 100644 index 08eff91..0000000 --- a/docs/reference/sw_augment.default.html +++ /dev/null @@ -1,122 +0,0 @@ - -Default augment method — sw_augment.default • sweep - Skip to contents - - -
    -
    -
    - -
    -

    By default, sw_augment() uses broom::augment() to convert its output.

    -
    - -
    -

    Usage

    -
    # S3 method for default
    -sw_augment(x, ...)
    -
    - -
    -

    Arguments

    -
    x
    -

    an object to be tidied

    - - -
    ...
    -

    extra arguments passed to broom::augment()

    - -
    -
    -

    Value

    - - -

    A tibble generated by broom::augment()

    - - -
    - -
    - - -
    - - - -
    - - - - - - - diff --git a/docs/reference/sw_augment.html b/docs/reference/sw_augment.html deleted file mode 100644 index fb5376a..0000000 --- a/docs/reference/sw_augment.html +++ /dev/null @@ -1,132 +0,0 @@ - -Augment data according to a tidied model — sw_augment • sweep - Skip to contents - - -
    -
    -
    - -
    -

    Given an R statistical model or other non-tidy object, add columns to the -original dataset such as predictions, residuals and cluster assignments.

    -
    - -
    -

    Usage

    -
    sw_augment(x, ...)
    -
    - -
    -

    Arguments

    -
    x
    -

    model or other R object to convert to data frame

    - - -
    ...
    -

    other arguments passed to methods

    - -
    -
    -

    Details

    -

    sw_augment() is a wrapper for broom::augment(). The benefit of sw_augment -is that it has methods for various time-series model classes such as -HoltWinters, ets, Arima, etc.

    -

    For non-time series, sw_augment() defaults to broom::augment(). -The only difference is that the return is a tibble.

    -

    Note that by convention the first argument is almost always data, -which specifies the original data object. This is not part of the S3 -signature, partly because it prevents rowwise_df_tidiers from -taking a column name as the first argument.

    -
    -
    -

    See also

    - -
    - -
    - - -
    - - - -
    - - - - - - - diff --git a/docs/reference/sw_augment_columns.html b/docs/reference/sw_augment_columns.html deleted file mode 100644 index 8eb9220..0000000 --- a/docs/reference/sw_augment_columns.html +++ /dev/null @@ -1,122 +0,0 @@ - -Augments data — sw_augment_columns • sweep - Skip to contents - - -
    -
    -
    - -
    -

    Augments data

    -
    - -
    -

    Usage

    -
    sw_augment_columns(ret, data, rename_index, timetk_idx = FALSE)
    -
    - -
    -

    Arguments

    -
    ret
    -

    An object of class tibble

    - - -
    data
    -

    Any time series data that is to be augmented

    - - -
    rename_index
    -

    A variable indicating the index name to be used in the -tibble returned

    - - -
    timetk_idx
    -

    Uses the timetk index (irregular time index) if present.

    - -
    - -
    - - -
    - - - -
    - - - - - - - diff --git a/docs/reference/sw_glance.default.html b/docs/reference/sw_glance.default.html deleted file mode 100644 index 181c2de..0000000 --- a/docs/reference/sw_glance.default.html +++ /dev/null @@ -1,122 +0,0 @@ - -Default glance method — sw_glance.default • sweep - Skip to contents - - -
    -
    -
    - -
    -

    By default, sw_glance() uses broom::glance() to convert its output.

    -
    - -
    -

    Usage

    -
    # S3 method for default
    -sw_glance(x, ...)
    -
    - -
    -

    Arguments

    -
    x
    -

    an object to be tidied

    - - -
    ...
    -

    extra arguments passed to broom::glance()

    - -
    -
    -

    Value

    - - -

    A tibble generated by broom::glance()

    - - -
    - -
    - - -
    - - - -
    - - - - - - - diff --git a/docs/reference/sw_glance.html b/docs/reference/sw_glance.html deleted file mode 100644 index a40c8cd..0000000 --- a/docs/reference/sw_glance.html +++ /dev/null @@ -1,139 +0,0 @@ - -Construct a single row summary "glance" of a model, fit, or other -object — sw_glance • sweep - Skip to contents - - -
    -
    -
    - -
    -

    Construct a single row summary "glance" of a model, fit, or other -object

    -
    - -
    -

    Usage

    -
    sw_glance(x, ...)
    -
    - -
    -

    Arguments

    -
    x
    -

    model or other R object to convert to single-row data frame

    - - -
    ...
    -

    other arguments passed to methods

    - -
    -
    -

    Value

    - - -

    single-row tibble with model summary information.

    -
    -
    -

    Details

    -

    sw_glance() is a wrapper for broom::glance(). The benefit of sw_glance -is that it has methods for various time-series model classes such as -HoltWinters, ets, Arima, etc. -sw_glance methods always return either a one-row tibble or NULL. -The single row includes summary statistics relevent to the model accuracy, -which can be used to assess model fit and quality.

    -

    For non-time series, sw_glance() defaults to broom::glance(). -The only difference is that the return is a tibble.

    -
    -
    -

    See also

    - -
    - -
    - - -
    - - - -
    - - - - - - - diff --git a/docs/reference/sw_sweep.html b/docs/reference/sw_sweep.html deleted file mode 100644 index 61d593d..0000000 --- a/docs/reference/sw_sweep.html +++ /dev/null @@ -1,196 +0,0 @@ - -Tidy forecast objects — sw_sweep • sweep - Skip to contents - - -
    -
    -
    - -
    -

    Tidy forecast objects

    -
    - -
    -

    Usage

    -
    sw_sweep(x, fitted = FALSE, timetk_idx = FALSE, rename_index = "index", ...)
    -
    - -
    -

    Arguments

    -
    x
    -

    A time-series forecast of class forecast.

    - - -
    fitted
    -

    Whether or not to return the fitted values (model values) in the results. -FALSE by default.

    - - -
    timetk_idx
    -

    If timetk index (non-regularized index) is present, uses it -to develop forecast. Otherwise uses default index.

    - - -
    rename_index
    -

    Enables the index column to be renamed.

    - - -
    ...
    -

    Additional arguments passed to tk_make_future_timeseries()

    - -
    -
    -

    Value

    - - -

    Returns a tibble object.

    -
    -
    -

    Details

    -

    sw_sweep is designed -to coerce forecast objects from the forecast package -into tibble objects in a "tidy" format (long). -The returned object contains both the actual values -and the forecasted values including the point forecast and upper and lower -confidence intervals.

    -

    The timetk_idx argument is used to modify the return format of the index.

    • If timetk_idx = FALSE, a regularized time index is always constructed. -This may be in the format of numeric values (e.g. 2010.000) or the -higher order yearmon and yearqtr classes from the zoo package. -A higher order class is attempted to be returned.

    • -
    • If timetk_idx = TRUE and a timetk index is present, an irregular time index -will be returned that combines the original time series (i.e. date or datetime) -along with a computed future time series created using tk_make_future_timeseries() -from the timetk package. The ... can be used to pass additional arguments -to tk_make_future_timeseries() such as inspect_weekdays, skip_values, etc -that can be useful in tuning the future time series sequence.

    • -

    The index column name can be changed using the rename_index argument.

    -
    -
    -

    See also

    -

    tk_make_future_timeseries()

    -
    - -
    -

    Examples

    -
    library(forecast)
    -#> Registered S3 method overwritten by 'quantmod':
    -#>   method            from
    -#>   as.zoo.data.frame zoo 
    -library(dplyr)
    -#> 
    -#> Attaching package: ‘dplyr’
    -#> The following objects are masked from ‘package:stats’:
    -#> 
    -#>     filter, lag
    -#> The following objects are masked from ‘package:base’:
    -#> 
    -#>     intersect, setdiff, setequal, union
    -
    -# ETS forecasts
    -USAccDeaths %>%
    -    ets() %>%
    -    forecast(level = c(80, 95, 99)) %>%
    -    sw_sweep()
    -#> # A tibble: 96 × 9
    -#>    index     key    value lo.80 lo.95 lo.99 hi.80 hi.95 hi.99
    -#>    <yearmon> <chr>  <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
    -#>  1 Jan 1973  actual  9007    NA    NA    NA    NA    NA    NA
    -#>  2 Feb 1973  actual  8106    NA    NA    NA    NA    NA    NA
    -#>  3 Mar 1973  actual  8928    NA    NA    NA    NA    NA    NA
    -#>  4 Apr 1973  actual  9137    NA    NA    NA    NA    NA    NA
    -#>  5 May 1973  actual 10017    NA    NA    NA    NA    NA    NA
    -#>  6 Jun 1973  actual 10826    NA    NA    NA    NA    NA    NA
    -#>  7 Jul 1973  actual 11317    NA    NA    NA    NA    NA    NA
    -#>  8 Aug 1973  actual 10744    NA    NA    NA    NA    NA    NA
    -#>  9 Sep 1973  actual  9713    NA    NA    NA    NA    NA    NA
    -#> 10 Oct 1973  actual  9938    NA    NA    NA    NA    NA    NA
    -#> # ℹ 86 more rows
    -
    -
    -
    -
    -
    - - -
    - - - -
    - - - - - - - diff --git a/docs/reference/sw_tidy.default.html b/docs/reference/sw_tidy.default.html deleted file mode 100644 index 22f33cf..0000000 --- a/docs/reference/sw_tidy.default.html +++ /dev/null @@ -1,122 +0,0 @@ - -Default tidying method — sw_tidy.default • sweep - Skip to contents - - -
    -
    -
    - -
    -

    By default, sw_tidy() uses broom::tidy() to convert its output.

    -
    - -
    -

    Usage

    -
    # S3 method for default
    -sw_tidy(x, ...)
    -
    - -
    -

    Arguments

    -
    x
    -

    an object to be tidied

    - - -
    ...
    -

    extra arguments passed to broom::tidy()

    - -
    -
    -

    Value

    - - -

    A tibble generated by broom::tidy()

    - - -
    - -
    - - -
    - - - -
    - - - - - - - diff --git a/docs/reference/sw_tidy.html b/docs/reference/sw_tidy.html deleted file mode 100644 index 71067ee..0000000 --- a/docs/reference/sw_tidy.html +++ /dev/null @@ -1,151 +0,0 @@ - -Tidy the result of a time-series model into a summary tibble — sw_tidy • sweep - Skip to contents - - -
    -
    -
    - -
    -

    Tidy the result of a time-series model into a summary tibble

    -
    - -
    -

    Usage

    -
    sw_tidy(x, ...)
    -
    - -
    -

    Arguments

    -
    x
    -

    An object to be converted into a tibble ("tidy" data.frame)

    - - -
    ...
    -

    extra arguments

    - -
    -
    -

    Value

    - - -

    a tibble

    -
    -
    -

    Details

    -

    sw_tidy() is a wrapper for broom::tidy(). The main benefit of sw_tidy() -is that it has methods for various time-series model classes such as -HoltWinters, ets, Arima, etc. -sw_tidy() methods always returns a "tidy" tibble with model coefficient / parameters.

    -

    For non-time series, sw_tidy() defaults to broom::tidy(). -The only difference is that the return is a tibble. -The output of sw_tidy() is always a tibble with disposable row names. It is -therefore suited for further manipulation by packages like dplyr and -ggplot2.

    -
    -
    -

    See also

    - -
    - -
    -

    Examples

    -
    library(dplyr)
    -library(forecast)
    -
    -WWWusage %>%
    -    auto.arima() %>%
    -    sw_tidy(conf.int = TRUE)
    -#> # A tibble: 2 × 2
    -#>   term  estimate
    -#>   <chr>    <dbl>
    -#> 1 ar1      0.650
    -#> 2 ma1      0.526
    -
    -
    -
    -
    - - -
    - - - -
    - - - - - - - diff --git a/docs/reference/sw_tidy_decomp.html b/docs/reference/sw_tidy_decomp.html deleted file mode 100644 index 34264b5..0000000 --- a/docs/reference/sw_tidy_decomp.html +++ /dev/null @@ -1,183 +0,0 @@ - -Coerces decomposed time-series objects to tibble format. — sw_tidy_decomp • sweep - Skip to contents - - -
    -
    -
    - -
    -

    Coerces decomposed time-series objects to tibble format.

    -
    - -
    -

    Usage

    -
    sw_tidy_decomp(x, timetk_idx = FALSE, rename_index = "index", ...)
    -
    - -
    -

    Arguments

    -
    x
    -

    A time-series object of class stl, ets, decomposed.ts, HoltWinters, -bats or tbats.

    - - -
    timetk_idx
    -

    When TRUE, uses a timetk index (irregular, typically date or datetime) if present.

    - - -
    rename_index
    -

    Enables the index column to be renamed.

    - - -
    ...
    -

    Not used.

    - -
    -
    -

    Value

    - - -

    Returns a tibble object.

    -
    -
    -

    Details

    -

    sw_tidy_decomp is designed -to coerce time-series objects with decompositions to tibble objects.

    -

    A regularized time index is always constructed. If no time index is -detected, a sequential index is returned as a default. -The index column name can be changed using the rename_index argument.

    -
    - -
    -

    Examples

    -
    library(dplyr)
    -library(forecast)
    -library(sweep)
    -
    -# Decompose ETS model
    -USAccDeaths %>%
    -    ets() %>%
    -    sw_tidy_decomp()
    -#> # A tibble: 73 × 4
    -#>    index     observed level  season
    -#>    <yearmon>    <dbl> <dbl>   <dbl>
    -#>  1 Dec 1972        NA 9248.   -51.3
    -#>  2 Jan 1973      9007 9544.  -738. 
    -#>  3 Feb 1973      8106 9603. -1538. 
    -#>  4 Mar 1973      8928 9642.  -740. 
    -#>  5 Apr 1973      9137 9633.  -490. 
    -#>  6 May 1973     10017 9679.   307. 
    -#>  7 Jun 1973     10826 9911.   757. 
    -#>  8 Jul 1973     11317 9746.  1683. 
    -#>  9 Aug 1973     10744 9762.   971. 
    -#> 10 Sep 1973      9713 9805.  -122. 
    -#> # ℹ 63 more rows
    -
    -# Decompose STL object
    -USAccDeaths %>%
    -    stl(s.window = 'periodic') %>%
    -    sw_tidy_decomp()
    -#> # A tibble: 72 × 6
    -#>    index     observed  season trend remainder seasadj
    -#>    <yearmon>    <dbl>   <dbl> <dbl>     <dbl>   <dbl>
    -#>  1 Jan 1973      9007  -820.  9935.    -108.    9827.
    -#>  2 Feb 1973      8106 -1559.  9881.    -216.    9665.
    -#>  3 Mar 1973      8928  -760.  9827.    -139.    9688.
    -#>  4 Apr 1973      9137  -530.  9766.     -98.2   9667.
    -#>  5 May 1973     10017   335.  9704.     -22.0   9682.
    -#>  6 Jun 1973     10826   815.  9637.     374.   10011.
    -#>  7 Jul 1973     11317  1682.  9569.      65.9   9635.
    -#>  8 Aug 1973     10744   982.  9500.     262.    9762.
    -#>  9 Sep 1973      9713   -62.8 9431.     345.    9776.
    -#> 10 Oct 1973      9938   232.  9343.     363.    9706.
    -#> # ℹ 62 more rows
    -
    -
    -
    -
    -
    - - -
    - - - -
    - - - - - - - diff --git a/docs/reference/sweep_package.html b/docs/reference/sweep_package.html deleted file mode 100644 index 36e16c9..0000000 --- a/docs/reference/sweep_package.html +++ /dev/null @@ -1,118 +0,0 @@ - -sweep: Extending broom to time series forecasting — sweep_package • sweep - - -
    -
    - - - -
    -
    - - -
    -

    The sweep package "tidies" up the -modeling workflow of the forecast package.

    -
    - - -
    -

    Details

    -

    The model and forecast objects are not covered by -the broom package. It includes the sw_tidy(), sw_glance(), -and sw_augment() functions that work in a similar capacity as broom functions. -In addition, it provides sw_tidy_decomp() to tidy decompositions, and -sw_sweep() to coerce forecast objects to "tibbles" for easy visualization with ggplot2 -and manipulation with dplyr.

    -

    To learn more about sweep, start with the vignettes: -browseVignettes(package = "sweep")

    -
    - -
    - -
    - - -
    - -
    -

    Site built with pkgdown 2.0.6.

    -
    - -
    - - - - - - - - diff --git a/docs/reference/tbats_string.html b/docs/reference/tbats_string.html deleted file mode 100644 index 7f2de89..0000000 --- a/docs/reference/tbats_string.html +++ /dev/null @@ -1,112 +0,0 @@ - -Print the TBATS model parameters — tbats_string • sweep - Skip to contents - - -
    -
    -
    - -
    -

    Refer to forecast:::makeTextTBATS. -forecast bats.R

    -
    - -
    -

    Usage

    -
    tbats_string(object)
    -
    - -
    -

    Arguments

    -
    object
    -

    An object of class bats or tbats

    - -
    - -
    - - -
    - - - -
    - - - - - - - diff --git a/docs/reference/tidiers_HoltWinters.html b/docs/reference/tidiers_HoltWinters.html deleted file mode 100644 index 9896635..0000000 --- a/docs/reference/tidiers_HoltWinters.html +++ /dev/null @@ -1,245 +0,0 @@ - -Tidying methods for HoltWinters modeling of time series — tidiers_HoltWinters • sweep - Skip to contents - - -
    -
    -
    - -
    -

    These methods tidy HoltWinters models of univariate time -series.

    -
    - -
    -

    Usage

    -
    # S3 method for HoltWinters
    -sw_tidy(x, ...)
    -
    -# S3 method for HoltWinters
    -sw_glance(x, ...)
    -
    -# S3 method for HoltWinters
    -sw_augment(x, data = NULL, rename_index = "index", timetk_idx = FALSE, ...)
    -
    -# S3 method for HoltWinters
    -sw_tidy_decomp(x, timetk_idx = FALSE, rename_index = "index", ...)
    -
    - -
    -

    Arguments

    -
    x
    -

    An object of class "HoltWinters"

    - - -
    ...
    -

    Additional parameters (not used)

    - - -
    data
    -

    Used with sw_augment only. -NULL by default which simply returns augmented columns only. -User can supply the original data, which returns the data + augmented columns.

    - - -
    rename_index
    -

    Used with sw_augment only. -A string representing the name of the index generated.

    - - -
    timetk_idx
    -

    Used with sw_augment and sw_tidy_decomp. -When TRUE, uses a timetk index (irregular, typically date or datetime) if present.

    - -
    -
    -

    Value

    - - -

    sw_tidy() returns one row for each model parameter, -with two columns:

    • term: The various parameters (alpha, beta, gamma, and coefficients)

    • -
    • estimate: The estimated parameter value

    • -

    sw_glance() returns one row with the following columns:

    • model.desc: A description of the model

    • -
    • sigma: The square root of the estimated residual variance

    • -
    • logLik: The data's log-likelihood under the model

    • -
    • AIC: The Akaike Information Criterion

    • -
    • BIC: The Bayesian Information Criterion (NA for bats / tbats)

    • -
    • ME: Mean error

    • -
    • RMSE: Root mean squared error

    • -
    • MAE: Mean absolute error

    • -
    • MPE: Mean percentage error

    • -
    • MAPE: Mean absolute percentage error

    • -
    • MASE: Mean absolute scaled error

    • -
    • ACF1: Autocorrelation of errors at lag 1

    • -

    sw_augment() returns a tibble with the following time series attributes:

    • index: An index is either attempted to be extracted from the model or -a sequential index is created for plotting purposes

    • -
    • .actual: The original time series

    • -
    • .fitted: The fitted values from the model

    • -
    • .resid: The residual values from the model

    • -

    sw_tidy_decomp() returns a tibble with the following time series attributes:

    • index: An index is either attempted to be extracted from the model or -a sequential index is created for plotting purposes

    • -
    • observed: The original time series

    • -
    • season: The seasonal component

    • -
    • trend: The trend component

    • -
    • remainder: observed - (season + trend)

    • -
    • seasadj: observed - season (or trend + remainder)

    • -
    -
    -

    See also

    - -
    - -
    -

    Examples

    -
    library(dplyr)
    -library(forecast)
    -
    -fit_hw <- USAccDeaths %>%
    -    stats::HoltWinters()
    -
    -sw_tidy(fit_hw)
    -#> # A tibble: 17 × 2
    -#>    term    estimate
    -#>    <chr>      <dbl>
    -#>  1 alpha     0.738 
    -#>  2 beta      0.0223
    -#>  3 gamma     1     
    -#>  4 a      8799.    
    -#>  5 b       -22.7   
    -#>  6 s1     -802.    
    -#>  7 s2    -1740.    
    -#>  8 s3     -960.    
    -#>  9 s4     -594.    
    -#> 10 s5      259.    
    -#> 11 s6      674.    
    -#> 12 s7     1771.    
    -#> 13 s8     1031.    
    -#> 14 s9      211.    
    -#> 15 s10     549.    
    -#> 16 s11     128.    
    -#> 17 s12     441.    
    -sw_glance(fit_hw)
    -#> # A tibble: 1 × 12
    -#>   model.desc sigma logLik AIC   BIC      ME  RMSE   MAE   MPE  MAPE  MASE   ACF1
    -#>   <chr>      <dbl> <lgl>  <lgl> <lgl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>  <dbl>
    -#> 1 HoltWinte… 2939. NA     NA    NA     61.4  379.  274. 0.727  3.21 0.626 0.0569
    -sw_augment(fit_hw)
    -#> # A tibble: 72 × 4
    -#>    index     .actual .fitted .resid
    -#>    <yearmon>   <dbl>   <dbl>  <dbl>
    -#>  1 Jan 1973     9007      NA     NA
    -#>  2 Feb 1973     8106      NA     NA
    -#>  3 Mar 1973     8928      NA     NA
    -#>  4 Apr 1973     9137      NA     NA
    -#>  5 May 1973    10017      NA     NA
    -#>  6 Jun 1973    10826      NA     NA
    -#>  7 Jul 1973    11317      NA     NA
    -#>  8 Aug 1973    10744      NA     NA
    -#>  9 Sep 1973     9713      NA     NA
    -#> 10 Oct 1973     9938      NA     NA
    -#> # ℹ 62 more rows
    -sw_tidy_decomp(fit_hw)
    -#> # A tibble: 72 × 6
    -#>    index     observed season trend remainder seasadj
    -#>    <yearmon>    <dbl>  <dbl> <dbl>     <dbl>   <dbl>
    -#>  1 Jan 1973      9007     NA    NA        NA      NA
    -#>  2 Feb 1973      8106     NA    NA        NA      NA
    -#>  3 Mar 1973      8928     NA    NA        NA      NA
    -#>  4 Apr 1973      9137     NA    NA        NA      NA
    -#>  5 May 1973     10017     NA    NA        NA      NA
    -#>  6 Jun 1973     10826     NA    NA        NA      NA
    -#>  7 Jul 1973     11317     NA    NA        NA      NA
    -#>  8 Aug 1973     10744     NA    NA        NA      NA
    -#>  9 Sep 1973      9713     NA    NA        NA      NA
    -#> 10 Oct 1973      9938     NA    NA        NA      NA
    -#> # ℹ 62 more rows
    -
    -
    -
    -
    - - -
    - - - -
    - - - - - - - diff --git a/docs/reference/tidiers_StructTS.html b/docs/reference/tidiers_StructTS.html deleted file mode 100644 index 9fe320c..0000000 --- a/docs/reference/tidiers_StructTS.html +++ /dev/null @@ -1,212 +0,0 @@ - -Tidying methods for StructTS (Error, Trend, Seasonal) / exponential smoothing -modeling of time series — tidiers_StructTS • sweep - Skip to contents - - -
    -
    -
    - -
    -

    These methods tidy the coefficients of StructTS models of univariate time -series.

    -
    - -
    -

    Usage

    -
    # S3 method for StructTS
    -sw_tidy(x, ...)
    -
    -# S3 method for StructTS
    -sw_glance(x, ...)
    -
    -# S3 method for StructTS
    -sw_augment(x, data = NULL, timetk_idx = FALSE, rename_index = "index", ...)
    -
    - -
    -

    Arguments

    -
    x
    -

    An object of class "StructTS"

    - - -
    ...
    -

    Additional parameters (not used)

    - - -
    data
    -

    Used with sw_augment only. -NULL by default which simply returns augmented columns only. -User can supply the original data, which returns the data + augmented columns.

    - - -
    timetk_idx
    -

    Used with sw_augment only. -Uses a irregular timetk index if present.

    - - -
    rename_index
    -

    Used with sw_augment only. -A string representing the name of the index generated.

    - -
    -
    -

    Value

    - - -

    sw_tidy() returns one row for each model parameter, -with two columns:

    • term: The model parameters

    • -
    • estimate: The estimated parameter value

    • -

    sw_glance() returns one row with the columns

    • model.desc: A description of the model including the -three integer components (p, d, q) are the AR order, -the degree of differencing, and the MA order.

    • -
    • sigma: The square root of the estimated residual variance

    • -
    • logLik: The data's log-likelihood under the model

    • -
    • AIC: The Akaike Information Criterion

    • -
    • BIC: The Bayesian Information Criterion

    • -
    • ME: Mean error

    • -
    • RMSE: Root mean squared error

    • -
    • MAE: Mean absolute error

    • -
    • MPE: Mean percentage error

    • -
    • MAPE: Mean absolute percentage error

    • -
    • MASE: Mean absolute scaled error

    • -
    • ACF1: Autocorrelation of errors at lag 1

    • -

    sw_augment() returns a tibble with the following time series attributes:

    • index: An index is either attempted to be extracted from the model or -a sequential index is created for plotting purposes

    • -
    • .actual: The original time series

    • -
    • .fitted: The fitted values from the model

    • -
    • .resid: The residual values from the model

    • -
    -
    -

    See also

    - -
    - -
    -

    Examples

    -
    library(dplyr)
    -library(forecast)
    -
    -fit_StructTS <- WWWusage %>%
    -    StructTS()
    -
    -sw_tidy(fit_StructTS)
    -#> # A tibble: 3 × 2
    -#>   term    estimate
    -#>   <chr>      <dbl>
    -#> 1 level        0  
    -#> 2 slope       13.0
    -#> 3 epsilon      0  
    -sw_glance(fit_StructTS)
    -#> # A tibble: 1 × 12
    -#>   model.desc      sigma logLik   AIC   BIC      ME  RMSE   MAE   MPE  MAPE  MASE
    -#>   <chr>           <dbl>  <dbl> <dbl> <dbl>   <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
    -#> 1 Local linear s… 0.995  -277.  559.  564. -0.0200  3.59  2.96 0.140  2.32 0.654
    -#> # ℹ 1 more variable: ACF1 <dbl>
    -sw_augment(fit_StructTS)
    -#> # A tibble: 100 × 4
    -#>    index .actual .fitted .resid
    -#>    <int>   <dbl>   <dbl>  <dbl>
    -#>  1     1      88    88     0   
    -#>  2     2      84    88.0  -4.00
    -#>  3     3      85    80     5   
    -#>  4     4      85    86    -1   
    -#>  5     5      84    85    -1   
    -#>  6     6      85    83     2   
    -#>  7     7      83    86    -3   
    -#>  8     8      85    81     4   
    -#>  9     9      88    87     1   
    -#> 10    10      89    91    -2   
    -#> # ℹ 90 more rows
    -
    -
    -
    -
    - - -
    - - - -
    - - - - - - - diff --git a/docs/reference/tidiers_arima.html b/docs/reference/tidiers_arima.html deleted file mode 100644 index 554a575..0000000 --- a/docs/reference/tidiers_arima.html +++ /dev/null @@ -1,218 +0,0 @@ - -Tidying methods for ARIMA modeling of time series — tidiers_arima • sweep - Skip to contents - - -
    -
    -
    - -
    -

    These methods tidy the coefficients of ARIMA models of univariate time -series.

    -
    - -
    -

    Usage

    -
    # S3 method for Arima
    -sw_tidy(x, ...)
    -
    -# S3 method for Arima
    -sw_glance(x, ...)
    -
    -# S3 method for Arima
    -sw_augment(x, data = NULL, rename_index = "index", timetk_idx = FALSE, ...)
    -
    -# S3 method for stlm
    -sw_tidy(x, ...)
    -
    - -
    -

    Arguments

    -
    x
    -

    An object of class "Arima"

    - - -
    ...
    -

    Additional parameters (not used)

    - - -
    data
    -

    Used with sw_augment only. -NULL by default which simply returns augmented columns only. -User can supply the original data, which returns the data + augmented columns.

    - - -
    rename_index
    -

    Used with sw_augment only. -A string representing the name of the index generated.

    - - -
    timetk_idx
    -

    Used with sw_augment only. -Uses a irregular timetk index if present.

    - -
    -
    -

    Value

    - - -

    sw_tidy() returns one row for each coefficient in the model, -with five columns:

    • term: The term in the nonlinear model being estimated and tested

    • -
    • estimate: The estimated coefficient

    • -

    sw_glance() returns one row with the columns

    • model.desc: A description of the model including the -three integer components (p, d, q) are the AR order, -the degree of differencing, and the MA order.

    • -
    • sigma: The square root of the estimated residual variance

    • -
    • logLik: The data's log-likelihood under the model

    • -
    • AIC: The Akaike Information Criterion

    • -
    • BIC: The Bayesian Information Criterion

    • -
    • ME: Mean error

    • -
    • RMSE: Root mean squared error

    • -
    • MAE: Mean absolute error

    • -
    • MPE: Mean percentage error

    • -
    • MAPE: Mean absolute percentage error

    • -
    • MASE: Mean absolute scaled error

    • -
    • ACF1: Autocorrelation of errors at lag 1

    • -

    sw_augment() returns a tibble with the following time series attributes:

    • index: An index is either attempted to be extracted from the model or -a sequential index is created for plotting purposes

    • -
    • .actual: The original time series

    • -
    • .fitted: The fitted values from the model

    • -
    • .resid: The residual values from the model

    • -

    sw_tidy() returns the underlying ETS or ARIMA model's sw_tidy()

    - - -

    one row for each coefficient in the model, -with five columns:

    • term: The term in the nonlinear model being estimated and tested

    • -
    • estimate: The estimated coefficient

    • -
    -
    -

    See also

    - -
    - -
    -

    Examples

    -
    library(dplyr)
    -library(forecast)
    -
    -fit_arima <- WWWusage %>%
    -    auto.arima()
    -
    -sw_tidy(fit_arima)
    -#> # A tibble: 2 × 2
    -#>   term  estimate
    -#>   <chr>    <dbl>
    -#> 1 ar1      0.650
    -#> 2 ma1      0.526
    -sw_glance(fit_arima)
    -#> # A tibble: 1 × 12
    -#>   model.desc   sigma logLik   AIC   BIC    ME  RMSE   MAE   MPE  MAPE  MASE
    -#>   <chr>        <dbl>  <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
    -#> 1 ARIMA(1,1,1)  3.16  -254.  514.  522. 0.304  3.11  2.41 0.281  1.92 0.532
    -#> # ℹ 1 more variable: ACF1 <dbl>
    -sw_augment(fit_arima)
    -#> # A tibble: 100 × 4
    -#>    index .actual .fitted  .resid
    -#>    <int>   <dbl>   <dbl>   <dbl>
    -#>  1     1      88    87.9  0.0880
    -#>  2     2      84    86.2 -2.17  
    -#>  3     3      85    81.1  3.86  
    -#>  4     4      85    87.5 -2.45  
    -#>  5     5      84    83.7  0.259 
    -#>  6     6      85    83.5  1.51  
    -#>  7     7      83    86.4 -3.44  
    -#>  8     8      85    79.9  5.11  
    -#>  9     9      88    89.0 -0.985 
    -#> 10    10      89    89.4 -0.433 
    -#> # ℹ 90 more rows
    -
    -
    -
    -
    -
    - - -
    - - - -
    - - - - - - - diff --git a/docs/reference/tidiers_bats.html b/docs/reference/tidiers_bats.html deleted file mode 100644 index d1533b7..0000000 --- a/docs/reference/tidiers_bats.html +++ /dev/null @@ -1,218 +0,0 @@ - -Tidying methods for BATS and TBATS modeling of time series — tidiers_bats • sweep - Skip to contents - - -
    -
    -
    - -
    -

    Tidying methods for BATS and TBATS modeling of time series

    -
    - -
    -

    Usage

    -
    # S3 method for bats
    -sw_tidy(x, ...)
    -
    -# S3 method for bats
    -sw_glance(x, ...)
    -
    -# S3 method for bats
    -sw_augment(x, data = NULL, rename_index = "index", timetk_idx = FALSE, ...)
    -
    -# S3 method for bats
    -sw_tidy_decomp(x, timetk_idx = FALSE, rename_index = "index", ...)
    -
    - -
    -

    Arguments

    -
    x
    -

    An object of class "bats" or "tbats"

    - - -
    ...
    -

    Additional parameters (not used)

    - - -
    data
    -

    Used with sw_augment only. -NULL by default which simply returns augmented columns only. -User can supply the original data, which returns the data + augmented columns.

    - - -
    rename_index
    -

    Used with sw_augment only. -A string representing the name of the index generated.

    - - -
    timetk_idx
    -

    Used with sw_augment and sw_tidy_decomp. -When TRUE, uses a timetk index (irregular, typically date or datetime) if present.

    - -
    -
    -

    Value

    - - -

    sw_tidy() returns one row for each model parameter, -with two columns:

    • term: The various parameters (lambda, alpha, gamma, etc)

    • -
    • estimate: The estimated parameter value

    • -

    sw_glance() returns one row with the columns

    • model.desc: A description of the model including the -three integer components (p, d, q) are the AR order, -the degree of differencing, and the MA order.

    • -
    • sigma: The square root of the estimated residual variance

    • -
    • logLik: The data's log-likelihood under the model

    • -
    • AIC: The Akaike Information Criterion

    • -
    • BIC: The Bayesian Information Criterion (NA for bats / tbats)

    • -
    • ME: Mean error

    • -
    • RMSE: Root mean squared error

    • -
    • MAE: Mean absolute error

    • -
    • MPE: Mean percentage error

    • -
    • MAPE: Mean absolute percentage error

    • -
    • MASE: Mean absolute scaled error

    • -
    • ACF1: Autocorrelation of errors at lag 1

    • -

    sw_augment() returns a tibble with the following time series attributes:

    • index: An index is either attempted to be extracted from the model or -a sequential index is created for plotting purposes

    • -
    • .actual: The original time series

    • -
    • .fitted: The fitted values from the model

    • -
    • .resid: The residual values from the model

    • -

    sw_tidy_decomp() returns a tibble with the following time series attributes:

    • index: An index is either attempted to be extracted from the model or -a sequential index is created for plotting purposes

    • -
    • observed: The original time series

    • -
    • level: The level component

    • -
    • slope: The slope component (Not always present)

    • -
    • season: The seasonal component (Not always present)

    • -
    -
    -

    See also

    - -
    - -
    -

    Examples

    -
    library(dplyr)
    -library(forecast)
    -
    -fit_bats <- WWWusage %>%
    -    bats()
    -
    -sw_tidy(fit_bats)
    -#> # A tibble: 7 × 2
    -#>   term              estimate
    -#>   <chr>                <dbl>
    -#> 1 lambda               1.00 
    -#> 2 alpha                1.52 
    -#> 3 beta                NA    
    -#> 4 damping.parameter   NA    
    -#> 5 gamma.values        NA    
    -#> 6 ar.coefficients     NA    
    -#> 7 ma.coefficients     -0.666
    -sw_glance(fit_bats)
    -#> # A tibble: 1 × 12
    -#>   model.desc sigma logLik   AIC   BIC    ME  RMSE   MAE   MPE  MAPE  MASE   ACF1
    -#>   <chr>      <dbl>  <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>  <dbl>
    -#> 1 BATS(1, {…  3.47   709.  727.  732. 0.217  3.47  2.62 0.261  2.13 0.579 0.0445
    -sw_augment(fit_bats)
    -#> # A tibble: 100 × 4
    -#>    index .actual .fitted  .resid
    -#>    <int>   <dbl>   <dbl>   <dbl>
    -#>  1     1      88   101.  -12.7  
    -#>  2     2      84    75.6   8.38 
    -#>  3     3      85    85.5  -0.453
    -#>  4     4      85    84.1   0.867
    -#>  5     5      84    84.8  -0.818
    -#>  6     6      85    82.7   2.30 
    -#>  7     7      83    86.3  -3.29 
    -#>  8     8      85    80.2   4.78 
    -#>  9     9      88    88.1  -0.125
    -#> 10    10      89    89.3  -0.284
    -#> # ℹ 90 more rows
    -
    -
    -
    -
    - - -
    - - - -
    - - - - - - - diff --git a/docs/reference/tidiers_decomposed_ts.html b/docs/reference/tidiers_decomposed_ts.html deleted file mode 100644 index f6011cb..0000000 --- a/docs/reference/tidiers_decomposed_ts.html +++ /dev/null @@ -1,165 +0,0 @@ - -Tidying methods for decomposed time series — tidiers_decomposed_ts • sweep - Skip to contents - - -
    -
    -
    - -
    -

    Tidying methods for decomposed time series

    -
    - -
    -

    Usage

    -
    # S3 method for decomposed.ts
    -sw_tidy_decomp(x, timetk_idx = FALSE, rename_index = "index", ...)
    -
    - -
    -

    Arguments

    -
    x
    -

    An object of class "decomposed.ts"

    - - -
    timetk_idx
    -

    Used with sw_augment and sw_tidy_decomp. -When TRUE, uses a timetk index (irregular, typically date or datetime) if present.

    - - -
    rename_index
    -

    Used with sw_augment and sw_tidy_decomp. -A string representing the name of the index generated.

    - - -
    ...
    -

    Not used.

    - -
    -
    -

    Value

    - - -

    sw_tidy_decomp() returns a tibble with the following time series attributes:

    • index: An index is either attempted to be extracted from the model or -a sequential index is created for plotting purposes

    • -
    • season: The seasonal component

    • -
    • trend: The trend component

    • -
    • random: The error component

    • -
    • seasadj: observed - season

    • -
    -
    -

    See also

    - -
    - -
    -

    Examples

    -
    library(dplyr)
    -library(forecast)
    -
    -fit_decomposed <- USAccDeaths %>%
    -    decompose()
    -
    -sw_tidy_decomp(fit_decomposed)
    -#> # A tibble: 72 × 6
    -#>    index     observed season trend random seasadj
    -#>    <yearmon>    <dbl>  <dbl> <dbl>  <dbl>   <dbl>
    -#>  1 Jan 1973      9007  -806.   NA    NA     9813.
    -#>  2 Feb 1973      8106 -1523.   NA    NA     9629.
    -#>  3 Mar 1973      8928  -741.   NA    NA     9669.
    -#>  4 Apr 1973      9137  -515.   NA    NA     9652.
    -#>  5 May 1973     10017   340.   NA    NA     9677.
    -#>  6 Jun 1973     10826   745.   NA    NA    10081.
    -#>  7 Jul 1973     11317  1679. 9599.   38.2   9638.
    -#>  8 Aug 1973     10744   986. 9500.  258.    9758.
    -#>  9 Sep 1973      9713  -109. 9416.  406.    9822.
    -#> 10 Oct 1973      9938   264. 9349.  325.    9674.
    -#> # ℹ 62 more rows
    -
    -
    -
    -
    - - -
    - - - -
    - - - - - - - diff --git a/docs/reference/tidiers_ets.html b/docs/reference/tidiers_ets.html deleted file mode 100644 index 5814960..0000000 --- a/docs/reference/tidiers_ets.html +++ /dev/null @@ -1,238 +0,0 @@ - -Tidying methods for ETS (Error, Trend, Seasonal) exponential smoothing -modeling of time series — tidiers_ets • sweep - Skip to contents - - -
    -
    -
    - -
    -

    Tidying methods for ETS (Error, Trend, Seasonal) exponential smoothing -modeling of time series

    -
    - -
    -

    Usage

    -
    # S3 method for ets
    -sw_tidy(x, ...)
    -
    -# S3 method for ets
    -sw_glance(x, ...)
    -
    -# S3 method for ets
    -sw_augment(x, data = NULL, timetk_idx = FALSE, rename_index = "index", ...)
    -
    -# S3 method for ets
    -sw_tidy_decomp(x, timetk_idx = FALSE, rename_index = "index", ...)
    -
    - -
    -

    Arguments

    -
    x
    -

    An object of class "ets"

    - - -
    ...
    -

    Not used.

    - - -
    data
    -

    Used with sw_augment only. -NULL by default which simply returns augmented columns only. -User can supply the original data, which returns the data + augmented columns.

    - - -
    timetk_idx
    -

    Used with sw_augment and sw_tidy_decomp. -When TRUE, uses a timetk index (irregular, typically date or datetime) if present.

    - - -
    rename_index
    -

    Used with sw_augment and sw_tidy_decomp. -A string representing the name of the index generated.

    - -
    -
    -

    Value

    - - -

    sw_tidy() returns one row for each model parameter, -with two columns:

    • term: The smoothing parameters (alpha, gamma) and the initial states -(l, s0 through s10)

    • -
    • estimate: The estimated parameter value

    • -

    sw_glance() returns one row with the columns

    • model.desc: A description of the model including the -three integer components (p, d, q) are the AR order, -the degree of differencing, and the MA order.

    • -
    • sigma: The square root of the estimated residual variance

    • -
    • logLik: The data's log-likelihood under the model

    • -
    • AIC: The Akaike Information Criterion

    • -
    • BIC: The Bayesian Information Criterion

    • -
    • ME: Mean error

    • -
    • RMSE: Root mean squared error

    • -
    • MAE: Mean absolute error

    • -
    • MPE: Mean percentage error

    • -
    • MAPE: Mean absolute percentage error

    • -
    • MASE: Mean absolute scaled error

    • -
    • ACF1: Autocorrelation of errors at lag 1

    • -

    sw_augment() returns a tibble with the following time series attributes:

    • index: An index is either attempted to be extracted from the model or -a sequential index is created for plotting purposes

    • -
    • .actual: The original time series

    • -
    • .fitted: The fitted values from the model

    • -
    • .resid: The residual values from the model

    • -

    sw_tidy_decomp() returns a tibble with the following time series attributes:

    • index: An index is either attempted to be extracted from the model or -a sequential index is created for plotting purposes

    • -
    • observed: The original time series

    • -
    • level: The level component

    • -
    • slope: The slope component (Not always present)

    • -
    • season: The seasonal component (Not always present)

    • -
    -
    -

    See also

    - -
    - -
    -

    Examples

    -
    library(dplyr)
    -library(forecast)
    -
    -fit_ets <- WWWusage %>%
    -    ets()
    -
    -sw_tidy(fit_ets)
    -#> # A tibble: 5 × 2
    -#>   term  estimate
    -#>   <chr>    <dbl>
    -#> 1 alpha   1.00  
    -#> 2 beta    0.997 
    -#> 3 phi     0.815 
    -#> 4 l      90.4   
    -#> 5 b      -0.0173
    -sw_glance(fit_ets)
    -#> # A tibble: 1 × 12
    -#>   model.desc  sigma logLik   AIC   BIC    ME  RMSE   MAE   MPE  MAPE  MASE  ACF1
    -#>   <chr>       <dbl>  <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
    -#> 1 ETS(A,Ad,N)  3.50  -353.  718.  733. 0.224  3.41  2.76 0.263  2.16 0.610 0.231
    -sw_augment(fit_ets)
    -#> # A tibble: 100 × 4
    -#>    index .actual .fitted .resid
    -#>    <int>   <dbl>   <dbl>  <dbl>
    -#>  1     1      88    90.3 -2.34 
    -#>  2     2      84    86.1 -2.09 
    -#>  3     3      85    80.7  4.25 
    -#>  4     4      85    85.8 -0.803
    -#>  5     5      84    85.0 -1.00 
    -#>  6     6      85    83.2  1.81 
    -#>  7     7      83    85.8 -2.81 
    -#>  8     8      85    81.4  3.62 
    -#>  9     9      88    86.6  1.38 
    -#> 10    10      89    90.4 -1.44 
    -#> # ℹ 90 more rows
    -sw_tidy_decomp(fit_ets)
    -#> # A tibble: 101 × 4
    -#>    index observed level    slope
    -#>    <dbl>    <dbl> <dbl>    <dbl>
    -#>  1     0       NA  90.4 -0.0173 
    -#>  2     1       88  88.0 -2.34   
    -#>  3     2       84  84.0 -3.99   
    -#>  4     3       85  85.0  0.986  
    -#>  5     4       85  85.0  0.00312
    -#>  6     5       84  84.0 -0.997  
    -#>  7     6       85  85.0  0.994  
    -#>  8     7       83  83.0 -1.99   
    -#>  9     8       85  85.0  1.99   
    -#> 10     9       88  88.0  3.00   
    -#> # ℹ 91 more rows
    -
    -
    -
    -
    - - -
    - - - -
    - - - - - - - diff --git a/docs/reference/tidiers_nnetar.html b/docs/reference/tidiers_nnetar.html deleted file mode 100644 index 42b9564..0000000 --- a/docs/reference/tidiers_nnetar.html +++ /dev/null @@ -1,211 +0,0 @@ - -Tidying methods for Nural Network Time Series models — tidiers_nnetar • sweep - Skip to contents - - -
    -
    -
    - -
    -

    These methods tidy the coefficients of NNETAR models of univariate time -series.

    -
    - -
    -

    Usage

    -
    # S3 method for nnetar
    -sw_tidy(x, ...)
    -
    -# S3 method for nnetar
    -sw_glance(x, ...)
    -
    -# S3 method for nnetar
    -sw_augment(x, data = NULL, timetk_idx = FALSE, rename_index = "index", ...)
    -
    - -
    -

    Arguments

    -
    x
    -

    An object of class "nnetar"

    - - -
    ...
    -

    Additional parameters (not used)

    - - -
    data
    -

    Used with sw_augment only. -NULL by default which simply returns augmented columns only. -User can supply the original data, which returns the data + augmented columns.

    - - -
    timetk_idx
    -

    Used with sw_augment only. -Uses a irregular timetk index if present.

    - - -
    rename_index
    -

    Used with sw_augment only. -A string representing the name of the index generated.

    - -
    -
    -

    Value

    - - -

    sw_tidy() returns one row for each model parameter, -with two columns:

    • term: The smoothing parameters (alpha, gamma) and the initial states -(l, s0 through s10)

    • -
    • estimate: The estimated parameter value

    • -

    sw_glance() returns one row with the columns

    • model.desc: A description of the model including the -three integer components (p, d, q) are the AR order, -the degree of differencing, and the MA order.

    • -
    • sigma: The square root of the estimated residual variance

    • -
    • logLik: The data's log-likelihood under the model (NA)

    • -
    • AIC: The Akaike Information Criterion (NA)

    • -
    • BIC: The Bayesian Information Criterion (NA)

    • -
    • ME: Mean error

    • -
    • RMSE: Root mean squared error

    • -
    • MAE: Mean absolute error

    • -
    • MPE: Mean percentage error

    • -
    • MAPE: Mean absolute percentage error

    • -
    • MASE: Mean absolute scaled error

    • -
    • ACF1: Autocorrelation of errors at lag 1

    • -

    sw_augment() returns a tibble with the following time series attributes:

    • index: An index is either attempted to be extracted from the model or -a sequential index is created for plotting purposes

    • -
    • .actual: The original time series

    • -
    • .fitted: The fitted values from the model

    • -
    • .resid: The residual values from the model

    • -
    -
    -

    See also

    - -
    - -
    -

    Examples

    -
    library(dplyr)
    -library(forecast)
    -
    -fit_nnetar <- lynx %>%
    -    nnetar()
    -
    -sw_tidy(fit_nnetar)
    -#> # A tibble: 4 × 2
    -#>   term  estimate
    -#>   <chr>    <dbl>
    -#> 1 m            1
    -#> 2 p            8
    -#> 3 P            0
    -#> 4 size         4
    -sw_glance(fit_nnetar)
    -#> # A tibble: 1 × 12
    -#>   model.desc sigma logLik AIC   BIC        ME  RMSE   MAE   MPE  MAPE  MASE
    -#>   <chr>      <dbl> <lgl>  <lgl> <lgl>   <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
    -#> 1 NNAR(8,4)   297. NA     NA    NA    -0.0400  297.  218. -39.6  54.0 0.262
    -#> # ℹ 1 more variable: ACF1 <dbl>
    -sw_augment(fit_nnetar)
    -#> # A tibble: 114 × 4
    -#>    index .actual .fitted .resid
    -#>    <dbl>   <dbl>   <dbl>  <dbl>
    -#>  1  1821     269     NA    NA  
    -#>  2  1822     321     NA    NA  
    -#>  3  1823     585     NA    NA  
    -#>  4  1824     871     NA    NA  
    -#>  5  1825    1475     NA    NA  
    -#>  6  1826    2821     NA    NA  
    -#>  7  1827    3928     NA    NA  
    -#>  8  1828    5943     NA    NA  
    -#>  9  1829    4950   4798.  152. 
    -#> 10  1830    2577   2613.  -35.7
    -#> # ℹ 104 more rows
    -
    -
    -
    -
    - - -
    - - - -
    - - - - - - - diff --git a/docs/reference/tidiers_robets.html b/docs/reference/tidiers_robets.html deleted file mode 100644 index 4ed3474..0000000 --- a/docs/reference/tidiers_robets.html +++ /dev/null @@ -1,316 +0,0 @@ - - - - - - - - -Tidying methods for robets (Robust Error, Trend, Seasonal) exponential smoothing -modeling of time series — tidiers_robets • sweep - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - - -
    - -
    -
    - - -
    -

    Tidying methods for robets (Robust Error, Trend, Seasonal) exponential smoothing -modeling of time series

    -
    - -
    # S3 method for robets
    -sw_tidy(x, ...)
    -
    -# S3 method for robets
    -sw_glance(x, ...)
    -
    -# S3 method for robets
    -sw_augment(x, data = NULL, timetk_idx = FALSE, rename_index = "index", ...)
    -
    -# S3 method for robets
    -sw_tidy_decomp(x, timetk_idx = FALSE, rename_index = "index", ...)
    - -

    Arguments

    - - - - - - - - - - - - - - - - - - - - - - -
    x

    An object of class "robets"

    ...

    Not used.

    data

    Used with sw_augment only. -NULL by default which simply returns augmented columns only. -User can supply the original data, which returns the data + augmented columns.

    timetk_idx

    Used with sw_augment and sw_tidy_decomp. -When TRUE, uses a timetk index (irregular, typically date or datetime) if present.

    rename_index

    Used with sw_augment and sw_tidy_decomp. -A string representing the name of the index generated.

    - -

    Value

    - -

    sw_tidy() returns one row for each model parameter, -with two columns:

      -
    • term: The smoothing parameters (alpha, gamma) and the initial states -(l, s0 through s10)

    • -
    • estimate: The estimated parameter value

    • -
    - -

    sw_glance() returns one row with the columns

      -
    • model.desc: A description of the model including the -three integer components (p, d, q) are the AR order, -the degree of differencing, and the MA order.

    • -
    • sigma: The square root of the estimated residual variance

    • -
    • logLik: The data's log-likelihood under the model

    • -
    • AIC: The Akaike Information Criterion

    • -
    • BIC: The Bayesian Information Criterion

    • -
    • ME: Mean error

    • -
    • RMSE: Root mean squared error

    • -
    • MAE: Mean absolute error

    • -
    • MPE: Mean percentage error

    • -
    • MAPE: Mean absolute percentage error

    • -
    • MASE: Mean absolute scaled error

    • -
    • ACF1: Autocorrelation of errors at lag 1

    • -
    - -

    sw_augment() returns a tibble with the following time series attributes:

      -
    • index: An index is either attempted to be extracted from the model or -a sequential index is created for plotting purposes

    • -
    • .actual: The original time series

    • -
    • .fitted: The fitted values from the model

    • -
    • .resid: The residual values from the model

    • -
    - -

    sw_tidy_decomp() returns a tibble with the following time series attributes:

      -
    • index: An index is either attempted to be extracted from the model or -a sequential index is created for plotting purposes

    • -
    • observed: The original time series

    • -
    • level: The level component

    • -
    • slope: The slope component (Not always present)

    • -
    • season: The seasonal component (Not always present)

    • -
    - -

    See also

    - - - -

    Examples

    -
    library(dplyr) -library(robets) -library(sweep) - -fit_robets <- WWWusage %>% - robets() - -sw_tidy(fit_robets)
    #> # A tibble: 7 x 2 -#> term estimate -#> <chr> <dbl> -#> 1 alpha 0.997 -#> 2 beta 0.980 -#> 3 phi 0.800 -#> 4 sigma0 1.48 -#> 5 initstate.l 85 -#> 6 initstate.b 0 -#> 7 k 3
    sw_glance(fit_robets)
    #> # A tibble: 1 x 2 -#> model.desc sigma -#> <chr> <dbl> -#> 1 ROBETS(A,Ad,N) 3.47
    sw_augment(fit_robets)
    #> # A tibble: 100 x 4 -#> index .actual .fitted .resid -#> <int> <dbl> <dbl> <dbl> -#> 1 1 88 85 3 -#> 2 2 84 90.3 -6.34 -#> 3 3 85 82.1 2.90 -#> 4 4 85 85.2 -0.205 -#> 5 5 84 85.0 -1.01 -#> 6 6 85 83.2 1.78 -#> 7 7 83 85.8 -2.76 -#> 8 8 85 81.5 3.54 -#> 9 9 88 86.5 1.47 -#> 10 10 89 90.4 -1.38 -#> # … with 90 more rows
    sw_tidy_decomp(fit_robets)
    #> # A tibble: 101 x 4 -#> index observed level slope -#> <dbl> <dbl> <dbl> <dbl> -#> 1 0 NA 1.48 0 -#> 2 1 88 1.65 2.94 -#> 3 2 84 1.90 -3.22 -#> 4 3 85 2.03 0.267 -#> 5 4 85 1.93 0.0130 -#> 6 5 84 1.86 -0.980 -#> 7 6 85 1.88 0.961 -#> 8 7 83 2.00 -1.94 -#> 9 8 85 2.19 1.92 -#> 10 9 88 2.14 2.98 -#> # … with 91 more rows
    -
    -
    - -
    - - -
    - - -
    -

    Site built with pkgdown 1.5.1.

    -
    - -
    -
    - - - - - - - - diff --git a/docs/reference/tidiers_stl.html b/docs/reference/tidiers_stl.html deleted file mode 100644 index bc9f8b6..0000000 --- a/docs/reference/tidiers_stl.html +++ /dev/null @@ -1,205 +0,0 @@ - -Tidying methods for STL (Seasonal, Trend, Level) decomposition of time series — tidiers_stl • sweep - Skip to contents - - -
    -
    -
    - -
    -

    Tidying methods for STL (Seasonal, Trend, Level) decomposition of time series

    -
    - -
    -

    Usage

    -
    # S3 method for stl
    -sw_tidy(x, ...)
    -
    -# S3 method for stl
    -sw_tidy_decomp(x, timetk_idx = FALSE, rename_index = "index", ...)
    -
    -# S3 method for stlm
    -sw_tidy_decomp(x, timetk_idx = FALSE, rename_index = "index", ...)
    -
    -# S3 method for stlm
    -sw_glance(x, ...)
    -
    -# S3 method for stlm
    -sw_augment(x, data = NULL, rename_index = "index", timetk_idx = FALSE, ...)
    -
    - -
    -

    Arguments

    -
    x
    -

    An object of class "stl"

    - - -
    ...
    -

    Not used.

    - - -
    timetk_idx
    -

    Used with sw_tidy_decomp. -When TRUE, uses a timetk index (irregular, typically date or datetime) if present.

    - - -
    rename_index
    -

    Used with sw_tidy_decomp. -A string representing the name of the index generated.

    - - -
    data
    -

    Used with sw_augment only.

    - -
    -
    -

    Value

    - - -

    sw_tidy() wraps sw_tidy_decomp()

    - - - -

    sw_tidy_decomp() returns a tibble with the following time series attributes:

    • index: An index is either attempted to be extracted from the model or -a sequential index is created for plotting purposes

    • -
    • season: The seasonal component

    • -
    • trend: The trend component

    • -
    • remainder: observed - (season + trend)

    • -
    • seasadj: observed - season (or trend + remainder)

    • -

    sw_glance() returns the underlying ETS or ARIMA model's sw_glance() results one row with the columns

    • model.desc: A description of the model including the -three integer components (p, d, q) are the AR order, -the degree of differencing, and the MA order.

    • -
    • sigma: The square root of the estimated residual variance

    • -
    • logLik: The data's log-likelihood under the model

    • -
    • AIC: The Akaike Information Criterion

    • -
    • BIC: The Bayesian Information Criterion

    • -
    • ME: Mean error

    • -
    • RMSE: Root mean squared error

    • -
    • MAE: Mean absolute error

    • -
    • MPE: Mean percentage error

    • -
    • MAPE: Mean absolute percentage error

    • -
    • MASE: Mean absolute scaled error

    • -
    • ACF1: Autocorrelation of errors at lag 1

    • -

    sw_augment() returns a tibble with the following time series attributes:

    • index: An index is either attempted to be extracted from the model or -a sequential index is created for plotting purposes

    • -
    • .actual: The original time series

    • -
    • .fitted: The fitted values from the model

    • -
    • .resid: The residual values from the model

    • -
    -
    -

    See also

    - -
    - -
    -

    Examples

    -
    library(dplyr)
    -library(forecast)
    -library(sweep)
    -
    -fit_stl <- USAccDeaths %>%
    -    stl(s.window = "periodic")
    -
    -sw_tidy_decomp(fit_stl)
    -#> # A tibble: 72 × 6
    -#>    index     observed  season trend remainder seasadj
    -#>    <yearmon>    <dbl>   <dbl> <dbl>     <dbl>   <dbl>
    -#>  1 Jan 1973      9007  -820.  9935.    -108.    9827.
    -#>  2 Feb 1973      8106 -1559.  9881.    -216.    9665.
    -#>  3 Mar 1973      8928  -760.  9827.    -139.    9688.
    -#>  4 Apr 1973      9137  -530.  9766.     -98.2   9667.
    -#>  5 May 1973     10017   335.  9704.     -22.0   9682.
    -#>  6 Jun 1973     10826   815.  9637.     374.   10011.
    -#>  7 Jul 1973     11317  1682.  9569.      65.9   9635.
    -#>  8 Aug 1973     10744   982.  9500.     262.    9762.
    -#>  9 Sep 1973      9713   -62.8 9431.     345.    9776.
    -#> 10 Oct 1973      9938   232.  9343.     363.    9706.
    -#> # ℹ 62 more rows
    -
    -
    -
    -
    - - -
    - - - -
    - - - - - - - diff --git a/docs/reference/validate_index.html b/docs/reference/validate_index.html deleted file mode 100644 index 0f22d5f..0000000 --- a/docs/reference/validate_index.html +++ /dev/null @@ -1,114 +0,0 @@ - -Validates data frame has column named the same name as variable rename_index — validate_index • sweep - Skip to contents - - -
    -
    -
    - -
    -

    Validates data frame has column named the same name as variable rename_index

    -
    - -
    -

    Usage

    -
    validate_index(ret, rename_index)
    -
    - -
    -

    Arguments

    -
    ret
    -

    An object of class tibble

    - - -
    rename_index
    -

    A variable indicating the index name to be used in the -tibble returned

    - -
    - -
    - - -
    - - - -
    - - - - - - - diff --git a/docs/sitemap.xml b/docs/sitemap.xml deleted file mode 100644 index 693c4a6..0000000 --- a/docs/sitemap.xml +++ /dev/null @@ -1,111 +0,0 @@ - - - - https://business-science.github.io/sweep/404.html - - - https://business-science.github.io/sweep/articles/SW00_Introduction_to_sweep.html - - - https://business-science.github.io/sweep/articles/SW01_Forecasting_Time_Series_Groups.html - - - https://business-science.github.io/sweep/articles/SW02_Forecasting_Multiple_Models.html - - - https://business-science.github.io/sweep/articles/index.html - - - https://business-science.github.io/sweep/authors.html - - - https://business-science.github.io/sweep/index.html - - - https://business-science.github.io/sweep/news/index.html - - - https://business-science.github.io/sweep/reference/add_index.html - - - https://business-science.github.io/sweep/reference/arima_string.html - - - https://business-science.github.io/sweep/reference/bats_string.html - - - https://business-science.github.io/sweep/reference/bike_sales.html - - - https://business-science.github.io/sweep/reference/index.html - - - https://business-science.github.io/sweep/reference/reexports.html - - - https://business-science.github.io/sweep/reference/sw_augment.default.html - - - https://business-science.github.io/sweep/reference/sw_augment.html - - - https://business-science.github.io/sweep/reference/sw_augment_columns.html - - - https://business-science.github.io/sweep/reference/sw_glance.default.html - - - https://business-science.github.io/sweep/reference/sw_glance.html - - - https://business-science.github.io/sweep/reference/sw_sweep.html - - - https://business-science.github.io/sweep/reference/sw_tidy.default.html - - - https://business-science.github.io/sweep/reference/sw_tidy.html - - - https://business-science.github.io/sweep/reference/sw_tidy_decomp.html - - - https://business-science.github.io/sweep/reference/sweep-package.html - - - https://business-science.github.io/sweep/reference/sweep_package.html - - - https://business-science.github.io/sweep/reference/tbats_string.html - - - https://business-science.github.io/sweep/reference/tidiers_HoltWinters.html - - - https://business-science.github.io/sweep/reference/tidiers_StructTS.html - - - https://business-science.github.io/sweep/reference/tidiers_arima.html - - - https://business-science.github.io/sweep/reference/tidiers_bats.html - - - https://business-science.github.io/sweep/reference/tidiers_decomposed_ts.html - - - https://business-science.github.io/sweep/reference/tidiers_ets.html - - - https://business-science.github.io/sweep/reference/tidiers_nnetar.html - - - https://business-science.github.io/sweep/reference/tidiers_robets.html - - - https://business-science.github.io/sweep/reference/tidiers_stl.html - - - https://business-science.github.io/sweep/reference/validate_index.html - -