diff --git a/articles/SW00_Introduction_to_sweep.html b/articles/SW00_Introduction_to_sweep.html index 394c0fe..3c2c7f6 100644 --- a/articles/SW00_Introduction_to_sweep.html +++ b/articles/SW00_Introduction_to_sweep.html @@ -103,7 +103,7 @@

Matt Dancho

-

2023-12-28

+

2024-01-04

Source: vignettes/SW00_Introduction_to_sweep.Rmd
SW00_Introduction_to_sweep.Rmd
diff --git a/articles/SW01_Forecasting_Time_Series_Groups.html b/articles/SW01_Forecasting_Time_Series_Groups.html index 611a4df..8d9c613 100644 --- a/articles/SW01_Forecasting_Time_Series_Groups.html +++ b/articles/SW01_Forecasting_Time_Series_Groups.html @@ -103,7 +103,7 @@

Matt Dancho

-

2023-12-28

+

2024-01-04

Source: vignettes/SW01_Forecasting_Time_Series_Groups.Rmd
SW01_Forecasting_Time_Series_Groups.Rmd
diff --git a/articles/SW02_Forecasting_Multiple_Models.html b/articles/SW02_Forecasting_Multiple_Models.html index 6e60a72..0f24d61 100644 --- a/articles/SW02_Forecasting_Multiple_Models.html +++ b/articles/SW02_Forecasting_Multiple_Models.html @@ -103,7 +103,7 @@

Matt Dancho

-

2023-12-28

+

2024-01-04

Source: vignettes/SW02_Forecasting_Multiple_Models.Rmd
SW02_Forecasting_Multiple_Models.Rmd
@@ -144,7 +144,7 @@

Forecasting Gasoline Pricestq_get() to retrieve the -Gasoline Prices from 1990 through today (2023-12-28).

+Gasoline Prices from 1990 through today (2024-01-04).

 gas_prices_monthly_raw <- tq_get(
     x    = "GASREGCOVM", 
@@ -313,15 +313,15 @@ 

Multiple Models Concept
 df_out$out

## [[1]]
-##  [1] 0.43872858 0.28465883 0.84943912 0.84561588 0.07014807 0.70347772
-##  [7] 0.36236192 0.78298809 0.19649185 0.85122581
+##  [1] 0.54818551 0.31200612 0.55621273 0.32530683 0.76215766 0.30280104
+##  [7] 0.27580616 0.04623577 0.68474766 0.03887453
 ## 
 ## [[2]]
-## [1]  9 10 10 12  9
+## [1]  6  7  6  5 12
 ## 
 ## [[3]]
-##  [1]  10.03371353 -15.90055900 -17.23650991  -9.39415959  16.56242493
-##  [6]   8.18828973  -9.33137140   4.57302312  -0.07964688  -1.64578790
+## [1] 18.4421424 4.3480539 -7.3581514 0.6666766 21.8707091 -1.7164745 +## [7] -11.9968083 -21.6309492 23.5678024 -11.5255936

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.

diff --git a/authors.html b/authors.html index e816e26..b3d59fc 100644 --- a/authors.html +++ b/authors.html @@ -86,14 +86,14 @@

Authors

Citation

Source: DESCRIPTION

-

Dancho M, Vaughan D (2023). +

Dancho M, Vaughan D (2024). sweep: Tidy Tools for Forecasting. R package version 0.2.5.9000, https://github.com/business-science/sweep, https://business-science.github.io/sweep/.

@Manual{,
   title = {sweep: Tidy Tools for Forecasting},
   author = {Matt Dancho and Davis Vaughan},
-  year = {2023},
+  year = {2024},
   note = {R package version 0.2.5.9000, https://github.com/business-science/sweep},
   url = {https://business-science.github.io/sweep/},
 }
diff --git a/pkgdown.yml b/pkgdown.yml index 2e07d49..9095163 100644 --- a/pkgdown.yml +++ b/pkgdown.yml @@ -5,7 +5,7 @@ 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-28T15:19Z +last_built: 2024-01-04T18:58Z urls: reference: https://business-science.github.io/sweep/reference article: https://business-science.github.io/sweep/articles diff --git a/reference/tidiers_nnetar.html b/reference/tidiers_nnetar.html index df6f3c8..cb3ca01 100644 --- a/reference/tidiers_nnetar.html +++ b/reference/tidiers_nnetar.html @@ -169,22 +169,22 @@

Examples#> # 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) 266. NA NA NA 0.0817 266. 198. -37.7 52.0 0.238 +#> 1 NNAR(8,4) 313. NA NA NA -0.300 313. 226. -38.2 52.2 0.272 #> # ℹ 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 4618. 332. -#> 10 1830 2577 2614. -37.1 +#> 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 4560. 390. +#> 10 1830 2577 2467. 110. #> # ℹ 104 more rows diff --git a/search.json b/search.json index f84d7a7..91430d0 100644 --- a/search.json +++ b/search.json @@ -1 +1 @@ -[{"path":"https://business-science.github.io/sweep/articles/SW00_Introduction_to_sweep.html","id":"prerequisites","dir":"Articles","previous_headings":"","what":"Prerequisites","title":"Introduction to sweep","text":"get started, load following packages.","code":"library(ggplot2) library(tidyquant) library(timetk) library(sweep) library(forecast)"},{"path":"https://business-science.github.io/sweep/articles/SW00_Introduction_to_sweep.html","id":"forecasting-sales-of-beer-wine-and-distilled-alcohol-beverages","dir":"Articles","previous_headings":"","what":"Forecasting Sales of Beer, Wine, and Distilled Alcohol Beverages","title":"Introduction to sweep","text":"’ll use tidyquant package get US alcohol sales, comes FRED data base (origin US Bureau Census, one 80+ data sources FRED connects ). FRED code “S4248SM144NCEN” data set can found . can quickly visualize using ggplot2 package. can see appears seasonality upward trend.","code":"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 ## ## 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 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'"},{"path":"https://business-science.github.io/sweep/articles/SW00_Introduction_to_sweep.html","id":"forecasting-workflow","dir":"Articles","previous_headings":"","what":"Forecasting Workflow","title":"Introduction to sweep","text":"forecasting workflow involves basic steps: Step 1: Coerce ts object class. Step 2: Apply model (set models) Step 3: Forecast models (similar predict) Step 4: Use sw_sweep() tidy forecast. Note purposely omit steps testing series stationarity (Box.test(type = \"Ljung\")) analysis autocorrelations (Acf, Pacf) brevity purposes. recommend analyst follow forecasting workflow “Forecasting: principles practice”","code":""},{"path":"https://business-science.github.io/sweep/articles/SW00_Introduction_to_sweep.html","id":"step-1-coerce-to-a-ts-object-class","dir":"Articles","previous_headings":"Forecasting Workflow","what":"Step 1: Coerce to a ts object class","title":"Introduction to sweep","text":"forecast package uses ts data structure, quite bit different tibbles currently using. Fortunately, ’s easy get correct structure tk_ts() timetk package. start freq variables required regularized time series (ts) class, specify treat time series. monthly, frequency specified 12. results nice calendar view. silent = TRUE tells tk_ts() function skip warning notifying us “date” column dropped. Non-numeric columns must dropped ts class, matrix based homogeneous data class. significant benefit resulting ts object maintains “timetk index”, help forecasting dates later. can verify using has_timetk_idx() timetk package. Now time series coerced, let’s proceed modeling.","code":"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 has_timetk_idx(alcohol_sales_ts) ## [1] TRUE"},{"path":"https://business-science.github.io/sweep/articles/SW00_Introduction_to_sweep.html","id":"step-2-modeling-a-time-series","dir":"Articles","previous_headings":"Forecasting Workflow","what":"Step 2: Modeling a time series","title":"Introduction to sweep","text":"modeling workflow takes time series object applies model. Nothing new : ’ll simply use ets() function forecast package get Exponential Smoothing ETS (Error, Trend, Seasonal) model. sweep can help evaluation model. Expanding broom package four functions: sw_tidy(): Returns tibble model parameters sw_glance(): Returns model accuracy measurements sw_augment(): Returns fitted residuals model sw_tidy_decomp(): Returns tidy decomposition model guide shows model object compatibility sweep tidier functions. Function Compatibility Going tidiers, can get useful model information.","code":"fit_ets <- alcohol_sales_ts %>% ets()"},{"path":"https://business-science.github.io/sweep/articles/SW00_Introduction_to_sweep.html","id":"sw_tidy","dir":"Articles","previous_headings":"Forecasting Workflow > Step 2: Modeling a time series","what":"sw_tidy","title":"Introduction to sweep","text":"sw_tidy() returns model parameters.","code":"sw_tidy(fit_ets) ## # A tibble: 17 × 2 ## term estimate ## ## 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"},{"path":"https://business-science.github.io/sweep/articles/SW00_Introduction_to_sweep.html","id":"sw_glance","dir":"Articles","previous_headings":"Forecasting Workflow > Step 2: Modeling a time series","what":"sw_glance","title":"Introduction to sweep","text":"sw_glance() returns model quality parameters.","code":"sw_glance(fit_ets) ## # A tibble: 1 × 12 ## model.desc sigma logLik AIC BIC ME RMSE MAE MPE MAPE MASE ## ## 1 ETS(M,Ad,M) 0.0458 -1012. 2060. 2111. 40.7 431. 357. 0.223 3.54 0.705 ## # ℹ 1 more variable: ACF1 "},{"path":"https://business-science.github.io/sweep/articles/SW00_Introduction_to_sweep.html","id":"sw_augment","dir":"Articles","previous_headings":"Forecasting Workflow > Step 2: Modeling a time series","what":"sw_augment","title":"Introduction to sweep","text":"sw_augment() returns actual, fitted residual values. can review residuals determine underlying patterns left. Note index class yearmon, regularized date format.","code":"augment_fit_ets <- sw_augment(fit_ets) augment_fit_ets ## # A tibble: 120 × 4 ## index .actual .fitted .resid ## ## 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 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'"},{"path":"https://business-science.github.io/sweep/articles/SW00_Introduction_to_sweep.html","id":"sw_tidy_decomp","dir":"Articles","previous_headings":"Forecasting Workflow > Step 2: Modeling a time series","what":"sw_tidy_decomp","title":"Introduction to sweep","text":"sw_tidy_decomp() returns decomposition ETS model. can review decomposition using ggplot2 well. data need manipulated slightly facet visualization. gather() function tidyr package used reshape data long format data frame column names “key” “value” indicating columns except index reshaped. “key” column mutated using mutate() factor preserves order keys “observed” comes first plotting. normal circumstances make sense refine model point. However, interest showing capabilities (rather forecast) move onto forecasting model. information forecast, please refer online book “Forecasting: principles practices”.","code":"decomp_fit_ets <- sw_tidy_decomp(fit_ets) decomp_fit_ets ## # A tibble: 121 × 5 ## index observed level slope season ## ## 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 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()`)."},{"path":"https://business-science.github.io/sweep/articles/SW00_Introduction_to_sweep.html","id":"step-3-forecasting-the-model","dir":"Articles","previous_headings":"Forecasting Workflow","what":"Step 3: Forecasting the model","title":"Introduction to sweep","text":"Next forecast ETS model using forecast() function. returned forecast object isn’t “tidy” format (.e. data frame). sw_sweep() function helps.","code":"fcast_ets <- fit_ets %>% forecast(h = 12)"},{"path":"https://business-science.github.io/sweep/articles/SW00_Introduction_to_sweep.html","id":"step-4-tidy-the-forecast-object","dir":"Articles","previous_headings":"Forecasting Workflow","what":"Step 4: Tidy the forecast object","title":"Introduction to sweep","text":"’ll use sw_sweep() function coerce forecast “tidy” data frame. sw_sweep() function coerces forecast object tibble can sent ggplot visualization. Let’s inspect result. tibble returned contains “index”, “key” “value” (case “price”) columns long “tidy” format ideal visualization ggplot2. “index” regularized format (case yearmon) forecast package uses ts objects. ’ll see can get back original irregularized format (case date) later. “key” “price” columns contains three groups key-value pairs: actual: actual values original data fitted: model values returned ets() function (excluded default) forecast: predicted values forecast() function sw_sweep() function contains argument fitted = FALSE default meaning model “fitted” values returned. can toggle desired. remaining columns forecast confidence intervals (typically 80 95, can changed forecast(level = c(80, 95))). columns setup wide format enable using geom_ribbon(). Let’s visualize forecast ggplot2. ’ll use combination geom_line() geom_ribbon(). fitted values toggled default reduce complexity plot, can added desired. Note using regular time index yearmon class, need add scale_x_yearmon(). ts object created tk_ts() function, contained timetk index carried throughout forecasting workflow. result, can use timetk_idx argument, maps original irregular index (dates) generated future index regularized time series (yearmon). results ability return index date datetime, currently possible forecast objects. Notice index returned date class. can build plot dates x-axis now. example, much benefit returning irregular time series. However, working frequencies monthly, ability return irregular index values becomes apparent.","code":"sw_sweep(fcast_ets, fitted = TRUE) ## # A tibble: 252 × 7 ## index key price lo.80 lo.95 hi.80 hi.95 ## ## 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 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() 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 ## ## 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 ## ## 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. 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"},{"path":"https://business-science.github.io/sweep/articles/SW00_Introduction_to_sweep.html","id":"recap","dir":"Articles","previous_headings":"","what":"Recap","title":"Introduction to sweep","text":"overview various functions within sweep package can used assist forecast analysis. next vignette, discuss powerful concepts including forecasting scale grouped time series analysis.","code":""},{"path":"https://business-science.github.io/sweep/articles/SW01_Forecasting_Time_Series_Groups.html","id":"prerequisites","dir":"Articles","previous_headings":"","what":"Prerequisites","title":"Forecasting Time Series Groups in the tidyverse","text":"get started, load following packages.","code":"library(dplyr) library(ggplot2) library(tidyr) library(purrr) library(lubridate) library(tidyquant) library(timetk) library(sweep) library(forecast)"},{"path":"https://business-science.github.io/sweep/articles/SW01_Forecasting_Time_Series_Groups.html","id":"bike-sales","dir":"Articles","previous_headings":"","what":"Bike Sales","title":"Forecasting Time Series Groups in the tidyverse","text":"’ll use bike sales data set, bike_sales, provided sweep package tutorial. bike_sales data set fictional daily order history spans 2011 2015. simulates sales database typical business. customers “bike shops” products “models”. ’ll analyse monthly sales trends bicycle manufacturer. Let’s transform data set aggregating month. can visualize package month plot using ggplot2 . Suppose Manufacturing wants granular forecast bike components related secondary category. next section discuss sweep can help perform forecast sub-category.","code":"bike_sales ## # A tibble: 15,644 × 17 ## order.date order.id order.line quantity price price.ext customer.id ## ## 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 , bikeshop.city , ## # bikeshop.state , latitude , longitude , product.id , ## # model , category.primary , category.secondary , frame 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 ## ## 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 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()"},{"path":"https://business-science.github.io/sweep/articles/SW01_Forecasting_Time_Series_Groups.html","id":"performing-forecasts-on-groups","dir":"Articles","previous_headings":"","what":"Performing Forecasts on Groups","title":"Forecasting Time Series Groups in the tidyverse","text":"First, need get data organized groups month year. ’ll create new “order.month” date using zoo::.yearmon() captures year month information “order.date” passing lubridate::as_date() convert date format. Next, use nest() function tidyr package consolidate time series group. newly created list-column, “data.tbl”, contains “order.month” “total.qty” columns group previous step. nest() function just bundles data together useful iterative functional programming.","code":"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 ## ## 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 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 ## ## 1 Cross Country Race ## 2 Cyclocross ## 3 Elite Road ## 4 Endurance Road ## 5 Fat Bike ## 6 Over Mountain ## 7 Sport ## 8 Trail ## 9 Triathalon "},{"path":"https://business-science.github.io/sweep/articles/SW01_Forecasting_Time_Series_Groups.html","id":"forecasting-workflow","dir":"Articles","previous_headings":"Performing Forecasts on Groups","what":"Forecasting Workflow","title":"Forecasting Time Series Groups in the tidyverse","text":"forecasting workflow involves basic steps: Step 1: Coerce ts object class. Step 2: Apply model (set models) Step 3: Forecast models (similar predict) Step 4: Tidy forecast","code":""},{"path":"https://business-science.github.io/sweep/articles/SW01_Forecasting_Time_Series_Groups.html","id":"step-1-coerce-to-a-ts-object-class","dir":"Articles","previous_headings":"Performing Forecasts on Groups","what":"Step 1: Coerce to a ts object class","title":"Forecasting Time Series Groups in the tidyverse","text":"step map tk_ts() function new column “data.ts”. procedure performed using combination dplyr::mutate() purrr::map(), works really well data science workflow analyses built progressively. result, combination used many subsequent steps vignette build analysis.","code":""},{"path":"https://business-science.github.io/sweep/articles/SW01_Forecasting_Time_Series_Groups.html","id":"mutate-and-map","dir":"Articles","previous_headings":"Performing Forecasts on Groups > Step 1: Coerce to a ts object class","what":"mutate and map","title":"Forecasting Time Series Groups in the tidyverse","text":"mutate() function adds column, map() function maps contents list-column (.x) function (.f). case, .x = data.tbl .f = tk_ts. arguments select = -order.month, start = 2011, freq = 12 passed ... parameters map, passed function. select statement used drop “order.month” final output don’t get bunch warning messages. specify start = 2011 freq = 12 return monthly frequency.","code":"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 ## ## 1 Cross Country Race ## 2 Cyclocross ## 3 Elite Road ## 4 Endurance Road ## 5 Fat Bike ## 6 Over Mountain ## 7 Sport ## 8 Trail ## 9 Triathalon "},{"path":"https://business-science.github.io/sweep/articles/SW01_Forecasting_Time_Series_Groups.html","id":"step-2-modeling-a-time-series","dir":"Articles","previous_headings":"Performing Forecasts on Groups","what":"Step 2: Modeling a time series","title":"Forecasting Time Series Groups in the tidyverse","text":"Next, map Exponential Smoothing ETS (Error, Trend, Seasonal) model function, ets, forecast package. Use combination mutate add column map interatively apply function rowwise list-column. instance, function map ets function list-column “data.ts”. rename resultant column “fit.ets” indicating ETS model fit time series data. point, can model inspection sweep tidiers.","code":"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 ## ## 1 Cross Country Race ## 2 Cyclocross ## 3 Elite Road ## 4 Endurance Road ## 5 Fat Bike ## 6 Over Mountain ## 7 Sport ## 8 Trail ## 9 Triathalon "},{"path":"https://business-science.github.io/sweep/articles/SW01_Forecasting_Time_Series_Groups.html","id":"sw_tidy","dir":"Articles","previous_headings":"Performing Forecasts on Groups > Step 2: Modeling a time series","what":"sw_tidy","title":"Forecasting Time Series Groups in the tidyverse","text":"get model parameters nested list, can combine sw_tidy within mutate map combo. real difference now unnest generated column (named “tidy”). Last, ’s easier compare model parameters side side, add one additional call spread() tidyr package.","code":"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` ## ## 1 alpha 0.0398 NA NA ## 2 gamma 0.000101 NA NA ## 3 l 321. NA NA ## 4 s0 0.503 NA NA ## 5 s1 1.10 NA NA ## 6 s10 0.643 NA NA ## 7 s2 0.375 NA NA ## 8 s3 1.12 NA NA ## 9 s4 0.630 NA NA ## 10 s5 2.06 NA NA ## # ℹ 118 more rows ## # ℹ 6 more variables: `Endurance Road` , `Fat Bike` , ## # `Over Mountain` , Sport , Trail , Triathalon "},{"path":"https://business-science.github.io/sweep/articles/SW01_Forecasting_Time_Series_Groups.html","id":"sw_glance","dir":"Articles","previous_headings":"Performing Forecasts on Groups > Step 2: Modeling a time series","what":"sw_glance","title":"Forecasting Time Series Groups in the tidyverse","text":"can view model accuracies also mapping sw_glance within mutate map combo.","code":"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 ## ## 1 Cross Country Race ETS(M,N,M) 1.06 -464. 957. ## 2 Cyclocross ETS(M,N,M) 1.12 -409. 848. ## 3 Elite Road ETS(M,N,M) 0.895 -471. 972. ## 4 Endurance Road ETS(M,N,M) 0.759 -439. 909. ## 5 Fat Bike ETS(M,N,M) 2.73 -343. 715. ## 6 Over Mountain ETS(M,N,M) 0.910 -423. 877. ## 7 Sport ETS(M,N,M) 0.872 -427. 884. ## 8 Trail ETS(M,A,M) 0.741 -411. 855. ## 9 Triathalon ETS(M,N,M) 1.52 -410. 850. ## # ℹ 8 more variables: BIC , ME , RMSE , MAE , MPE , ## # MAPE , MASE , ACF1 "},{"path":"https://business-science.github.io/sweep/articles/SW01_Forecasting_Time_Series_Groups.html","id":"sw_augment","dir":"Articles","previous_headings":"Performing Forecasts on Groups > Step 2: Modeling a time series","what":"sw_augment","title":"Forecasting Time Series Groups in the tidyverse","text":"augmented fitted residual values can achieved much manner. returns nine groups data. Note pass timetk_idx = TRUE return date format times opposed regular (yearmon numeric) time series. can plot residuals nine categories like . Unfortunately see high residuals (especially “Fat Bike”). often case realworld data.","code":"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 ## ## 1 Cross Country Race 2011-01-01 122 373. ## 2 Cross Country Race 2011-02-01 489 201. ## 3 Cross Country Race 2011-03-01 505 465. ## 4 Cross Country Race 2011-04-01 343 161. ## 5 Cross Country Race 2011-05-01 263 567. ## 6 Cross Country Race 2011-06-01 735 296. ## 7 Cross Country Race 2011-07-01 183 741. ## 8 Cross Country Race 2011-08-01 66 220. ## 9 Cross Country Race 2011-09-01 97 381. ## 10 Cross Country Race 2011-10-01 189 123. ## # ℹ 528 more rows ## # ℹ 1 more variable: .resid 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'"},{"path":"https://business-science.github.io/sweep/articles/SW01_Forecasting_Time_Series_Groups.html","id":"sw_tidy_decomp","dir":"Articles","previous_headings":"Performing Forecasts on Groups > Step 2: Modeling a time series","what":"sw_tidy_decomp","title":"Forecasting Time Series Groups in the tidyverse","text":"can create decompositions using procedure sw_tidy_decomp() mutate map combo.","code":"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 ## ## 1 Cross Country Race 2011-01-01 122 313. 1.16 ## 2 Cross Country Race 2011-02-01 489 331. 0.643 ## 3 Cross Country Race 2011-03-01 505 332. 1.41 ## 4 Cross Country Race 2011-04-01 343 347. 0.487 ## 5 Cross Country Race 2011-05-01 263 339. 1.64 ## 6 Cross Country Race 2011-06-01 735 359. 0.873 ## 7 Cross Country Race 2011-07-01 183 348. 2.06 ## 8 Cross Country Race 2011-08-01 66 339. 0.630 ## 9 Cross Country Race 2011-09-01 97 329. 1.12 ## 10 Cross Country Race 2011-10-01 189 336. 0.375 ## # ℹ 528 more rows ## # ℹ 1 more variable: slope "},{"path":"https://business-science.github.io/sweep/articles/SW01_Forecasting_Time_Series_Groups.html","id":"step-3-forecasting-the-model","dir":"Articles","previous_headings":"Performing Forecasts on Groups","what":"Step 3: Forecasting the model","title":"Forecasting Time Series Groups in the tidyverse","text":"can also forecast multiple models using similar approach forecast function. want 12 month forecast add argument h = 12 (refer ?forecast parameters can add, ’s quite ).","code":"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 ## ## 1 Cross Country Race ## 2 Cyclocross ## 3 Elite Road ## 4 Endurance Road ## 5 Fat Bike ## 6 Over Mountain ## 7 Sport ## 8 Trail ## 9 Triathalon "},{"path":"https://business-science.github.io/sweep/articles/SW01_Forecasting_Time_Series_Groups.html","id":"step-4-tidy-the-forecast","dir":"Articles","previous_headings":"Performing Forecasts on Groups","what":"Step 4: Tidy the forecast","title":"Forecasting Time Series Groups in the tidyverse","text":"Next, can apply sw_sweep get forecast nice “tidy” data frame. use argument fitted = FALSE remove fitted values forecast (leave fitted values desired). set timetk_idx = TRUE use dates instead numeric values index. ’ll use unnest() drop left list-columns return unnested data frame. Visualization just one final step.","code":"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 ## ## 1 Cross Country Race 2011-01-01 actu… ## 2 Cross Country Race 2011-02-01 actu… ## 3 Cross Country Race 2011-03-01 actu… ## 4 Cross Country Race 2011-04-01 actu… ## 5 Cross Country Race 2011-05-01 actu… ## 6 Cross Country Race 2011-06-01 actu… ## 7 Cross Country Race 2011-07-01 actu… ## 8 Cross Country Race 2011-08-01 actu… ## 9 Cross Country Race 2011-09-01 actu… ## 10 Cross Country Race 2011-10-01 actu… ## # ℹ 636 more rows ## # ℹ 5 more variables: total.qty , lo.80 , lo.95 , hi.80 , ## # hi.95 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))"},{"path":"https://business-science.github.io/sweep/articles/SW01_Forecasting_Time_Series_Groups.html","id":"recap","dir":"Articles","previous_headings":"","what":"Recap","title":"Forecasting Time Series Groups in the tidyverse","text":"sweep package several tools analyze grouped time series. next vignette review apply multiple models time series.","code":""},{"path":"https://business-science.github.io/sweep/articles/SW02_Forecasting_Multiple_Models.html","id":"prerequisites","dir":"Articles","previous_headings":"","what":"Prerequisites","title":"Forecasting Using Multiple Models","text":"get started, load following packages.","code":"library(tidyr) library(dplyr) library(purrr) library(lubridate) library(ggplot2) library(tidyquant) library(timetk) library(sweep) library(forecast)"},{"path":"https://business-science.github.io/sweep/articles/SW02_Forecasting_Multiple_Models.html","id":"forecasting-gasoline-prices","dir":"Articles","previous_headings":"","what":"Forecasting Gasoline Prices","title":"Forecasting Using Multiple Models","text":"start, let’s get data FRED data base using tidyquant. ’ll use tq_get() retrieve Gasoline Prices 1990 today (2023-12-28). Upon brief inspection, data contains 2 NA values need dealt . can use fill() tidyr package help deal data. first fill fill use previous post days prices fill missing data. can now visualize data. Monthly periodicity might bit granular model fitting. can easily switch periodicity quarterly using tq_transmute() tidyquant package along periodicity aggregation function .period xts package. ’ll convert date yearqtr class regularized. Another quick visualization show reduction granularity.","code":"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 ## ## 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 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 gas_prices_monthly <- gas_prices_monthly_raw %>% fill(price, .direction = \"down\") %>% fill(price, .direction = \"up\") 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() gas_prices_quarterly <- gas_prices_monthly %>% tq_transmute(mutate_fun = to.period, period = \"quarters\") gas_prices_quarterly ## # A tibble: 106 × 2 ## date price ## ## 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 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()"},{"path":"https://business-science.github.io/sweep/articles/SW02_Forecasting_Multiple_Models.html","id":"performing-forecasts-using-multiple-models","dir":"Articles","previous_headings":"","what":"Performing Forecasts Using Multiple Models","title":"Forecasting Using Multiple Models","text":"section use three models forecast gasoline prices: ARIMA ETS BATS","code":""},{"path":"https://business-science.github.io/sweep/articles/SW02_Forecasting_Multiple_Models.html","id":"multiple-models-concept","dir":"Articles","previous_headings":"Performing Forecasts Using Multiple Models","what":"Multiple Models Concept","title":"Forecasting Using Multiple Models","text":"jump modeling, let’s take look multiple model process R Data Science, Chapter 25 Many Models. first create data frame named list. example two columns: “f” functions text, “params” nested list parameters pass respective function column “f”. can also view contents df$params column understand underlying structure. Notice three primary levels secondary levels containing name-value pairs parameters. format important. Next apply functions parameters using special function, invoke_map(). parameter lists “params” column passed function “f” column. output nested list-column named “”. , ’s contents “”, result mapping list functions list parameters. Pretty powerful! Take minute understand conceptual process invoke_map function specifically parameter setup. comfortable, can move model implementation.","code":"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 ## ## 1 runif ## 2 rpois ## 3 rnorm 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 # 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 ## ## 1 runif ## 2 rpois ## 3 rnorm df_out$out ## [[1]] ## [1] 0.43872858 0.28465883 0.84943912 0.84561588 0.07014807 0.70347772 ## [7] 0.36236192 0.78298809 0.19649185 0.85122581 ## ## [[2]] ## [1] 9 10 10 12 9 ## ## [[3]] ## [1] 10.03371353 -15.90055900 -17.23650991 -9.39415959 16.56242493 ## [6] 8.18828973 -9.33137140 4.57302312 -0.07964688 -1.64578790"},{"path":"https://business-science.github.io/sweep/articles/SW02_Forecasting_Multiple_Models.html","id":"multiple-model-implementation","dir":"Articles","previous_headings":"Performing Forecasts Using Multiple Models","what":"Multiple Model Implementation","title":"Forecasting Using Multiple Models","text":"’ll need take following steps actual forecast model implementation: Coerce data time series Build model list using nested lists Create model data frame Invoke function map easier sounds. Let’s start coercing univariate time series tk_ts(). Next, create nested list using function names first-level keys (important ’ll see next step). Pass model parameters name-value pairs second level. Now, convert data frame using function, enframe() turns lists tibbles. Set arguments name = \"f\" value = \"params\". get bonus: model names now conveniently located column “f”. ready invoke map. Combine mutate() invoke_map() follows. Bada bing, bada boom, now models fitted using parameters defined previously.","code":"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 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 ) ) models_tbl <- tibble::enframe(models_list, name = \"f\", value = \"params\") models_tbl ## # A tibble: 3 × 2 ## f params ## ## 1 auto.arima ## 2 ets ## 3 bats models_tbl_fit <- models_tbl %>% mutate(fit = purrr::invoke_map(f, params)) models_tbl_fit ## # A tibble: 3 × 3 ## f params fit ## ## 1 auto.arima ## 2 ets ## 3 bats "},{"path":"https://business-science.github.io/sweep/articles/SW02_Forecasting_Multiple_Models.html","id":"inspecting-the-model-fit","dir":"Articles","previous_headings":"","what":"Inspecting the Model Fit","title":"Forecasting Using Multiple Models","text":"’s good point review understand model output. can review model parameters, accuracy measurements, residuals using sw_tidy(), sw_glance(), sw_augment().","code":""},{"path":"https://business-science.github.io/sweep/articles/SW02_Forecasting_Multiple_Models.html","id":"sw_tidy","dir":"Articles","previous_headings":"Inspecting the Model Fit","what":"sw_tidy","title":"Forecasting Using Multiple Models","text":"tidying function returns model parameters estimates. use combination mutate map iteratively apply sw_tidy() function new column named “tidy”. unnest spread review terms model function.","code":"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 ## ## 1 ar1 0.834 NA NA ## 2 ma1 -0.964 NA NA ## 3 sar1 0.939 NA NA ## 4 sma1 -0.776 NA NA ## 5 alpha NA 0.588 NA ## 6 ar.coefficients NA NA NA ## 7 beta NA NA NA ## 8 damping.parameter NA NA NA ## 9 gamma.values NA -0.0262 NA ## 10 lambda NA 0.0000605 NA ## 11 ma.coefficients NA 0.256 NA ## 12 alpha NA NA 0.831 ## 13 b NA NA -0.0524 ## 14 beta NA NA 0.000100 ## 15 gamma NA NA 0.0521 ## 16 l NA NA 1.29 ## 17 phi NA NA 0.837 ## 18 s0 NA NA 0.0469 ## 19 s1 NA NA -0.0209 ## 20 s2 NA NA -0.0407"},{"path":"https://business-science.github.io/sweep/articles/SW02_Forecasting_Multiple_Models.html","id":"sw_glance","dir":"Articles","previous_headings":"Inspecting the Model Fit","what":"sw_glance","title":"Forecasting Using Multiple Models","text":"Glance one powerful tools yields model accuracies enabling direct comparisons fit model. use process used tidy, except theres need spread perform comparison. can see ARIMA model lowest AIC far.","code":"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 ## ## 1 auto… ARIMA(1,1… 0.298 -20.6 51.2 64.4 0.0180 0.291 ## 2 ets ETS(M,Ad,… 0.118 -76.6 173. 200. 0.0149 0.292 ## 3 bats BATS(0, {… 0.116 159. 179. 184. 0.0193 0.259 ## # ℹ 5 more variables: MAE , MPE , MAPE , MASE , ACF1 "},{"path":"https://business-science.github.io/sweep/articles/SW02_Forecasting_Multiple_Models.html","id":"sw_augment","dir":"Articles","previous_headings":"Inspecting the Model Fit","what":"sw_augment","title":"Forecasting Using Multiple Models","text":"can augment models get residuals following procedure. can pipe (%>%) results right ggplot() plotting. Notice ARIMA model largest residuals especially model index increases whereas bats model relatively low residuals.","code":"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'"},{"path":"https://business-science.github.io/sweep/articles/SW02_Forecasting_Multiple_Models.html","id":"forecasting-the-model","dir":"Articles","previous_headings":"","what":"Forecasting the model","title":"Forecasting Using Multiple Models","text":"Creating forecast models accomplished mapping forecast function. next six quarters forecasted withe argument h = 6.","code":"models_tbl_fcast <- models_tbl_fit %>% mutate(fcast = map(fit, forecast, h = 6)) models_tbl_fcast ## # A tibble: 3 × 4 ## f params fit fcast ## ## 1 auto.arima ## 2 ets ## 3 bats "},{"path":"https://business-science.github.io/sweep/articles/SW02_Forecasting_Multiple_Models.html","id":"tidying-the-forecast","dir":"Articles","previous_headings":"","what":"Tidying the forecast","title":"Forecasting Using Multiple Models","text":"Next, map sw_sweep, coerces forecast “tidy” tibble format. set fitted = FALSE remove model fitted values output. set timetk_idx = TRUE use dates instead numeric values index. can unnest “sweep” column get results three models. Finally, can plot forecasts unnesting “sweep” column piping ggplot().","code":"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 ## ## 1 auto.arima ## 2 ets ## 3 bats models_tbl_fcast_tidy %>% unnest(sweep) ## # A tibble: 336 × 11 ## f params fit fcast date key price lo.80 lo.95 ## ## 1 auto.a… 1990-09-01 actu… 1.26 NA NA ## 2 auto.a… 1990-12-01 actu… 1.32 NA NA ## 3 auto.a… 1991-03-01 actu… 1.04 NA NA ## 4 auto.a… 1991-06-01 actu… 1.13 NA NA ## 5 auto.a… 1991-09-01 actu… 1.11 NA NA ## 6 auto.a… 1991-12-01 actu… 1.08 NA NA ## 7 auto.a… 1992-03-01 actu… 1.01 NA NA ## 8 auto.a… 1992-06-01 actu… 1.14 NA NA ## 9 auto.a… 1992-09-01 actu… 1.12 NA NA ## 10 auto.a… 1992-12-01 actu… 1.08 NA NA ## # ℹ 326 more rows ## # ℹ 2 more variables: hi.80 , hi.95 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()"},{"path":"https://business-science.github.io/sweep/articles/SW02_Forecasting_Multiple_Models.html","id":"recap","dir":"Articles","previous_headings":"","what":"Recap","title":"Forecasting Using Multiple Models","text":"sweep package can aid analysis multiple forecast models. next vignette review time series object coercion sweep.","code":""},{"path":"https://business-science.github.io/sweep/authors.html","id":null,"dir":"","previous_headings":"","what":"Authors","title":"Authors and Citation","text":"Matt Dancho. Author, maintainer. Davis Vaughan. Author.","code":""},{"path":"https://business-science.github.io/sweep/authors.html","id":"citation","dir":"","previous_headings":"","what":"Citation","title":"Authors and Citation","text":"Dancho M, Vaughan D (2023). sweep: Tidy Tools Forecasting. R package version 0.2.5.9000, https://github.com/business-science/sweep, https://business-science.github.io/sweep/.","code":"@Manual{, title = {sweep: Tidy Tools for Forecasting}, author = {Matt Dancho and Davis Vaughan}, year = {2023}, note = {R package version 0.2.5.9000, https://github.com/business-science/sweep}, url = {https://business-science.github.io/sweep/}, }"},{"path":"https://business-science.github.io/sweep/index.html","id":"sweep-","dir":"","previous_headings":"","what":"Tidy Tools for Forecasting","title":"Tidy Tools for Forecasting","text":"Extending broom time series forecasting sweep package extends broom tools (tidy, glance, augment) performing forecasts time series analysis “tidyverse”. package geared towards “tidying” forecast workflow used Rob Hyndman’s forecast package.","code":""},{"path":"https://business-science.github.io/sweep/index.html","id":"benefits","dir":"","previous_headings":"","what":"Benefits","title":"Tidy Tools for Forecasting","text":"Designed modeling scaling forecasts using tidyverse tools R Data Science Extends broom model analysis (ARIMA, ETS, BATS, etc) Tidies forecast objects easy plotting “tidy” data manipulation Integrates timetk enable dates datetimes (irregular time series) tidied forecast output","code":""},{"path":"https://business-science.github.io/sweep/index.html","id":"tools","dir":"","previous_headings":"","what":"Tools","title":"Tidy Tools for Forecasting","text":"package contains following elements: model tidiers: sw_tidy, sw_glance, sw_augment, sw_tidy_decomp functions extend tidy, glance, augment broom package specifically models (ets(), Arima(), bats(), etc) used forecasting. forecast tidier: sw_sweep converts forecast object tibble can easily manipulated “tidyverse”.","code":""},{"path":"https://business-science.github.io/sweep/index.html","id":"making-forecasts-in-the-tidyverse","dir":"","previous_headings":"","what":"Making forecasts in the tidyverse","title":"Tidy Tools for Forecasting","text":"sweep enables converting forecast object tibble. result ability use dplyr, tidyr, ggplot natively manipulate, analyze visualize forecasts.","code":""},{"path":"https://business-science.github.io/sweep/index.html","id":"forecasting-multiple-time-series-groups-at-scale","dir":"","previous_headings":"","what":"Forecasting multiple time series groups at scale","title":"Tidy Tools for Forecasting","text":"Often forecasts required grouped data analyse trends sub-categories. good news scaling one time series many easy various sw_ functions combination dplyr purrr.","code":""},{"path":"https://business-science.github.io/sweep/index.html","id":"forecasting-multiple-models-for-accuracy","dir":"","previous_headings":"","what":"Forecasting multiple models for accuracy","title":"Tidy Tools for Forecasting","text":"common goal forecasting compare different forecast models . sweep helps area well.","code":""},{"path":"https://business-science.github.io/sweep/index.html","id":"broom-extensions-for-forecasting","dir":"","previous_headings":"","what":"broom extensions for forecasting","title":"Tidy Tools for Forecasting","text":"familiar broom, know useful retrieving “tidy” format model components. sweep extends benefit forecast package workflow 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. compatibility chart listed . Function Compatibility","code":""},{"path":"https://business-science.github.io/sweep/index.html","id":"installation","dir":"","previous_headings":"","what":"Installation","title":"Tidy Tools for Forecasting","text":"’s get started. Development version latest features:","code":"# install.packages(\"remotes\") remotes::install_github(\"business-science/sweep\")"},{"path":"https://business-science.github.io/sweep/index.html","id":"further-information","dir":"","previous_headings":"","what":"Further Information","title":"Tidy Tools for Forecasting","text":"sweep package includes several vignettes help users get speed quickly: SW00 - Introduction sweep SW01 - Forecasting Time Series Groups tidyverse SW02 - Forecasting Using Multiple Models","code":""},{"path":"https://business-science.github.io/sweep/reference/add_index.html","id":null,"dir":"Reference","previous_headings":"","what":"Adds a sequential index column to a data frame — add_index","title":"Adds a sequential index column to a data frame — add_index","text":"Adds sequential index column data frame","code":""},{"path":"https://business-science.github.io/sweep/reference/add_index.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Adds a sequential index column to a data frame — add_index","text":"","code":"add_index(ret, rename_index)"},{"path":"https://business-science.github.io/sweep/reference/add_index.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Adds a sequential index column to a data frame — add_index","text":"ret object class tibble rename_index variable indicating index name used tibble returned","code":""},{"path":"https://business-science.github.io/sweep/reference/arima_string.html","id":null,"dir":"Reference","previous_headings":"","what":"Print the ARIMA model parameters — arima_string","title":"Print the ARIMA model parameters — arima_string","text":"Refer forecast:::arima.string. forecast arima.R","code":""},{"path":"https://business-science.github.io/sweep/reference/arima_string.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Print the ARIMA model parameters — arima_string","text":"","code":"arima_string(object, padding = FALSE)"},{"path":"https://business-science.github.io/sweep/reference/arima_string.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Print the ARIMA model parameters — arima_string","text":"object object class Arima padding Add padding name returned","code":""},{"path":"https://business-science.github.io/sweep/reference/bats_string.html","id":null,"dir":"Reference","previous_headings":"","what":"Print the BATS model parameters — bats_string","title":"Print the BATS model parameters — bats_string","text":"Refer forecast:::makeText. forecast bats.R","code":""},{"path":"https://business-science.github.io/sweep/reference/bats_string.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Print the BATS model parameters — bats_string","text":"","code":"bats_string(object)"},{"path":"https://business-science.github.io/sweep/reference/bats_string.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Print the BATS model parameters — bats_string","text":"object object class bats","code":""},{"path":"https://business-science.github.io/sweep/reference/bike_sales.html","id":null,"dir":"Reference","previous_headings":"","what":"Fictional sales data for bike shops purchasing Cannondale bikes — bike_sales","title":"Fictional sales data for bike shops purchasing Cannondale bikes — bike_sales","text":"dataset containing fictional bicycle orders spanning 2011 2015. Hypothetically, bike_sales data similar sales data mainatained business' sales data base. unit price model names come data provided model bicycle manufacturer, Cannondale (2016). customers (bicycle shops) including name, location, etc orders including quantity purchased order dates fictional. data intended implementing business analytics techniques (e.g. forecast, clustering, etc) identify underlying trends.","code":""},{"path":"https://business-science.github.io/sweep/reference/bike_sales.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Fictional sales data for bike shops purchasing Cannondale bikes — bike_sales","text":"","code":"bike_sales"},{"path":"https://business-science.github.io/sweep/reference/bike_sales.html","id":"format","dir":"Reference","previous_headings":"","what":"Format","title":"Fictional sales data for bike shops purchasing Cannondale bikes — bike_sales","text":"data frame 15644 rows 17 variables: order.date Date order placed order.id unique order identification number order.line sequential identification number products order quantity Number units purchased price unit price bicycle price.ext extended price = price x quantity customer.id unique customer identification number bikeshop.name customer name bikeshop.city city bike shop located bikeshop.state state bike shop located latitude geograhpic latitude customer location longitude geograhpic longitude customer location product.id unique product identification number model model name bicycle category.primary main bicycle category, either \"Mountain\" \"Road\" category.secondary One nine specific bicycle categories frame bicycle frame material, either \"Carbon\" \"Aluminum\"","code":""},{"path":"https://business-science.github.io/sweep/reference/bike_sales.html","id":"source","dir":"Reference","previous_headings":"","what":"Source","title":"Fictional sales data for bike shops purchasing Cannondale bikes — bike_sales","text":"2016 bicycle model names prices originated https://www.cannondale.com/en-us","code":""},{"path":"https://business-science.github.io/sweep/reference/reexports.html","id":null,"dir":"Reference","previous_headings":"","what":"Objects exported from other packages — reexports","title":"Objects exported from other packages — reexports","text":"objects imported packages. Follow links see documentation. dplyr %>%","code":""},{"path":"https://business-science.github.io/sweep/reference/sw_augment.default.html","id":null,"dir":"Reference","previous_headings":"","what":"Default augment method — sw_augment.default","title":"Default augment method — sw_augment.default","text":"default, sw_augment() uses broom::augment() convert output.","code":""},{"path":"https://business-science.github.io/sweep/reference/sw_augment.default.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Default augment method — sw_augment.default","text":"","code":"# S3 method for default sw_augment(x, ...)"},{"path":"https://business-science.github.io/sweep/reference/sw_augment.default.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Default augment method — sw_augment.default","text":"x object tidied ... extra arguments passed broom::augment()","code":""},{"path":"https://business-science.github.io/sweep/reference/sw_augment.default.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Default augment method — sw_augment.default","text":"tibble generated broom::augment()","code":""},{"path":"https://business-science.github.io/sweep/reference/sw_augment.html","id":null,"dir":"Reference","previous_headings":"","what":"Augment data according to a tidied model — sw_augment","title":"Augment data according to a tidied model — sw_augment","text":"Given R statistical model non-tidy object, add columns original dataset predictions, residuals cluster assignments.","code":""},{"path":"https://business-science.github.io/sweep/reference/sw_augment.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Augment data according to a tidied model — sw_augment","text":"","code":"sw_augment(x, ...)"},{"path":"https://business-science.github.io/sweep/reference/sw_augment.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Augment data according to a tidied model — sw_augment","text":"x model R object convert data frame ... arguments passed methods","code":""},{"path":"https://business-science.github.io/sweep/reference/sw_augment.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Augment data according to a tidied model — sw_augment","text":"sw_augment() wrapper broom::augment(). benefit sw_augment methods various time-series model classes HoltWinters, ets, Arima, etc. non-time series, sw_augment() defaults broom::augment(). difference return tibble. Note convention first argument almost always data, specifies original data object. part S3 signature, partly prevents rowwise_df_tidiers taking column name first argument.","code":""},{"path":[]},{"path":"https://business-science.github.io/sweep/reference/sw_augment_columns.html","id":null,"dir":"Reference","previous_headings":"","what":"Augments data — sw_augment_columns","title":"Augments data — sw_augment_columns","text":"Augments data","code":""},{"path":"https://business-science.github.io/sweep/reference/sw_augment_columns.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Augments data — sw_augment_columns","text":"","code":"sw_augment_columns(ret, data, rename_index, timetk_idx = FALSE)"},{"path":"https://business-science.github.io/sweep/reference/sw_augment_columns.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Augments data — sw_augment_columns","text":"ret object class tibble data time series data augmented rename_index variable indicating index name used tibble returned timetk_idx Uses timetk index (irregular time index) present.","code":""},{"path":"https://business-science.github.io/sweep/reference/sw_glance.default.html","id":null,"dir":"Reference","previous_headings":"","what":"Default glance method — sw_glance.default","title":"Default glance method — sw_glance.default","text":"default, sw_glance() uses broom::glance() convert output.","code":""},{"path":"https://business-science.github.io/sweep/reference/sw_glance.default.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Default glance method — sw_glance.default","text":"","code":"# S3 method for default sw_glance(x, ...)"},{"path":"https://business-science.github.io/sweep/reference/sw_glance.default.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Default glance method — sw_glance.default","text":"x object tidied ... extra arguments passed broom::glance()","code":""},{"path":"https://business-science.github.io/sweep/reference/sw_glance.default.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Default glance method — sw_glance.default","text":"tibble generated broom::glance()","code":""},{"path":"https://business-science.github.io/sweep/reference/sw_glance.html","id":null,"dir":"Reference","previous_headings":"","what":"Construct a single row summary ","title":"Construct a single row summary ","text":"Construct single row summary \"glance\" model, fit, object","code":""},{"path":"https://business-science.github.io/sweep/reference/sw_glance.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Construct a single row summary ","text":"","code":"sw_glance(x, ...)"},{"path":"https://business-science.github.io/sweep/reference/sw_glance.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Construct a single row summary ","text":"x model R object convert single-row data frame ... arguments passed methods","code":""},{"path":"https://business-science.github.io/sweep/reference/sw_glance.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Construct a single row summary ","text":"single-row tibble model summary information.","code":""},{"path":"https://business-science.github.io/sweep/reference/sw_glance.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Construct a single row summary ","text":"sw_glance() wrapper broom::glance(). benefit sw_glance methods various time-series model classes HoltWinters, ets, Arima, etc. sw_glance methods always return either one-row tibble NULL. single row includes summary statistics relevent model accuracy, can used assess model fit quality. non-time series, sw_glance() defaults broom::glance(). difference return tibble.","code":""},{"path":[]},{"path":"https://business-science.github.io/sweep/reference/sw_sweep.html","id":null,"dir":"Reference","previous_headings":"","what":"Tidy forecast objects — sw_sweep","title":"Tidy forecast objects — sw_sweep","text":"Tidy forecast objects","code":""},{"path":"https://business-science.github.io/sweep/reference/sw_sweep.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Tidy forecast objects — sw_sweep","text":"","code":"sw_sweep(x, fitted = FALSE, timetk_idx = FALSE, rename_index = \"index\", ...)"},{"path":"https://business-science.github.io/sweep/reference/sw_sweep.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Tidy forecast objects — sw_sweep","text":"x time-series forecast class forecast. fitted Whether return fitted values (model values) results. FALSE default. timetk_idx timetk index (non-regularized index) present, uses develop forecast. Otherwise uses default index. rename_index Enables index column renamed. ... Additional arguments passed tk_make_future_timeseries()","code":""},{"path":"https://business-science.github.io/sweep/reference/sw_sweep.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Tidy forecast objects — sw_sweep","text":"Returns tibble object.","code":""},{"path":"https://business-science.github.io/sweep/reference/sw_sweep.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Tidy forecast objects — sw_sweep","text":"sw_sweep designed coerce forecast objects forecast package tibble objects \"tidy\" format (long). returned object contains actual values forecasted values including point forecast upper lower confidence intervals. timetk_idx argument used modify return format index. timetk_idx = FALSE, regularized time index always constructed. may format numeric values (e.g. 2010.000) higher order yearmon yearqtr classes zoo package. higher order class attempted returned. timetk_idx = TRUE timetk index present, irregular time index returned combines original time series (.e. date datetime) along computed future time series created using tk_make_future_timeseries() timetk package. ... can used pass additional arguments tk_make_future_timeseries() inspect_weekdays, skip_values, etc can useful tuning future time series sequence. index column name can changed using rename_index argument.","code":""},{"path":[]},{"path":"https://business-science.github.io/sweep/reference/sw_sweep.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Tidy forecast objects — sw_sweep","text":"","code":"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 #> #> 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"},{"path":"https://business-science.github.io/sweep/reference/sw_tidy.default.html","id":null,"dir":"Reference","previous_headings":"","what":"Default tidying method — sw_tidy.default","title":"Default tidying method — sw_tidy.default","text":"default, sw_tidy() uses broom::tidy() convert output.","code":""},{"path":"https://business-science.github.io/sweep/reference/sw_tidy.default.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Default tidying method — sw_tidy.default","text":"","code":"# S3 method for default sw_tidy(x, ...)"},{"path":"https://business-science.github.io/sweep/reference/sw_tidy.default.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Default tidying method — sw_tidy.default","text":"x object tidied ... extra arguments passed broom::tidy()","code":""},{"path":"https://business-science.github.io/sweep/reference/sw_tidy.default.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Default tidying method — sw_tidy.default","text":"tibble generated broom::tidy()","code":""},{"path":"https://business-science.github.io/sweep/reference/sw_tidy.html","id":null,"dir":"Reference","previous_headings":"","what":"Tidy the result of a time-series model into a summary tibble — sw_tidy","title":"Tidy the result of a time-series model into a summary tibble — sw_tidy","text":"Tidy result time-series model summary tibble","code":""},{"path":"https://business-science.github.io/sweep/reference/sw_tidy.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Tidy the result of a time-series model into a summary tibble — sw_tidy","text":"","code":"sw_tidy(x, ...)"},{"path":"https://business-science.github.io/sweep/reference/sw_tidy.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Tidy the result of a time-series model into a summary tibble — sw_tidy","text":"x object converted tibble (\"tidy\" data.frame) ... extra arguments","code":""},{"path":"https://business-science.github.io/sweep/reference/sw_tidy.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Tidy the result of a time-series model into a summary tibble — sw_tidy","text":"tibble","code":""},{"path":"https://business-science.github.io/sweep/reference/sw_tidy.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Tidy the result of a time-series model into a summary tibble — sw_tidy","text":"sw_tidy() wrapper broom::tidy(). main benefit sw_tidy() methods various time-series model classes HoltWinters, ets, Arima, etc. sw_tidy() methods always returns \"tidy\" tibble model coefficient / parameters. non-time series, sw_tidy() defaults broom::tidy(). difference return tibble. output sw_tidy() always tibble disposable row names. therefore suited manipulation packages like dplyr ggplot2.","code":""},{"path":[]},{"path":"https://business-science.github.io/sweep/reference/sw_tidy.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Tidy the result of a time-series model into a summary tibble — sw_tidy","text":"","code":"library(dplyr) library(forecast) WWWusage %>% auto.arima() %>% sw_tidy(conf.int = TRUE) #> # A tibble: 2 × 2 #> term estimate #> #> 1 ar1 0.650 #> 2 ma1 0.526"},{"path":"https://business-science.github.io/sweep/reference/sw_tidy_decomp.html","id":null,"dir":"Reference","previous_headings":"","what":"Coerces decomposed time-series objects to tibble format. — sw_tidy_decomp","title":"Coerces decomposed time-series objects to tibble format. — sw_tidy_decomp","text":"Coerces decomposed time-series objects tibble format.","code":""},{"path":"https://business-science.github.io/sweep/reference/sw_tidy_decomp.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Coerces decomposed time-series objects to tibble format. — sw_tidy_decomp","text":"","code":"sw_tidy_decomp(x, timetk_idx = FALSE, rename_index = \"index\", ...)"},{"path":"https://business-science.github.io/sweep/reference/sw_tidy_decomp.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Coerces decomposed time-series objects to tibble format. — sw_tidy_decomp","text":"x time-series object class stl, ets, decomposed.ts, HoltWinters, bats tbats. timetk_idx TRUE, uses timetk index (irregular, typically date datetime) present. rename_index Enables index column renamed. ... used.","code":""},{"path":"https://business-science.github.io/sweep/reference/sw_tidy_decomp.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Coerces decomposed time-series objects to tibble format. — sw_tidy_decomp","text":"Returns tibble object.","code":""},{"path":"https://business-science.github.io/sweep/reference/sw_tidy_decomp.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Coerces decomposed time-series objects to tibble format. — sw_tidy_decomp","text":"sw_tidy_decomp designed coerce time-series objects decompositions tibble objects. regularized time index always constructed. time index detected, sequential index returned default. index column name can changed using rename_index argument.","code":""},{"path":"https://business-science.github.io/sweep/reference/sw_tidy_decomp.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Coerces decomposed time-series objects to tibble format. — sw_tidy_decomp","text":"","code":"library(dplyr) library(forecast) library(sweep) # Decompose ETS model USAccDeaths %>% ets() %>% sw_tidy_decomp() #> # A tibble: 73 × 4 #> index observed level season #> #> 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 #> #> 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"},{"path":"https://business-science.github.io/sweep/reference/sweep-package.html","id":null,"dir":"Reference","previous_headings":"","what":"sweep: Tidy Tools for Forecasting — sweep-package","title":"sweep: Tidy Tools for Forecasting — sweep-package","text":"sweep package \"tidies\" modeling workflow forecast package.","code":""},{"path":"https://business-science.github.io/sweep/reference/sweep-package.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"sweep: Tidy Tools for Forecasting — sweep-package","text":"model forecast objects covered broom package. includes sw_tidy(), sw_glance(), sw_augment() functions work similar capacity broom functions. addition, provides sw_tidy_decomp() tidy decomposition, sw_sweep() coerce forecast objects \"tibbles\" easy visualization ggplot2 manipulation dplyr. learn sweep, start vignettes: browseVignettes(package = \"sweep\")","code":""},{"path":[]},{"path":"https://business-science.github.io/sweep/reference/sweep-package.html","id":"author","dir":"Reference","previous_headings":"","what":"Author","title":"sweep: Tidy Tools for Forecasting — sweep-package","text":"Maintainer: Matt Dancho mdancho@business-science.io Authors: Davis Vaughan dvaughan@business-science.io","code":""},{"path":"https://business-science.github.io/sweep/reference/tbats_string.html","id":null,"dir":"Reference","previous_headings":"","what":"Print the TBATS model parameters — tbats_string","title":"Print the TBATS model parameters — tbats_string","text":"Refer forecast:::makeTextTBATS. forecast bats.R","code":""},{"path":"https://business-science.github.io/sweep/reference/tbats_string.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Print the TBATS model parameters — tbats_string","text":"","code":"tbats_string(object)"},{"path":"https://business-science.github.io/sweep/reference/tbats_string.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Print the TBATS model parameters — tbats_string","text":"object object class bats tbats","code":""},{"path":"https://business-science.github.io/sweep/reference/tidiers_HoltWinters.html","id":null,"dir":"Reference","previous_headings":"","what":"Tidying methods for HoltWinters modeling of time series — tidiers_HoltWinters","title":"Tidying methods for HoltWinters modeling of time series — tidiers_HoltWinters","text":"methods tidy HoltWinters models univariate time series.","code":""},{"path":"https://business-science.github.io/sweep/reference/tidiers_HoltWinters.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Tidying methods for HoltWinters modeling of time series — tidiers_HoltWinters","text":"","code":"# 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\", ...)"},{"path":"https://business-science.github.io/sweep/reference/tidiers_HoltWinters.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Tidying methods for HoltWinters modeling of time series — tidiers_HoltWinters","text":"x object class \"HoltWinters\" ... Additional parameters (used) data Used sw_augment . NULL default simply returns augmented columns . User can supply original data, returns data + augmented columns. rename_index Used sw_augment . string representing name index generated. timetk_idx Used sw_augment sw_tidy_decomp. TRUE, uses timetk index (irregular, typically date datetime) present.","code":""},{"path":"https://business-science.github.io/sweep/reference/tidiers_HoltWinters.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Tidying methods for HoltWinters modeling of time series — tidiers_HoltWinters","text":"sw_tidy() returns one row model parameter, two columns: term: various parameters (alpha, beta, gamma, coefficients) estimate: estimated parameter value sw_glance() returns one row following columns: model.desc: description model sigma: square root estimated residual variance logLik: data's log-likelihood model AIC: Akaike Information Criterion BIC: Bayesian Information Criterion (NA bats / tbats) : 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 errors lag 1 sw_augment() returns tibble following time series attributes: index: index either attempted extracted model sequential index created plotting purposes .actual: original time series .fitted: fitted values model .resid: residual values model sw_tidy_decomp() returns tibble following time series attributes: index: index either attempted extracted model sequential index created plotting purposes observed: original time series season: seasonal component trend: trend component remainder: observed - (season + trend) seasadj: observed - season (trend + remainder)","code":""},{"path":[]},{"path":"https://business-science.github.io/sweep/reference/tidiers_HoltWinters.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Tidying methods for HoltWinters modeling of time series — tidiers_HoltWinters","text":"","code":"library(dplyr) library(forecast) fit_hw <- USAccDeaths %>% stats::HoltWinters() sw_tidy(fit_hw) #> # A tibble: 17 × 2 #> term estimate #> #> 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 #> #> 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 #> #> 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 #> #> 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"},{"path":"https://business-science.github.io/sweep/reference/tidiers_StructTS.html","id":null,"dir":"Reference","previous_headings":"","what":"Tidying methods for StructTS (Error, Trend, Seasonal) / exponential smoothing\nmodeling of time series — tidiers_StructTS","title":"Tidying methods for StructTS (Error, Trend, Seasonal) / exponential smoothing\nmodeling of time series — tidiers_StructTS","text":"methods tidy coefficients StructTS models univariate time series.","code":""},{"path":"https://business-science.github.io/sweep/reference/tidiers_StructTS.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Tidying methods for StructTS (Error, Trend, Seasonal) / exponential smoothing\nmodeling of time series — tidiers_StructTS","text":"","code":"# 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\", ...)"},{"path":"https://business-science.github.io/sweep/reference/tidiers_StructTS.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Tidying methods for StructTS (Error, Trend, Seasonal) / exponential smoothing\nmodeling of time series — tidiers_StructTS","text":"x object class \"StructTS\" ... Additional parameters (used) data Used sw_augment . NULL default simply returns augmented columns . User can supply original data, returns data + augmented columns. timetk_idx Used sw_augment . Uses irregular timetk index present. rename_index Used sw_augment . string representing name index generated.","code":""},{"path":"https://business-science.github.io/sweep/reference/tidiers_StructTS.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Tidying methods for StructTS (Error, Trend, Seasonal) / exponential smoothing\nmodeling of time series — tidiers_StructTS","text":"sw_tidy() returns one row model parameter, two columns: term: model parameters estimate: estimated parameter value sw_glance() returns one row columns model.desc: description model including three integer components (p, d, q) AR order, degree differencing, MA order. sigma: square root estimated residual variance logLik: data's log-likelihood model AIC: Akaike Information Criterion BIC: Bayesian Information Criterion : 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 errors lag 1 sw_augment() returns tibble following time series attributes: index: index either attempted extracted model sequential index created plotting purposes .actual: original time series .fitted: fitted values model .resid: residual values model","code":""},{"path":[]},{"path":"https://business-science.github.io/sweep/reference/tidiers_StructTS.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Tidying methods for StructTS (Error, Trend, Seasonal) / exponential smoothing\nmodeling of time series — tidiers_StructTS","text":"","code":"library(dplyr) library(forecast) fit_StructTS <- WWWusage %>% StructTS() sw_tidy(fit_StructTS) #> # A tibble: 3 × 2 #> term estimate #> #> 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 #> #> 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 sw_augment(fit_StructTS) #> # A tibble: 100 × 4 #> index .actual .fitted .resid #> #> 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"},{"path":"https://business-science.github.io/sweep/reference/tidiers_arima.html","id":null,"dir":"Reference","previous_headings":"","what":"Tidying methods for ARIMA modeling of time series — tidiers_arima","title":"Tidying methods for ARIMA modeling of time series — tidiers_arima","text":"methods tidy coefficients ARIMA models univariate time series.","code":""},{"path":"https://business-science.github.io/sweep/reference/tidiers_arima.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Tidying methods for ARIMA modeling of time series — tidiers_arima","text":"","code":"# 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, ...)"},{"path":"https://business-science.github.io/sweep/reference/tidiers_arima.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Tidying methods for ARIMA modeling of time series — tidiers_arima","text":"x object class \"Arima\" ... Additional parameters (used) data Used sw_augment . NULL default simply returns augmented columns . User can supply original data, returns data + augmented columns. rename_index Used sw_augment . string representing name index generated. timetk_idx Used sw_augment . Uses irregular timetk index present.","code":""},{"path":"https://business-science.github.io/sweep/reference/tidiers_arima.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Tidying methods for ARIMA modeling of time series — tidiers_arima","text":"sw_tidy() returns one row coefficient model, five columns: term: term nonlinear model estimated tested estimate: estimated coefficient sw_glance() returns one row columns model.desc: description model including three integer components (p, d, q) AR order, degree differencing, MA order. sigma: square root estimated residual variance logLik: data's log-likelihood model AIC: Akaike Information Criterion BIC: Bayesian Information Criterion : 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 errors lag 1 sw_augment() returns tibble following time series attributes: index: index either attempted extracted model sequential index created plotting purposes .actual: original time series .fitted: fitted values model .resid: residual values model sw_tidy() returns underlying ETS ARIMA model's sw_tidy() one row coefficient model, five columns: term: term nonlinear model estimated tested estimate: estimated coefficient","code":""},{"path":[]},{"path":"https://business-science.github.io/sweep/reference/tidiers_arima.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Tidying methods for ARIMA modeling of time series — tidiers_arima","text":"","code":"library(dplyr) library(forecast) fit_arima <- WWWusage %>% auto.arima() sw_tidy(fit_arima) #> # A tibble: 2 × 2 #> term estimate #> #> 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 #> #> 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 sw_augment(fit_arima) #> # A tibble: 100 × 4 #> index .actual .fitted .resid #> #> 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"},{"path":"https://business-science.github.io/sweep/reference/tidiers_bats.html","id":null,"dir":"Reference","previous_headings":"","what":"Tidying methods for BATS and TBATS modeling of time series — tidiers_bats","title":"Tidying methods for BATS and TBATS modeling of time series — tidiers_bats","text":"Tidying methods BATS TBATS modeling time series","code":""},{"path":"https://business-science.github.io/sweep/reference/tidiers_bats.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Tidying methods for BATS and TBATS modeling of time series — tidiers_bats","text":"","code":"# 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\", ...)"},{"path":"https://business-science.github.io/sweep/reference/tidiers_bats.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Tidying methods for BATS and TBATS modeling of time series — tidiers_bats","text":"x object class \"bats\" \"tbats\" ... Additional parameters (used) data Used sw_augment . NULL default simply returns augmented columns . User can supply original data, returns data + augmented columns. rename_index Used sw_augment . string representing name index generated. timetk_idx Used sw_augment sw_tidy_decomp. TRUE, uses timetk index (irregular, typically date datetime) present.","code":""},{"path":"https://business-science.github.io/sweep/reference/tidiers_bats.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Tidying methods for BATS and TBATS modeling of time series — tidiers_bats","text":"sw_tidy() returns one row model parameter, two columns: term: various parameters (lambda, alpha, gamma, etc) estimate: estimated parameter value sw_glance() returns one row columns model.desc: description model including three integer components (p, d, q) AR order, degree differencing, MA order. sigma: square root estimated residual variance logLik: data's log-likelihood model AIC: Akaike Information Criterion BIC: Bayesian Information Criterion (NA bats / tbats) : 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 errors lag 1 sw_augment() returns tibble following time series attributes: index: index either attempted extracted model sequential index created plotting purposes .actual: original time series .fitted: fitted values model .resid: residual values model sw_tidy_decomp() returns tibble following time series attributes: index: index either attempted extracted model sequential index created plotting purposes observed: original time series level: level component slope: slope component (always present) season: seasonal component (always present)","code":""},{"path":[]},{"path":"https://business-science.github.io/sweep/reference/tidiers_bats.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Tidying methods for BATS and TBATS modeling of time series — tidiers_bats","text":"","code":"library(dplyr) library(forecast) fit_bats <- WWWusage %>% bats() sw_tidy(fit_bats) #> # A tibble: 7 × 2 #> term estimate #> #> 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 #> #> 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 #> #> 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"},{"path":"https://business-science.github.io/sweep/reference/tidiers_decomposed_ts.html","id":null,"dir":"Reference","previous_headings":"","what":"Tidying methods for decomposed time series — tidiers_decomposed_ts","title":"Tidying methods for decomposed time series — tidiers_decomposed_ts","text":"Tidying methods decomposed time series","code":""},{"path":"https://business-science.github.io/sweep/reference/tidiers_decomposed_ts.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Tidying methods for decomposed time series — tidiers_decomposed_ts","text":"","code":"# S3 method for decomposed.ts sw_tidy_decomp(x, timetk_idx = FALSE, rename_index = \"index\", ...)"},{"path":"https://business-science.github.io/sweep/reference/tidiers_decomposed_ts.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Tidying methods for decomposed time series — tidiers_decomposed_ts","text":"x object class \"decomposed.ts\" timetk_idx Used sw_augment sw_tidy_decomp. TRUE, uses timetk index (irregular, typically date datetime) present. rename_index Used sw_augment sw_tidy_decomp. string representing name index generated. ... used.","code":""},{"path":"https://business-science.github.io/sweep/reference/tidiers_decomposed_ts.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Tidying methods for decomposed time series — tidiers_decomposed_ts","text":"sw_tidy_decomp() returns tibble following time series attributes: index: index either attempted extracted model sequential index created plotting purposes season: seasonal component trend: trend component random: error component seasadj: observed - season","code":""},{"path":[]},{"path":"https://business-science.github.io/sweep/reference/tidiers_decomposed_ts.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Tidying methods for decomposed time series — tidiers_decomposed_ts","text":"","code":"library(dplyr) library(forecast) fit_decomposed <- USAccDeaths %>% decompose() sw_tidy_decomp(fit_decomposed) #> # A tibble: 72 × 6 #> index observed season trend random seasadj #> #> 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"},{"path":"https://business-science.github.io/sweep/reference/tidiers_ets.html","id":null,"dir":"Reference","previous_headings":"","what":"Tidying methods for ETS (Error, Trend, Seasonal) exponential smoothing\nmodeling of time series — tidiers_ets","title":"Tidying methods for ETS (Error, Trend, Seasonal) exponential smoothing\nmodeling of time series — tidiers_ets","text":"Tidying methods ETS (Error, Trend, Seasonal) exponential smoothing modeling time series","code":""},{"path":"https://business-science.github.io/sweep/reference/tidiers_ets.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Tidying methods for ETS (Error, Trend, Seasonal) exponential smoothing\nmodeling of time series — tidiers_ets","text":"","code":"# 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\", ...)"},{"path":"https://business-science.github.io/sweep/reference/tidiers_ets.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Tidying methods for ETS (Error, Trend, Seasonal) exponential smoothing\nmodeling of time series — tidiers_ets","text":"x object class \"ets\" ... used. data Used sw_augment . NULL default simply returns augmented columns . User can supply original data, returns data + augmented columns. timetk_idx Used sw_augment sw_tidy_decomp. TRUE, uses timetk index (irregular, typically date datetime) present. rename_index Used sw_augment sw_tidy_decomp. string representing name index generated.","code":""},{"path":"https://business-science.github.io/sweep/reference/tidiers_ets.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Tidying methods for ETS (Error, Trend, Seasonal) exponential smoothing\nmodeling of time series — tidiers_ets","text":"sw_tidy() returns one row model parameter, two columns: term: smoothing parameters (alpha, gamma) initial states (l, s0 s10) estimate: estimated parameter value sw_glance() returns one row columns model.desc: description model including three integer components (p, d, q) AR order, degree differencing, MA order. sigma: square root estimated residual variance logLik: data's log-likelihood model AIC: Akaike Information Criterion BIC: Bayesian Information Criterion : 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 errors lag 1 sw_augment() returns tibble following time series attributes: index: index either attempted extracted model sequential index created plotting purposes .actual: original time series .fitted: fitted values model .resid: residual values model sw_tidy_decomp() returns tibble following time series attributes: index: index either attempted extracted model sequential index created plotting purposes observed: original time series level: level component slope: slope component (always present) season: seasonal component (always present)","code":""},{"path":[]},{"path":"https://business-science.github.io/sweep/reference/tidiers_ets.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Tidying methods for ETS (Error, Trend, Seasonal) exponential smoothing\nmodeling of time series — tidiers_ets","text":"","code":"library(dplyr) library(forecast) fit_ets <- WWWusage %>% ets() sw_tidy(fit_ets) #> # A tibble: 5 × 2 #> term estimate #> #> 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 #> #> 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 #> #> 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 #> #> 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"},{"path":"https://business-science.github.io/sweep/reference/tidiers_nnetar.html","id":null,"dir":"Reference","previous_headings":"","what":"Tidying methods for Nural Network Time Series models — tidiers_nnetar","title":"Tidying methods for Nural Network Time Series models — tidiers_nnetar","text":"methods tidy coefficients NNETAR models univariate time series.","code":""},{"path":"https://business-science.github.io/sweep/reference/tidiers_nnetar.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Tidying methods for Nural Network Time Series models — tidiers_nnetar","text":"","code":"# 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\", ...)"},{"path":"https://business-science.github.io/sweep/reference/tidiers_nnetar.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Tidying methods for Nural Network Time Series models — tidiers_nnetar","text":"x object class \"nnetar\" ... Additional parameters (used) data Used sw_augment . NULL default simply returns augmented columns . User can supply original data, returns data + augmented columns. timetk_idx Used sw_augment . Uses irregular timetk index present. rename_index Used sw_augment . string representing name index generated.","code":""},{"path":"https://business-science.github.io/sweep/reference/tidiers_nnetar.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Tidying methods for Nural Network Time Series models — tidiers_nnetar","text":"sw_tidy() returns one row model parameter, two columns: term: smoothing parameters (alpha, gamma) initial states (l, s0 s10) estimate: estimated parameter value sw_glance() returns one row columns model.desc: description model including three integer components (p, d, q) AR order, degree differencing, MA order. sigma: square root estimated residual variance logLik: data's log-likelihood model (NA) AIC: Akaike Information Criterion (NA) BIC: Bayesian Information Criterion (NA) : 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 errors lag 1 sw_augment() returns tibble following time series attributes: index: index either attempted extracted model sequential index created plotting purposes .actual: original time series .fitted: fitted values model .resid: residual values model","code":""},{"path":[]},{"path":"https://business-science.github.io/sweep/reference/tidiers_nnetar.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Tidying methods for Nural Network Time Series models — tidiers_nnetar","text":"","code":"library(dplyr) library(forecast) fit_nnetar <- lynx %>% nnetar() sw_tidy(fit_nnetar) #> # A tibble: 4 × 2 #> term estimate #> #> 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 #> #> 1 NNAR(8,4) 266. NA NA NA 0.0817 266. 198. -37.7 52.0 0.238 #> # ℹ 1 more variable: ACF1 sw_augment(fit_nnetar) #> # A tibble: 114 × 4 #> index .actual .fitted .resid #> #> 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 4618. 332. #> 10 1830 2577 2614. -37.1 #> # ℹ 104 more rows"},{"path":"https://business-science.github.io/sweep/reference/tidiers_stl.html","id":null,"dir":"Reference","previous_headings":"","what":"Tidying methods for STL (Seasonal, Trend, Level) decomposition of time series — tidiers_stl","title":"Tidying methods for STL (Seasonal, Trend, Level) decomposition of time series — tidiers_stl","text":"Tidying methods STL (Seasonal, Trend, Level) decomposition time series","code":""},{"path":"https://business-science.github.io/sweep/reference/tidiers_stl.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Tidying methods for STL (Seasonal, Trend, Level) decomposition of time series — tidiers_stl","text":"","code":"# 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, ...)"},{"path":"https://business-science.github.io/sweep/reference/tidiers_stl.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Tidying methods for STL (Seasonal, Trend, Level) decomposition of time series — tidiers_stl","text":"x object class \"stl\" ... used. timetk_idx Used sw_tidy_decomp. TRUE, uses timetk index (irregular, typically date datetime) present. rename_index Used sw_tidy_decomp. string representing name index generated. data Used sw_augment .","code":""},{"path":"https://business-science.github.io/sweep/reference/tidiers_stl.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Tidying methods for STL (Seasonal, Trend, Level) decomposition of time series — tidiers_stl","text":"sw_tidy() wraps sw_tidy_decomp() sw_tidy_decomp() returns tibble following time series attributes: index: index either attempted extracted model sequential index created plotting purposes season: seasonal component trend: trend component remainder: observed - (season + trend) seasadj: observed - season (trend + remainder) sw_glance() returns underlying ETS ARIMA model's sw_glance() results one row columns model.desc: description model including three integer components (p, d, q) AR order, degree differencing, MA order. sigma: square root estimated residual variance logLik: data's log-likelihood model AIC: Akaike Information Criterion BIC: Bayesian Information Criterion : 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 errors lag 1 sw_augment() returns tibble following time series attributes: index: index either attempted extracted model sequential index created plotting purposes .actual: original time series .fitted: fitted values model .resid: residual values model","code":""},{"path":[]},{"path":"https://business-science.github.io/sweep/reference/tidiers_stl.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Tidying methods for STL (Seasonal, Trend, Level) decomposition of time series — tidiers_stl","text":"","code":"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 #> #> 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"},{"path":"https://business-science.github.io/sweep/reference/validate_index.html","id":null,"dir":"Reference","previous_headings":"","what":"Validates data frame has column named the same name as variable rename_index — validate_index","title":"Validates data frame has column named the same name as variable rename_index — validate_index","text":"Validates data frame column named name variable rename_index","code":""},{"path":"https://business-science.github.io/sweep/reference/validate_index.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Validates data frame has column named the same name as variable rename_index — validate_index","text":"","code":"validate_index(ret, rename_index)"},{"path":"https://business-science.github.io/sweep/reference/validate_index.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Validates data frame has column named the same name as variable rename_index — validate_index","text":"ret object class tibble rename_index variable indicating index name used tibble returned","code":""},{"path":"https://business-science.github.io/sweep/news/index.html","id":"sweep-development-version","dir":"Changelog","previous_headings":"","what":"sweep (development version)","title":"sweep (development version)","text":"sweep longer imports tidyverse. (@olivroy, #22) Remove internal usage dplyr::select_(). (@olivroy, #22)","code":""},{"path":"https://business-science.github.io/sweep/news/index.html","id":"sweep-025","dir":"Changelog","previous_headings":"","what":"sweep 0.2.5","title":"sweep 0.2.5","text":"CRAN release: 2023-07-06 Fixes get sweep back CRAN following inadvertent timetk archival.","code":""},{"path":"https://business-science.github.io/sweep/news/index.html","id":"sweep-024","dir":"Changelog","previous_headings":"","what":"sweep 0.2.4","title":"sweep 0.2.4","text":"Remove support robets.","code":""},{"path":"https://business-science.github.io/sweep/news/index.html","id":"sweep-023","dir":"Changelog","previous_headings":"","what":"sweep 0.2.3","title":"sweep 0.2.3","text":"CRAN release: 2020-07-10 Fixes compatability broom v0.7.0 Add tidiers stlm() models","code":""},{"path":"https://business-science.github.io/sweep/news/index.html","id":"sweep-022","dir":"Changelog","previous_headings":"","what":"sweep 0.2.2","title":"sweep 0.2.2","text":"CRAN release: 2019-10-08 Fixes compatability tidyquant v0.5.7","code":""},{"path":"https://business-science.github.io/sweep/news/index.html","id":"sweep-021","dir":"Changelog","previous_headings":"","what":"sweep 0.2.1","title":"sweep 0.2.1","text":"CRAN release: 2018-03-03 Fixes forecast::mstl","code":""},{"path":"https://business-science.github.io/sweep/news/index.html","id":"sweep-020","dir":"Changelog","previous_headings":"","what":"sweep 0.2.0","title":"sweep 0.2.0","text":"CRAN release: 2017-07-26 Change timetk timekit. Fix Issue #2 - sw_tidy fails auto.arima() returns terms (coefficients).","code":""},{"path":"https://business-science.github.io/sweep/news/index.html","id":"sweep-010","dir":"Changelog","previous_headings":"","what":"sweep 0.1.0","title":"sweep 0.1.0","text":"CRAN release: 2017-07-03 Initial release sweep, tool “tidy” forecast modeling prediction workflow.","code":""}] +[{"path":"https://business-science.github.io/sweep/articles/SW00_Introduction_to_sweep.html","id":"prerequisites","dir":"Articles","previous_headings":"","what":"Prerequisites","title":"Introduction to sweep","text":"get started, load following packages.","code":"library(ggplot2) library(tidyquant) library(timetk) library(sweep) library(forecast)"},{"path":"https://business-science.github.io/sweep/articles/SW00_Introduction_to_sweep.html","id":"forecasting-sales-of-beer-wine-and-distilled-alcohol-beverages","dir":"Articles","previous_headings":"","what":"Forecasting Sales of Beer, Wine, and Distilled Alcohol Beverages","title":"Introduction to sweep","text":"’ll use tidyquant package get US alcohol sales, comes FRED data base (origin US Bureau Census, one 80+ data sources FRED connects ). FRED code “S4248SM144NCEN” data set can found . can quickly visualize using ggplot2 package. can see appears seasonality upward trend.","code":"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 ## ## 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 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'"},{"path":"https://business-science.github.io/sweep/articles/SW00_Introduction_to_sweep.html","id":"forecasting-workflow","dir":"Articles","previous_headings":"","what":"Forecasting Workflow","title":"Introduction to sweep","text":"forecasting workflow involves basic steps: Step 1: Coerce ts object class. Step 2: Apply model (set models) Step 3: Forecast models (similar predict) Step 4: Use sw_sweep() tidy forecast. Note purposely omit steps testing series stationarity (Box.test(type = \"Ljung\")) analysis autocorrelations (Acf, Pacf) brevity purposes. recommend analyst follow forecasting workflow “Forecasting: principles practice”","code":""},{"path":"https://business-science.github.io/sweep/articles/SW00_Introduction_to_sweep.html","id":"step-1-coerce-to-a-ts-object-class","dir":"Articles","previous_headings":"Forecasting Workflow","what":"Step 1: Coerce to a ts object class","title":"Introduction to sweep","text":"forecast package uses ts data structure, quite bit different tibbles currently using. Fortunately, ’s easy get correct structure tk_ts() timetk package. start freq variables required regularized time series (ts) class, specify treat time series. monthly, frequency specified 12. results nice calendar view. silent = TRUE tells tk_ts() function skip warning notifying us “date” column dropped. Non-numeric columns must dropped ts class, matrix based homogeneous data class. significant benefit resulting ts object maintains “timetk index”, help forecasting dates later. can verify using has_timetk_idx() timetk package. Now time series coerced, let’s proceed modeling.","code":"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 has_timetk_idx(alcohol_sales_ts) ## [1] TRUE"},{"path":"https://business-science.github.io/sweep/articles/SW00_Introduction_to_sweep.html","id":"step-2-modeling-a-time-series","dir":"Articles","previous_headings":"Forecasting Workflow","what":"Step 2: Modeling a time series","title":"Introduction to sweep","text":"modeling workflow takes time series object applies model. Nothing new : ’ll simply use ets() function forecast package get Exponential Smoothing ETS (Error, Trend, Seasonal) model. sweep can help evaluation model. Expanding broom package four functions: sw_tidy(): Returns tibble model parameters sw_glance(): Returns model accuracy measurements sw_augment(): Returns fitted residuals model sw_tidy_decomp(): Returns tidy decomposition model guide shows model object compatibility sweep tidier functions. Function Compatibility Going tidiers, can get useful model information.","code":"fit_ets <- alcohol_sales_ts %>% ets()"},{"path":"https://business-science.github.io/sweep/articles/SW00_Introduction_to_sweep.html","id":"sw_tidy","dir":"Articles","previous_headings":"Forecasting Workflow > Step 2: Modeling a time series","what":"sw_tidy","title":"Introduction to sweep","text":"sw_tidy() returns model parameters.","code":"sw_tidy(fit_ets) ## # A tibble: 17 × 2 ## term estimate ## ## 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"},{"path":"https://business-science.github.io/sweep/articles/SW00_Introduction_to_sweep.html","id":"sw_glance","dir":"Articles","previous_headings":"Forecasting Workflow > Step 2: Modeling a time series","what":"sw_glance","title":"Introduction to sweep","text":"sw_glance() returns model quality parameters.","code":"sw_glance(fit_ets) ## # A tibble: 1 × 12 ## model.desc sigma logLik AIC BIC ME RMSE MAE MPE MAPE MASE ## ## 1 ETS(M,Ad,M) 0.0458 -1012. 2060. 2111. 40.7 431. 357. 0.223 3.54 0.705 ## # ℹ 1 more variable: ACF1 "},{"path":"https://business-science.github.io/sweep/articles/SW00_Introduction_to_sweep.html","id":"sw_augment","dir":"Articles","previous_headings":"Forecasting Workflow > Step 2: Modeling a time series","what":"sw_augment","title":"Introduction to sweep","text":"sw_augment() returns actual, fitted residual values. can review residuals determine underlying patterns left. Note index class yearmon, regularized date format.","code":"augment_fit_ets <- sw_augment(fit_ets) augment_fit_ets ## # A tibble: 120 × 4 ## index .actual .fitted .resid ## ## 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 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'"},{"path":"https://business-science.github.io/sweep/articles/SW00_Introduction_to_sweep.html","id":"sw_tidy_decomp","dir":"Articles","previous_headings":"Forecasting Workflow > Step 2: Modeling a time series","what":"sw_tidy_decomp","title":"Introduction to sweep","text":"sw_tidy_decomp() returns decomposition ETS model. can review decomposition using ggplot2 well. data need manipulated slightly facet visualization. gather() function tidyr package used reshape data long format data frame column names “key” “value” indicating columns except index reshaped. “key” column mutated using mutate() factor preserves order keys “observed” comes first plotting. normal circumstances make sense refine model point. However, interest showing capabilities (rather forecast) move onto forecasting model. information forecast, please refer online book “Forecasting: principles practices”.","code":"decomp_fit_ets <- sw_tidy_decomp(fit_ets) decomp_fit_ets ## # A tibble: 121 × 5 ## index observed level slope season ## ## 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 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()`)."},{"path":"https://business-science.github.io/sweep/articles/SW00_Introduction_to_sweep.html","id":"step-3-forecasting-the-model","dir":"Articles","previous_headings":"Forecasting Workflow","what":"Step 3: Forecasting the model","title":"Introduction to sweep","text":"Next forecast ETS model using forecast() function. returned forecast object isn’t “tidy” format (.e. data frame). sw_sweep() function helps.","code":"fcast_ets <- fit_ets %>% forecast(h = 12)"},{"path":"https://business-science.github.io/sweep/articles/SW00_Introduction_to_sweep.html","id":"step-4-tidy-the-forecast-object","dir":"Articles","previous_headings":"Forecasting Workflow","what":"Step 4: Tidy the forecast object","title":"Introduction to sweep","text":"’ll use sw_sweep() function coerce forecast “tidy” data frame. sw_sweep() function coerces forecast object tibble can sent ggplot visualization. Let’s inspect result. tibble returned contains “index”, “key” “value” (case “price”) columns long “tidy” format ideal visualization ggplot2. “index” regularized format (case yearmon) forecast package uses ts objects. ’ll see can get back original irregularized format (case date) later. “key” “price” columns contains three groups key-value pairs: actual: actual values original data fitted: model values returned ets() function (excluded default) forecast: predicted values forecast() function sw_sweep() function contains argument fitted = FALSE default meaning model “fitted” values returned. can toggle desired. remaining columns forecast confidence intervals (typically 80 95, can changed forecast(level = c(80, 95))). columns setup wide format enable using geom_ribbon(). Let’s visualize forecast ggplot2. ’ll use combination geom_line() geom_ribbon(). fitted values toggled default reduce complexity plot, can added desired. Note using regular time index yearmon class, need add scale_x_yearmon(). ts object created tk_ts() function, contained timetk index carried throughout forecasting workflow. result, can use timetk_idx argument, maps original irregular index (dates) generated future index regularized time series (yearmon). results ability return index date datetime, currently possible forecast objects. Notice index returned date class. can build plot dates x-axis now. example, much benefit returning irregular time series. However, working frequencies monthly, ability return irregular index values becomes apparent.","code":"sw_sweep(fcast_ets, fitted = TRUE) ## # A tibble: 252 × 7 ## index key price lo.80 lo.95 hi.80 hi.95 ## ## 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 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() 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 ## ## 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 ## ## 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. 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"},{"path":"https://business-science.github.io/sweep/articles/SW00_Introduction_to_sweep.html","id":"recap","dir":"Articles","previous_headings":"","what":"Recap","title":"Introduction to sweep","text":"overview various functions within sweep package can used assist forecast analysis. next vignette, discuss powerful concepts including forecasting scale grouped time series analysis.","code":""},{"path":"https://business-science.github.io/sweep/articles/SW01_Forecasting_Time_Series_Groups.html","id":"prerequisites","dir":"Articles","previous_headings":"","what":"Prerequisites","title":"Forecasting Time Series Groups in the tidyverse","text":"get started, load following packages.","code":"library(dplyr) library(ggplot2) library(tidyr) library(purrr) library(lubridate) library(tidyquant) library(timetk) library(sweep) library(forecast)"},{"path":"https://business-science.github.io/sweep/articles/SW01_Forecasting_Time_Series_Groups.html","id":"bike-sales","dir":"Articles","previous_headings":"","what":"Bike Sales","title":"Forecasting Time Series Groups in the tidyverse","text":"’ll use bike sales data set, bike_sales, provided sweep package tutorial. bike_sales data set fictional daily order history spans 2011 2015. simulates sales database typical business. customers “bike shops” products “models”. ’ll analyse monthly sales trends bicycle manufacturer. Let’s transform data set aggregating month. can visualize package month plot using ggplot2 . Suppose Manufacturing wants granular forecast bike components related secondary category. next section discuss sweep can help perform forecast sub-category.","code":"bike_sales ## # A tibble: 15,644 × 17 ## order.date order.id order.line quantity price price.ext customer.id ## ## 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 , bikeshop.city , ## # bikeshop.state , latitude , longitude , product.id , ## # model , category.primary , category.secondary , frame 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 ## ## 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 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()"},{"path":"https://business-science.github.io/sweep/articles/SW01_Forecasting_Time_Series_Groups.html","id":"performing-forecasts-on-groups","dir":"Articles","previous_headings":"","what":"Performing Forecasts on Groups","title":"Forecasting Time Series Groups in the tidyverse","text":"First, need get data organized groups month year. ’ll create new “order.month” date using zoo::.yearmon() captures year month information “order.date” passing lubridate::as_date() convert date format. Next, use nest() function tidyr package consolidate time series group. newly created list-column, “data.tbl”, contains “order.month” “total.qty” columns group previous step. nest() function just bundles data together useful iterative functional programming.","code":"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 ## ## 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 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 ## ## 1 Cross Country Race ## 2 Cyclocross ## 3 Elite Road ## 4 Endurance Road ## 5 Fat Bike ## 6 Over Mountain ## 7 Sport ## 8 Trail ## 9 Triathalon "},{"path":"https://business-science.github.io/sweep/articles/SW01_Forecasting_Time_Series_Groups.html","id":"forecasting-workflow","dir":"Articles","previous_headings":"Performing Forecasts on Groups","what":"Forecasting Workflow","title":"Forecasting Time Series Groups in the tidyverse","text":"forecasting workflow involves basic steps: Step 1: Coerce ts object class. Step 2: Apply model (set models) Step 3: Forecast models (similar predict) Step 4: Tidy forecast","code":""},{"path":"https://business-science.github.io/sweep/articles/SW01_Forecasting_Time_Series_Groups.html","id":"step-1-coerce-to-a-ts-object-class","dir":"Articles","previous_headings":"Performing Forecasts on Groups","what":"Step 1: Coerce to a ts object class","title":"Forecasting Time Series Groups in the tidyverse","text":"step map tk_ts() function new column “data.ts”. procedure performed using combination dplyr::mutate() purrr::map(), works really well data science workflow analyses built progressively. result, combination used many subsequent steps vignette build analysis.","code":""},{"path":"https://business-science.github.io/sweep/articles/SW01_Forecasting_Time_Series_Groups.html","id":"mutate-and-map","dir":"Articles","previous_headings":"Performing Forecasts on Groups > Step 1: Coerce to a ts object class","what":"mutate and map","title":"Forecasting Time Series Groups in the tidyverse","text":"mutate() function adds column, map() function maps contents list-column (.x) function (.f). case, .x = data.tbl .f = tk_ts. arguments select = -order.month, start = 2011, freq = 12 passed ... parameters map, passed function. select statement used drop “order.month” final output don’t get bunch warning messages. specify start = 2011 freq = 12 return monthly frequency.","code":"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 ## ## 1 Cross Country Race ## 2 Cyclocross ## 3 Elite Road ## 4 Endurance Road ## 5 Fat Bike ## 6 Over Mountain ## 7 Sport ## 8 Trail ## 9 Triathalon "},{"path":"https://business-science.github.io/sweep/articles/SW01_Forecasting_Time_Series_Groups.html","id":"step-2-modeling-a-time-series","dir":"Articles","previous_headings":"Performing Forecasts on Groups","what":"Step 2: Modeling a time series","title":"Forecasting Time Series Groups in the tidyverse","text":"Next, map Exponential Smoothing ETS (Error, Trend, Seasonal) model function, ets, forecast package. Use combination mutate add column map interatively apply function rowwise list-column. instance, function map ets function list-column “data.ts”. rename resultant column “fit.ets” indicating ETS model fit time series data. point, can model inspection sweep tidiers.","code":"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 ## ## 1 Cross Country Race ## 2 Cyclocross ## 3 Elite Road ## 4 Endurance Road ## 5 Fat Bike ## 6 Over Mountain ## 7 Sport ## 8 Trail ## 9 Triathalon "},{"path":"https://business-science.github.io/sweep/articles/SW01_Forecasting_Time_Series_Groups.html","id":"sw_tidy","dir":"Articles","previous_headings":"Performing Forecasts on Groups > Step 2: Modeling a time series","what":"sw_tidy","title":"Forecasting Time Series Groups in the tidyverse","text":"get model parameters nested list, can combine sw_tidy within mutate map combo. real difference now unnest generated column (named “tidy”). Last, ’s easier compare model parameters side side, add one additional call spread() tidyr package.","code":"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` ## ## 1 alpha 0.0398 NA NA ## 2 gamma 0.000101 NA NA ## 3 l 321. NA NA ## 4 s0 0.503 NA NA ## 5 s1 1.10 NA NA ## 6 s10 0.643 NA NA ## 7 s2 0.375 NA NA ## 8 s3 1.12 NA NA ## 9 s4 0.630 NA NA ## 10 s5 2.06 NA NA ## # ℹ 118 more rows ## # ℹ 6 more variables: `Endurance Road` , `Fat Bike` , ## # `Over Mountain` , Sport , Trail , Triathalon "},{"path":"https://business-science.github.io/sweep/articles/SW01_Forecasting_Time_Series_Groups.html","id":"sw_glance","dir":"Articles","previous_headings":"Performing Forecasts on Groups > Step 2: Modeling a time series","what":"sw_glance","title":"Forecasting Time Series Groups in the tidyverse","text":"can view model accuracies also mapping sw_glance within mutate map combo.","code":"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 ## ## 1 Cross Country Race ETS(M,N,M) 1.06 -464. 957. ## 2 Cyclocross ETS(M,N,M) 1.12 -409. 848. ## 3 Elite Road ETS(M,N,M) 0.895 -471. 972. ## 4 Endurance Road ETS(M,N,M) 0.759 -439. 909. ## 5 Fat Bike ETS(M,N,M) 2.73 -343. 715. ## 6 Over Mountain ETS(M,N,M) 0.910 -423. 877. ## 7 Sport ETS(M,N,M) 0.872 -427. 884. ## 8 Trail ETS(M,A,M) 0.741 -411. 855. ## 9 Triathalon ETS(M,N,M) 1.52 -410. 850. ## # ℹ 8 more variables: BIC , ME , RMSE , MAE , MPE , ## # MAPE , MASE , ACF1 "},{"path":"https://business-science.github.io/sweep/articles/SW01_Forecasting_Time_Series_Groups.html","id":"sw_augment","dir":"Articles","previous_headings":"Performing Forecasts on Groups > Step 2: Modeling a time series","what":"sw_augment","title":"Forecasting Time Series Groups in the tidyverse","text":"augmented fitted residual values can achieved much manner. returns nine groups data. Note pass timetk_idx = TRUE return date format times opposed regular (yearmon numeric) time series. can plot residuals nine categories like . Unfortunately see high residuals (especially “Fat Bike”). often case realworld data.","code":"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 ## ## 1 Cross Country Race 2011-01-01 122 373. ## 2 Cross Country Race 2011-02-01 489 201. ## 3 Cross Country Race 2011-03-01 505 465. ## 4 Cross Country Race 2011-04-01 343 161. ## 5 Cross Country Race 2011-05-01 263 567. ## 6 Cross Country Race 2011-06-01 735 296. ## 7 Cross Country Race 2011-07-01 183 741. ## 8 Cross Country Race 2011-08-01 66 220. ## 9 Cross Country Race 2011-09-01 97 381. ## 10 Cross Country Race 2011-10-01 189 123. ## # ℹ 528 more rows ## # ℹ 1 more variable: .resid 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'"},{"path":"https://business-science.github.io/sweep/articles/SW01_Forecasting_Time_Series_Groups.html","id":"sw_tidy_decomp","dir":"Articles","previous_headings":"Performing Forecasts on Groups > Step 2: Modeling a time series","what":"sw_tidy_decomp","title":"Forecasting Time Series Groups in the tidyverse","text":"can create decompositions using procedure sw_tidy_decomp() mutate map combo.","code":"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 ## ## 1 Cross Country Race 2011-01-01 122 313. 1.16 ## 2 Cross Country Race 2011-02-01 489 331. 0.643 ## 3 Cross Country Race 2011-03-01 505 332. 1.41 ## 4 Cross Country Race 2011-04-01 343 347. 0.487 ## 5 Cross Country Race 2011-05-01 263 339. 1.64 ## 6 Cross Country Race 2011-06-01 735 359. 0.873 ## 7 Cross Country Race 2011-07-01 183 348. 2.06 ## 8 Cross Country Race 2011-08-01 66 339. 0.630 ## 9 Cross Country Race 2011-09-01 97 329. 1.12 ## 10 Cross Country Race 2011-10-01 189 336. 0.375 ## # ℹ 528 more rows ## # ℹ 1 more variable: slope "},{"path":"https://business-science.github.io/sweep/articles/SW01_Forecasting_Time_Series_Groups.html","id":"step-3-forecasting-the-model","dir":"Articles","previous_headings":"Performing Forecasts on Groups","what":"Step 3: Forecasting the model","title":"Forecasting Time Series Groups in the tidyverse","text":"can also forecast multiple models using similar approach forecast function. want 12 month forecast add argument h = 12 (refer ?forecast parameters can add, ’s quite ).","code":"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 ## ## 1 Cross Country Race ## 2 Cyclocross ## 3 Elite Road ## 4 Endurance Road ## 5 Fat Bike ## 6 Over Mountain ## 7 Sport ## 8 Trail ## 9 Triathalon "},{"path":"https://business-science.github.io/sweep/articles/SW01_Forecasting_Time_Series_Groups.html","id":"step-4-tidy-the-forecast","dir":"Articles","previous_headings":"Performing Forecasts on Groups","what":"Step 4: Tidy the forecast","title":"Forecasting Time Series Groups in the tidyverse","text":"Next, can apply sw_sweep get forecast nice “tidy” data frame. use argument fitted = FALSE remove fitted values forecast (leave fitted values desired). set timetk_idx = TRUE use dates instead numeric values index. ’ll use unnest() drop left list-columns return unnested data frame. Visualization just one final step.","code":"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 ## ## 1 Cross Country Race 2011-01-01 actu… ## 2 Cross Country Race 2011-02-01 actu… ## 3 Cross Country Race 2011-03-01 actu… ## 4 Cross Country Race 2011-04-01 actu… ## 5 Cross Country Race 2011-05-01 actu… ## 6 Cross Country Race 2011-06-01 actu… ## 7 Cross Country Race 2011-07-01 actu… ## 8 Cross Country Race 2011-08-01 actu… ## 9 Cross Country Race 2011-09-01 actu… ## 10 Cross Country Race 2011-10-01 actu… ## # ℹ 636 more rows ## # ℹ 5 more variables: total.qty , lo.80 , lo.95 , hi.80 , ## # hi.95 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))"},{"path":"https://business-science.github.io/sweep/articles/SW01_Forecasting_Time_Series_Groups.html","id":"recap","dir":"Articles","previous_headings":"","what":"Recap","title":"Forecasting Time Series Groups in the tidyverse","text":"sweep package several tools analyze grouped time series. next vignette review apply multiple models time series.","code":""},{"path":"https://business-science.github.io/sweep/articles/SW02_Forecasting_Multiple_Models.html","id":"prerequisites","dir":"Articles","previous_headings":"","what":"Prerequisites","title":"Forecasting Using Multiple Models","text":"get started, load following packages.","code":"library(tidyr) library(dplyr) library(purrr) library(lubridate) library(ggplot2) library(tidyquant) library(timetk) library(sweep) library(forecast)"},{"path":"https://business-science.github.io/sweep/articles/SW02_Forecasting_Multiple_Models.html","id":"forecasting-gasoline-prices","dir":"Articles","previous_headings":"","what":"Forecasting Gasoline Prices","title":"Forecasting Using Multiple Models","text":"start, let’s get data FRED data base using tidyquant. ’ll use tq_get() retrieve Gasoline Prices 1990 today (2024-01-04). Upon brief inspection, data contains 2 NA values need dealt . can use fill() tidyr package help deal data. first fill fill use previous post days prices fill missing data. can now visualize data. Monthly periodicity might bit granular model fitting. can easily switch periodicity quarterly using tq_transmute() tidyquant package along periodicity aggregation function .period xts package. ’ll convert date yearqtr class regularized. Another quick visualization show reduction granularity.","code":"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 ## ## 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 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 gas_prices_monthly <- gas_prices_monthly_raw %>% fill(price, .direction = \"down\") %>% fill(price, .direction = \"up\") 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() gas_prices_quarterly <- gas_prices_monthly %>% tq_transmute(mutate_fun = to.period, period = \"quarters\") gas_prices_quarterly ## # A tibble: 106 × 2 ## date price ## ## 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 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()"},{"path":"https://business-science.github.io/sweep/articles/SW02_Forecasting_Multiple_Models.html","id":"performing-forecasts-using-multiple-models","dir":"Articles","previous_headings":"","what":"Performing Forecasts Using Multiple Models","title":"Forecasting Using Multiple Models","text":"section use three models forecast gasoline prices: ARIMA ETS BATS","code":""},{"path":"https://business-science.github.io/sweep/articles/SW02_Forecasting_Multiple_Models.html","id":"multiple-models-concept","dir":"Articles","previous_headings":"Performing Forecasts Using Multiple Models","what":"Multiple Models Concept","title":"Forecasting Using Multiple Models","text":"jump modeling, let’s take look multiple model process R Data Science, Chapter 25 Many Models. first create data frame named list. example two columns: “f” functions text, “params” nested list parameters pass respective function column “f”. can also view contents df$params column understand underlying structure. Notice three primary levels secondary levels containing name-value pairs parameters. format important. Next apply functions parameters using special function, invoke_map(). parameter lists “params” column passed function “f” column. output nested list-column named “”. , ’s contents “”, result mapping list functions list parameters. Pretty powerful! Take minute understand conceptual process invoke_map function specifically parameter setup. comfortable, can move model implementation.","code":"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 ## ## 1 runif ## 2 rpois ## 3 rnorm 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 # 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 ## ## 1 runif ## 2 rpois ## 3 rnorm df_out$out ## [[1]] ## [1] 0.54818551 0.31200612 0.55621273 0.32530683 0.76215766 0.30280104 ## [7] 0.27580616 0.04623577 0.68474766 0.03887453 ## ## [[2]] ## [1] 6 7 6 5 12 ## ## [[3]] ## [1] 18.4421424 4.3480539 -7.3581514 0.6666766 21.8707091 -1.7164745 ## [7] -11.9968083 -21.6309492 23.5678024 -11.5255936"},{"path":"https://business-science.github.io/sweep/articles/SW02_Forecasting_Multiple_Models.html","id":"multiple-model-implementation","dir":"Articles","previous_headings":"Performing Forecasts Using Multiple Models","what":"Multiple Model Implementation","title":"Forecasting Using Multiple Models","text":"’ll need take following steps actual forecast model implementation: Coerce data time series Build model list using nested lists Create model data frame Invoke function map easier sounds. Let’s start coercing univariate time series tk_ts(). Next, create nested list using function names first-level keys (important ’ll see next step). Pass model parameters name-value pairs second level. Now, convert data frame using function, enframe() turns lists tibbles. Set arguments name = \"f\" value = \"params\". get bonus: model names now conveniently located column “f”. ready invoke map. Combine mutate() invoke_map() follows. Bada bing, bada boom, now models fitted using parameters defined previously.","code":"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 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 ) ) models_tbl <- tibble::enframe(models_list, name = \"f\", value = \"params\") models_tbl ## # A tibble: 3 × 2 ## f params ## ## 1 auto.arima ## 2 ets ## 3 bats models_tbl_fit <- models_tbl %>% mutate(fit = purrr::invoke_map(f, params)) models_tbl_fit ## # A tibble: 3 × 3 ## f params fit ## ## 1 auto.arima ## 2 ets ## 3 bats "},{"path":"https://business-science.github.io/sweep/articles/SW02_Forecasting_Multiple_Models.html","id":"inspecting-the-model-fit","dir":"Articles","previous_headings":"","what":"Inspecting the Model Fit","title":"Forecasting Using Multiple Models","text":"’s good point review understand model output. can review model parameters, accuracy measurements, residuals using sw_tidy(), sw_glance(), sw_augment().","code":""},{"path":"https://business-science.github.io/sweep/articles/SW02_Forecasting_Multiple_Models.html","id":"sw_tidy","dir":"Articles","previous_headings":"Inspecting the Model Fit","what":"sw_tidy","title":"Forecasting Using Multiple Models","text":"tidying function returns model parameters estimates. use combination mutate map iteratively apply sw_tidy() function new column named “tidy”. unnest spread review terms model function.","code":"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 ## ## 1 ar1 0.834 NA NA ## 2 ma1 -0.964 NA NA ## 3 sar1 0.939 NA NA ## 4 sma1 -0.776 NA NA ## 5 alpha NA 0.588 NA ## 6 ar.coefficients NA NA NA ## 7 beta NA NA NA ## 8 damping.parameter NA NA NA ## 9 gamma.values NA -0.0262 NA ## 10 lambda NA 0.0000605 NA ## 11 ma.coefficients NA 0.256 NA ## 12 alpha NA NA 0.831 ## 13 b NA NA -0.0524 ## 14 beta NA NA 0.000100 ## 15 gamma NA NA 0.0521 ## 16 l NA NA 1.29 ## 17 phi NA NA 0.837 ## 18 s0 NA NA 0.0469 ## 19 s1 NA NA -0.0209 ## 20 s2 NA NA -0.0407"},{"path":"https://business-science.github.io/sweep/articles/SW02_Forecasting_Multiple_Models.html","id":"sw_glance","dir":"Articles","previous_headings":"Inspecting the Model Fit","what":"sw_glance","title":"Forecasting Using Multiple Models","text":"Glance one powerful tools yields model accuracies enabling direct comparisons fit model. use process used tidy, except theres need spread perform comparison. can see ARIMA model lowest AIC far.","code":"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 ## ## 1 auto… ARIMA(1,1… 0.298 -20.6 51.2 64.4 0.0180 0.291 ## 2 ets ETS(M,Ad,… 0.118 -76.6 173. 200. 0.0149 0.292 ## 3 bats BATS(0, {… 0.116 159. 179. 184. 0.0193 0.259 ## # ℹ 5 more variables: MAE , MPE , MAPE , MASE , ACF1 "},{"path":"https://business-science.github.io/sweep/articles/SW02_Forecasting_Multiple_Models.html","id":"sw_augment","dir":"Articles","previous_headings":"Inspecting the Model Fit","what":"sw_augment","title":"Forecasting Using Multiple Models","text":"can augment models get residuals following procedure. can pipe (%>%) results right ggplot() plotting. Notice ARIMA model largest residuals especially model index increases whereas bats model relatively low residuals.","code":"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'"},{"path":"https://business-science.github.io/sweep/articles/SW02_Forecasting_Multiple_Models.html","id":"forecasting-the-model","dir":"Articles","previous_headings":"","what":"Forecasting the model","title":"Forecasting Using Multiple Models","text":"Creating forecast models accomplished mapping forecast function. next six quarters forecasted withe argument h = 6.","code":"models_tbl_fcast <- models_tbl_fit %>% mutate(fcast = map(fit, forecast, h = 6)) models_tbl_fcast ## # A tibble: 3 × 4 ## f params fit fcast ## ## 1 auto.arima ## 2 ets ## 3 bats "},{"path":"https://business-science.github.io/sweep/articles/SW02_Forecasting_Multiple_Models.html","id":"tidying-the-forecast","dir":"Articles","previous_headings":"","what":"Tidying the forecast","title":"Forecasting Using Multiple Models","text":"Next, map sw_sweep, coerces forecast “tidy” tibble format. set fitted = FALSE remove model fitted values output. set timetk_idx = TRUE use dates instead numeric values index. can unnest “sweep” column get results three models. Finally, can plot forecasts unnesting “sweep” column piping ggplot().","code":"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 ## ## 1 auto.arima ## 2 ets ## 3 bats models_tbl_fcast_tidy %>% unnest(sweep) ## # A tibble: 336 × 11 ## f params fit fcast date key price lo.80 lo.95 ## ## 1 auto.a… 1990-09-01 actu… 1.26 NA NA ## 2 auto.a… 1990-12-01 actu… 1.32 NA NA ## 3 auto.a… 1991-03-01 actu… 1.04 NA NA ## 4 auto.a… 1991-06-01 actu… 1.13 NA NA ## 5 auto.a… 1991-09-01 actu… 1.11 NA NA ## 6 auto.a… 1991-12-01 actu… 1.08 NA NA ## 7 auto.a… 1992-03-01 actu… 1.01 NA NA ## 8 auto.a… 1992-06-01 actu… 1.14 NA NA ## 9 auto.a… 1992-09-01 actu… 1.12 NA NA ## 10 auto.a… 1992-12-01 actu… 1.08 NA NA ## # ℹ 326 more rows ## # ℹ 2 more variables: hi.80 , hi.95 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()"},{"path":"https://business-science.github.io/sweep/articles/SW02_Forecasting_Multiple_Models.html","id":"recap","dir":"Articles","previous_headings":"","what":"Recap","title":"Forecasting Using Multiple Models","text":"sweep package can aid analysis multiple forecast models. next vignette review time series object coercion sweep.","code":""},{"path":"https://business-science.github.io/sweep/authors.html","id":null,"dir":"","previous_headings":"","what":"Authors","title":"Authors and Citation","text":"Matt Dancho. Author, maintainer. Davis Vaughan. Author.","code":""},{"path":"https://business-science.github.io/sweep/authors.html","id":"citation","dir":"","previous_headings":"","what":"Citation","title":"Authors and Citation","text":"Dancho M, Vaughan D (2024). sweep: Tidy Tools Forecasting. R package version 0.2.5.9000, https://github.com/business-science/sweep, https://business-science.github.io/sweep/.","code":"@Manual{, title = {sweep: Tidy Tools for Forecasting}, author = {Matt Dancho and Davis Vaughan}, year = {2024}, note = {R package version 0.2.5.9000, https://github.com/business-science/sweep}, url = {https://business-science.github.io/sweep/}, }"},{"path":"https://business-science.github.io/sweep/index.html","id":"sweep-","dir":"","previous_headings":"","what":"Tidy Tools for Forecasting","title":"Tidy Tools for Forecasting","text":"Extending broom time series forecasting sweep package extends broom tools (tidy, glance, augment) performing forecasts time series analysis “tidyverse”. package geared towards “tidying” forecast workflow used Rob Hyndman’s forecast package.","code":""},{"path":"https://business-science.github.io/sweep/index.html","id":"benefits","dir":"","previous_headings":"","what":"Benefits","title":"Tidy Tools for Forecasting","text":"Designed modeling scaling forecasts using tidyverse tools R Data Science Extends broom model analysis (ARIMA, ETS, BATS, etc) Tidies forecast objects easy plotting “tidy” data manipulation Integrates timetk enable dates datetimes (irregular time series) tidied forecast output","code":""},{"path":"https://business-science.github.io/sweep/index.html","id":"tools","dir":"","previous_headings":"","what":"Tools","title":"Tidy Tools for Forecasting","text":"package contains following elements: model tidiers: sw_tidy, sw_glance, sw_augment, sw_tidy_decomp functions extend tidy, glance, augment broom package specifically models (ets(), Arima(), bats(), etc) used forecasting. forecast tidier: sw_sweep converts forecast object tibble can easily manipulated “tidyverse”.","code":""},{"path":"https://business-science.github.io/sweep/index.html","id":"making-forecasts-in-the-tidyverse","dir":"","previous_headings":"","what":"Making forecasts in the tidyverse","title":"Tidy Tools for Forecasting","text":"sweep enables converting forecast object tibble. result ability use dplyr, tidyr, ggplot natively manipulate, analyze visualize forecasts.","code":""},{"path":"https://business-science.github.io/sweep/index.html","id":"forecasting-multiple-time-series-groups-at-scale","dir":"","previous_headings":"","what":"Forecasting multiple time series groups at scale","title":"Tidy Tools for Forecasting","text":"Often forecasts required grouped data analyse trends sub-categories. good news scaling one time series many easy various sw_ functions combination dplyr purrr.","code":""},{"path":"https://business-science.github.io/sweep/index.html","id":"forecasting-multiple-models-for-accuracy","dir":"","previous_headings":"","what":"Forecasting multiple models for accuracy","title":"Tidy Tools for Forecasting","text":"common goal forecasting compare different forecast models . sweep helps area well.","code":""},{"path":"https://business-science.github.io/sweep/index.html","id":"broom-extensions-for-forecasting","dir":"","previous_headings":"","what":"broom extensions for forecasting","title":"Tidy Tools for Forecasting","text":"familiar broom, know useful retrieving “tidy” format model components. sweep extends benefit forecast package workflow 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. compatibility chart listed . Function Compatibility","code":""},{"path":"https://business-science.github.io/sweep/index.html","id":"installation","dir":"","previous_headings":"","what":"Installation","title":"Tidy Tools for Forecasting","text":"’s get started. Development version latest features:","code":"# install.packages(\"remotes\") remotes::install_github(\"business-science/sweep\")"},{"path":"https://business-science.github.io/sweep/index.html","id":"further-information","dir":"","previous_headings":"","what":"Further Information","title":"Tidy Tools for Forecasting","text":"sweep package includes several vignettes help users get speed quickly: SW00 - Introduction sweep SW01 - Forecasting Time Series Groups tidyverse SW02 - Forecasting Using Multiple Models","code":""},{"path":"https://business-science.github.io/sweep/reference/add_index.html","id":null,"dir":"Reference","previous_headings":"","what":"Adds a sequential index column to a data frame — add_index","title":"Adds a sequential index column to a data frame — add_index","text":"Adds sequential index column data frame","code":""},{"path":"https://business-science.github.io/sweep/reference/add_index.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Adds a sequential index column to a data frame — add_index","text":"","code":"add_index(ret, rename_index)"},{"path":"https://business-science.github.io/sweep/reference/add_index.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Adds a sequential index column to a data frame — add_index","text":"ret object class tibble rename_index variable indicating index name used tibble returned","code":""},{"path":"https://business-science.github.io/sweep/reference/arima_string.html","id":null,"dir":"Reference","previous_headings":"","what":"Print the ARIMA model parameters — arima_string","title":"Print the ARIMA model parameters — arima_string","text":"Refer forecast:::arima.string. forecast arima.R","code":""},{"path":"https://business-science.github.io/sweep/reference/arima_string.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Print the ARIMA model parameters — arima_string","text":"","code":"arima_string(object, padding = FALSE)"},{"path":"https://business-science.github.io/sweep/reference/arima_string.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Print the ARIMA model parameters — arima_string","text":"object object class Arima padding Add padding name returned","code":""},{"path":"https://business-science.github.io/sweep/reference/bats_string.html","id":null,"dir":"Reference","previous_headings":"","what":"Print the BATS model parameters — bats_string","title":"Print the BATS model parameters — bats_string","text":"Refer forecast:::makeText. forecast bats.R","code":""},{"path":"https://business-science.github.io/sweep/reference/bats_string.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Print the BATS model parameters — bats_string","text":"","code":"bats_string(object)"},{"path":"https://business-science.github.io/sweep/reference/bats_string.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Print the BATS model parameters — bats_string","text":"object object class bats","code":""},{"path":"https://business-science.github.io/sweep/reference/bike_sales.html","id":null,"dir":"Reference","previous_headings":"","what":"Fictional sales data for bike shops purchasing Cannondale bikes — bike_sales","title":"Fictional sales data for bike shops purchasing Cannondale bikes — bike_sales","text":"dataset containing fictional bicycle orders spanning 2011 2015. Hypothetically, bike_sales data similar sales data mainatained business' sales data base. unit price model names come data provided model bicycle manufacturer, Cannondale (2016). customers (bicycle shops) including name, location, etc orders including quantity purchased order dates fictional. data intended implementing business analytics techniques (e.g. forecast, clustering, etc) identify underlying trends.","code":""},{"path":"https://business-science.github.io/sweep/reference/bike_sales.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Fictional sales data for bike shops purchasing Cannondale bikes — bike_sales","text":"","code":"bike_sales"},{"path":"https://business-science.github.io/sweep/reference/bike_sales.html","id":"format","dir":"Reference","previous_headings":"","what":"Format","title":"Fictional sales data for bike shops purchasing Cannondale bikes — bike_sales","text":"data frame 15644 rows 17 variables: order.date Date order placed order.id unique order identification number order.line sequential identification number products order quantity Number units purchased price unit price bicycle price.ext extended price = price x quantity customer.id unique customer identification number bikeshop.name customer name bikeshop.city city bike shop located bikeshop.state state bike shop located latitude geograhpic latitude customer location longitude geograhpic longitude customer location product.id unique product identification number model model name bicycle category.primary main bicycle category, either \"Mountain\" \"Road\" category.secondary One nine specific bicycle categories frame bicycle frame material, either \"Carbon\" \"Aluminum\"","code":""},{"path":"https://business-science.github.io/sweep/reference/bike_sales.html","id":"source","dir":"Reference","previous_headings":"","what":"Source","title":"Fictional sales data for bike shops purchasing Cannondale bikes — bike_sales","text":"2016 bicycle model names prices originated https://www.cannondale.com/en-us","code":""},{"path":"https://business-science.github.io/sweep/reference/reexports.html","id":null,"dir":"Reference","previous_headings":"","what":"Objects exported from other packages — reexports","title":"Objects exported from other packages — reexports","text":"objects imported packages. Follow links see documentation. dplyr %>%","code":""},{"path":"https://business-science.github.io/sweep/reference/sw_augment.default.html","id":null,"dir":"Reference","previous_headings":"","what":"Default augment method — sw_augment.default","title":"Default augment method — sw_augment.default","text":"default, sw_augment() uses broom::augment() convert output.","code":""},{"path":"https://business-science.github.io/sweep/reference/sw_augment.default.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Default augment method — sw_augment.default","text":"","code":"# S3 method for default sw_augment(x, ...)"},{"path":"https://business-science.github.io/sweep/reference/sw_augment.default.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Default augment method — sw_augment.default","text":"x object tidied ... extra arguments passed broom::augment()","code":""},{"path":"https://business-science.github.io/sweep/reference/sw_augment.default.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Default augment method — sw_augment.default","text":"tibble generated broom::augment()","code":""},{"path":"https://business-science.github.io/sweep/reference/sw_augment.html","id":null,"dir":"Reference","previous_headings":"","what":"Augment data according to a tidied model — sw_augment","title":"Augment data according to a tidied model — sw_augment","text":"Given R statistical model non-tidy object, add columns original dataset predictions, residuals cluster assignments.","code":""},{"path":"https://business-science.github.io/sweep/reference/sw_augment.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Augment data according to a tidied model — sw_augment","text":"","code":"sw_augment(x, ...)"},{"path":"https://business-science.github.io/sweep/reference/sw_augment.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Augment data according to a tidied model — sw_augment","text":"x model R object convert data frame ... arguments passed methods","code":""},{"path":"https://business-science.github.io/sweep/reference/sw_augment.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Augment data according to a tidied model — sw_augment","text":"sw_augment() wrapper broom::augment(). benefit sw_augment methods various time-series model classes HoltWinters, ets, Arima, etc. non-time series, sw_augment() defaults broom::augment(). difference return tibble. Note convention first argument almost always data, specifies original data object. part S3 signature, partly prevents rowwise_df_tidiers taking column name first argument.","code":""},{"path":[]},{"path":"https://business-science.github.io/sweep/reference/sw_augment_columns.html","id":null,"dir":"Reference","previous_headings":"","what":"Augments data — sw_augment_columns","title":"Augments data — sw_augment_columns","text":"Augments data","code":""},{"path":"https://business-science.github.io/sweep/reference/sw_augment_columns.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Augments data — sw_augment_columns","text":"","code":"sw_augment_columns(ret, data, rename_index, timetk_idx = FALSE)"},{"path":"https://business-science.github.io/sweep/reference/sw_augment_columns.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Augments data — sw_augment_columns","text":"ret object class tibble data time series data augmented rename_index variable indicating index name used tibble returned timetk_idx Uses timetk index (irregular time index) present.","code":""},{"path":"https://business-science.github.io/sweep/reference/sw_glance.default.html","id":null,"dir":"Reference","previous_headings":"","what":"Default glance method — sw_glance.default","title":"Default glance method — sw_glance.default","text":"default, sw_glance() uses broom::glance() convert output.","code":""},{"path":"https://business-science.github.io/sweep/reference/sw_glance.default.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Default glance method — sw_glance.default","text":"","code":"# S3 method for default sw_glance(x, ...)"},{"path":"https://business-science.github.io/sweep/reference/sw_glance.default.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Default glance method — sw_glance.default","text":"x object tidied ... extra arguments passed broom::glance()","code":""},{"path":"https://business-science.github.io/sweep/reference/sw_glance.default.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Default glance method — sw_glance.default","text":"tibble generated broom::glance()","code":""},{"path":"https://business-science.github.io/sweep/reference/sw_glance.html","id":null,"dir":"Reference","previous_headings":"","what":"Construct a single row summary ","title":"Construct a single row summary ","text":"Construct single row summary \"glance\" model, fit, object","code":""},{"path":"https://business-science.github.io/sweep/reference/sw_glance.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Construct a single row summary ","text":"","code":"sw_glance(x, ...)"},{"path":"https://business-science.github.io/sweep/reference/sw_glance.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Construct a single row summary ","text":"x model R object convert single-row data frame ... arguments passed methods","code":""},{"path":"https://business-science.github.io/sweep/reference/sw_glance.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Construct a single row summary ","text":"single-row tibble model summary information.","code":""},{"path":"https://business-science.github.io/sweep/reference/sw_glance.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Construct a single row summary ","text":"sw_glance() wrapper broom::glance(). benefit sw_glance methods various time-series model classes HoltWinters, ets, Arima, etc. sw_glance methods always return either one-row tibble NULL. single row includes summary statistics relevent model accuracy, can used assess model fit quality. non-time series, sw_glance() defaults broom::glance(). difference return tibble.","code":""},{"path":[]},{"path":"https://business-science.github.io/sweep/reference/sw_sweep.html","id":null,"dir":"Reference","previous_headings":"","what":"Tidy forecast objects — sw_sweep","title":"Tidy forecast objects — sw_sweep","text":"Tidy forecast objects","code":""},{"path":"https://business-science.github.io/sweep/reference/sw_sweep.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Tidy forecast objects — sw_sweep","text":"","code":"sw_sweep(x, fitted = FALSE, timetk_idx = FALSE, rename_index = \"index\", ...)"},{"path":"https://business-science.github.io/sweep/reference/sw_sweep.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Tidy forecast objects — sw_sweep","text":"x time-series forecast class forecast. fitted Whether return fitted values (model values) results. FALSE default. timetk_idx timetk index (non-regularized index) present, uses develop forecast. Otherwise uses default index. rename_index Enables index column renamed. ... Additional arguments passed tk_make_future_timeseries()","code":""},{"path":"https://business-science.github.io/sweep/reference/sw_sweep.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Tidy forecast objects — sw_sweep","text":"Returns tibble object.","code":""},{"path":"https://business-science.github.io/sweep/reference/sw_sweep.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Tidy forecast objects — sw_sweep","text":"sw_sweep designed coerce forecast objects forecast package tibble objects \"tidy\" format (long). returned object contains actual values forecasted values including point forecast upper lower confidence intervals. timetk_idx argument used modify return format index. timetk_idx = FALSE, regularized time index always constructed. may format numeric values (e.g. 2010.000) higher order yearmon yearqtr classes zoo package. higher order class attempted returned. timetk_idx = TRUE timetk index present, irregular time index returned combines original time series (.e. date datetime) along computed future time series created using tk_make_future_timeseries() timetk package. ... can used pass additional arguments tk_make_future_timeseries() inspect_weekdays, skip_values, etc can useful tuning future time series sequence. index column name can changed using rename_index argument.","code":""},{"path":[]},{"path":"https://business-science.github.io/sweep/reference/sw_sweep.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Tidy forecast objects — sw_sweep","text":"","code":"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 #> #> 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"},{"path":"https://business-science.github.io/sweep/reference/sw_tidy.default.html","id":null,"dir":"Reference","previous_headings":"","what":"Default tidying method — sw_tidy.default","title":"Default tidying method — sw_tidy.default","text":"default, sw_tidy() uses broom::tidy() convert output.","code":""},{"path":"https://business-science.github.io/sweep/reference/sw_tidy.default.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Default tidying method — sw_tidy.default","text":"","code":"# S3 method for default sw_tidy(x, ...)"},{"path":"https://business-science.github.io/sweep/reference/sw_tidy.default.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Default tidying method — sw_tidy.default","text":"x object tidied ... extra arguments passed broom::tidy()","code":""},{"path":"https://business-science.github.io/sweep/reference/sw_tidy.default.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Default tidying method — sw_tidy.default","text":"tibble generated broom::tidy()","code":""},{"path":"https://business-science.github.io/sweep/reference/sw_tidy.html","id":null,"dir":"Reference","previous_headings":"","what":"Tidy the result of a time-series model into a summary tibble — sw_tidy","title":"Tidy the result of a time-series model into a summary tibble — sw_tidy","text":"Tidy result time-series model summary tibble","code":""},{"path":"https://business-science.github.io/sweep/reference/sw_tidy.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Tidy the result of a time-series model into a summary tibble — sw_tidy","text":"","code":"sw_tidy(x, ...)"},{"path":"https://business-science.github.io/sweep/reference/sw_tidy.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Tidy the result of a time-series model into a summary tibble — sw_tidy","text":"x object converted tibble (\"tidy\" data.frame) ... extra arguments","code":""},{"path":"https://business-science.github.io/sweep/reference/sw_tidy.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Tidy the result of a time-series model into a summary tibble — sw_tidy","text":"tibble","code":""},{"path":"https://business-science.github.io/sweep/reference/sw_tidy.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Tidy the result of a time-series model into a summary tibble — sw_tidy","text":"sw_tidy() wrapper broom::tidy(). main benefit sw_tidy() methods various time-series model classes HoltWinters, ets, Arima, etc. sw_tidy() methods always returns \"tidy\" tibble model coefficient / parameters. non-time series, sw_tidy() defaults broom::tidy(). difference return tibble. output sw_tidy() always tibble disposable row names. therefore suited manipulation packages like dplyr ggplot2.","code":""},{"path":[]},{"path":"https://business-science.github.io/sweep/reference/sw_tidy.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Tidy the result of a time-series model into a summary tibble — sw_tidy","text":"","code":"library(dplyr) library(forecast) WWWusage %>% auto.arima() %>% sw_tidy(conf.int = TRUE) #> # A tibble: 2 × 2 #> term estimate #> #> 1 ar1 0.650 #> 2 ma1 0.526"},{"path":"https://business-science.github.io/sweep/reference/sw_tidy_decomp.html","id":null,"dir":"Reference","previous_headings":"","what":"Coerces decomposed time-series objects to tibble format. — sw_tidy_decomp","title":"Coerces decomposed time-series objects to tibble format. — sw_tidy_decomp","text":"Coerces decomposed time-series objects tibble format.","code":""},{"path":"https://business-science.github.io/sweep/reference/sw_tidy_decomp.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Coerces decomposed time-series objects to tibble format. — sw_tidy_decomp","text":"","code":"sw_tidy_decomp(x, timetk_idx = FALSE, rename_index = \"index\", ...)"},{"path":"https://business-science.github.io/sweep/reference/sw_tidy_decomp.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Coerces decomposed time-series objects to tibble format. — sw_tidy_decomp","text":"x time-series object class stl, ets, decomposed.ts, HoltWinters, bats tbats. timetk_idx TRUE, uses timetk index (irregular, typically date datetime) present. rename_index Enables index column renamed. ... used.","code":""},{"path":"https://business-science.github.io/sweep/reference/sw_tidy_decomp.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Coerces decomposed time-series objects to tibble format. — sw_tidy_decomp","text":"Returns tibble object.","code":""},{"path":"https://business-science.github.io/sweep/reference/sw_tidy_decomp.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Coerces decomposed time-series objects to tibble format. — sw_tidy_decomp","text":"sw_tidy_decomp designed coerce time-series objects decompositions tibble objects. regularized time index always constructed. time index detected, sequential index returned default. index column name can changed using rename_index argument.","code":""},{"path":"https://business-science.github.io/sweep/reference/sw_tidy_decomp.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Coerces decomposed time-series objects to tibble format. — sw_tidy_decomp","text":"","code":"library(dplyr) library(forecast) library(sweep) # Decompose ETS model USAccDeaths %>% ets() %>% sw_tidy_decomp() #> # A tibble: 73 × 4 #> index observed level season #> #> 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 #> #> 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"},{"path":"https://business-science.github.io/sweep/reference/sweep-package.html","id":null,"dir":"Reference","previous_headings":"","what":"sweep: Tidy Tools for Forecasting — sweep-package","title":"sweep: Tidy Tools for Forecasting — sweep-package","text":"sweep package \"tidies\" modeling workflow forecast package.","code":""},{"path":"https://business-science.github.io/sweep/reference/sweep-package.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"sweep: Tidy Tools for Forecasting — sweep-package","text":"model forecast objects covered broom package. includes sw_tidy(), sw_glance(), sw_augment() functions work similar capacity broom functions. addition, provides sw_tidy_decomp() tidy decomposition, sw_sweep() coerce forecast objects \"tibbles\" easy visualization ggplot2 manipulation dplyr. learn sweep, start vignettes: browseVignettes(package = \"sweep\")","code":""},{"path":[]},{"path":"https://business-science.github.io/sweep/reference/sweep-package.html","id":"author","dir":"Reference","previous_headings":"","what":"Author","title":"sweep: Tidy Tools for Forecasting — sweep-package","text":"Maintainer: Matt Dancho mdancho@business-science.io Authors: Davis Vaughan dvaughan@business-science.io","code":""},{"path":"https://business-science.github.io/sweep/reference/tbats_string.html","id":null,"dir":"Reference","previous_headings":"","what":"Print the TBATS model parameters — tbats_string","title":"Print the TBATS model parameters — tbats_string","text":"Refer forecast:::makeTextTBATS. forecast bats.R","code":""},{"path":"https://business-science.github.io/sweep/reference/tbats_string.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Print the TBATS model parameters — tbats_string","text":"","code":"tbats_string(object)"},{"path":"https://business-science.github.io/sweep/reference/tbats_string.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Print the TBATS model parameters — tbats_string","text":"object object class bats tbats","code":""},{"path":"https://business-science.github.io/sweep/reference/tidiers_HoltWinters.html","id":null,"dir":"Reference","previous_headings":"","what":"Tidying methods for HoltWinters modeling of time series — tidiers_HoltWinters","title":"Tidying methods for HoltWinters modeling of time series — tidiers_HoltWinters","text":"methods tidy HoltWinters models univariate time series.","code":""},{"path":"https://business-science.github.io/sweep/reference/tidiers_HoltWinters.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Tidying methods for HoltWinters modeling of time series — tidiers_HoltWinters","text":"","code":"# 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\", ...)"},{"path":"https://business-science.github.io/sweep/reference/tidiers_HoltWinters.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Tidying methods for HoltWinters modeling of time series — tidiers_HoltWinters","text":"x object class \"HoltWinters\" ... Additional parameters (used) data Used sw_augment . NULL default simply returns augmented columns . User can supply original data, returns data + augmented columns. rename_index Used sw_augment . string representing name index generated. timetk_idx Used sw_augment sw_tidy_decomp. TRUE, uses timetk index (irregular, typically date datetime) present.","code":""},{"path":"https://business-science.github.io/sweep/reference/tidiers_HoltWinters.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Tidying methods for HoltWinters modeling of time series — tidiers_HoltWinters","text":"sw_tidy() returns one row model parameter, two columns: term: various parameters (alpha, beta, gamma, coefficients) estimate: estimated parameter value sw_glance() returns one row following columns: model.desc: description model sigma: square root estimated residual variance logLik: data's log-likelihood model AIC: Akaike Information Criterion BIC: Bayesian Information Criterion (NA bats / tbats) : 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 errors lag 1 sw_augment() returns tibble following time series attributes: index: index either attempted extracted model sequential index created plotting purposes .actual: original time series .fitted: fitted values model .resid: residual values model sw_tidy_decomp() returns tibble following time series attributes: index: index either attempted extracted model sequential index created plotting purposes observed: original time series season: seasonal component trend: trend component remainder: observed - (season + trend) seasadj: observed - season (trend + remainder)","code":""},{"path":[]},{"path":"https://business-science.github.io/sweep/reference/tidiers_HoltWinters.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Tidying methods for HoltWinters modeling of time series — tidiers_HoltWinters","text":"","code":"library(dplyr) library(forecast) fit_hw <- USAccDeaths %>% stats::HoltWinters() sw_tidy(fit_hw) #> # A tibble: 17 × 2 #> term estimate #> #> 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 #> #> 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 #> #> 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 #> #> 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"},{"path":"https://business-science.github.io/sweep/reference/tidiers_StructTS.html","id":null,"dir":"Reference","previous_headings":"","what":"Tidying methods for StructTS (Error, Trend, Seasonal) / exponential smoothing\nmodeling of time series — tidiers_StructTS","title":"Tidying methods for StructTS (Error, Trend, Seasonal) / exponential smoothing\nmodeling of time series — tidiers_StructTS","text":"methods tidy coefficients StructTS models univariate time series.","code":""},{"path":"https://business-science.github.io/sweep/reference/tidiers_StructTS.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Tidying methods for StructTS (Error, Trend, Seasonal) / exponential smoothing\nmodeling of time series — tidiers_StructTS","text":"","code":"# 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\", ...)"},{"path":"https://business-science.github.io/sweep/reference/tidiers_StructTS.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Tidying methods for StructTS (Error, Trend, Seasonal) / exponential smoothing\nmodeling of time series — tidiers_StructTS","text":"x object class \"StructTS\" ... Additional parameters (used) data Used sw_augment . NULL default simply returns augmented columns . User can supply original data, returns data + augmented columns. timetk_idx Used sw_augment . Uses irregular timetk index present. rename_index Used sw_augment . string representing name index generated.","code":""},{"path":"https://business-science.github.io/sweep/reference/tidiers_StructTS.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Tidying methods for StructTS (Error, Trend, Seasonal) / exponential smoothing\nmodeling of time series — tidiers_StructTS","text":"sw_tidy() returns one row model parameter, two columns: term: model parameters estimate: estimated parameter value sw_glance() returns one row columns model.desc: description model including three integer components (p, d, q) AR order, degree differencing, MA order. sigma: square root estimated residual variance logLik: data's log-likelihood model AIC: Akaike Information Criterion BIC: Bayesian Information Criterion : 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 errors lag 1 sw_augment() returns tibble following time series attributes: index: index either attempted extracted model sequential index created plotting purposes .actual: original time series .fitted: fitted values model .resid: residual values model","code":""},{"path":[]},{"path":"https://business-science.github.io/sweep/reference/tidiers_StructTS.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Tidying methods for StructTS (Error, Trend, Seasonal) / exponential smoothing\nmodeling of time series — tidiers_StructTS","text":"","code":"library(dplyr) library(forecast) fit_StructTS <- WWWusage %>% StructTS() sw_tidy(fit_StructTS) #> # A tibble: 3 × 2 #> term estimate #> #> 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 #> #> 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 sw_augment(fit_StructTS) #> # A tibble: 100 × 4 #> index .actual .fitted .resid #> #> 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"},{"path":"https://business-science.github.io/sweep/reference/tidiers_arima.html","id":null,"dir":"Reference","previous_headings":"","what":"Tidying methods for ARIMA modeling of time series — tidiers_arima","title":"Tidying methods for ARIMA modeling of time series — tidiers_arima","text":"methods tidy coefficients ARIMA models univariate time series.","code":""},{"path":"https://business-science.github.io/sweep/reference/tidiers_arima.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Tidying methods for ARIMA modeling of time series — tidiers_arima","text":"","code":"# 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, ...)"},{"path":"https://business-science.github.io/sweep/reference/tidiers_arima.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Tidying methods for ARIMA modeling of time series — tidiers_arima","text":"x object class \"Arima\" ... Additional parameters (used) data Used sw_augment . NULL default simply returns augmented columns . User can supply original data, returns data + augmented columns. rename_index Used sw_augment . string representing name index generated. timetk_idx Used sw_augment . Uses irregular timetk index present.","code":""},{"path":"https://business-science.github.io/sweep/reference/tidiers_arima.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Tidying methods for ARIMA modeling of time series — tidiers_arima","text":"sw_tidy() returns one row coefficient model, five columns: term: term nonlinear model estimated tested estimate: estimated coefficient sw_glance() returns one row columns model.desc: description model including three integer components (p, d, q) AR order, degree differencing, MA order. sigma: square root estimated residual variance logLik: data's log-likelihood model AIC: Akaike Information Criterion BIC: Bayesian Information Criterion : 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 errors lag 1 sw_augment() returns tibble following time series attributes: index: index either attempted extracted model sequential index created plotting purposes .actual: original time series .fitted: fitted values model .resid: residual values model sw_tidy() returns underlying ETS ARIMA model's sw_tidy() one row coefficient model, five columns: term: term nonlinear model estimated tested estimate: estimated coefficient","code":""},{"path":[]},{"path":"https://business-science.github.io/sweep/reference/tidiers_arima.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Tidying methods for ARIMA modeling of time series — tidiers_arima","text":"","code":"library(dplyr) library(forecast) fit_arima <- WWWusage %>% auto.arima() sw_tidy(fit_arima) #> # A tibble: 2 × 2 #> term estimate #> #> 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 #> #> 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 sw_augment(fit_arima) #> # A tibble: 100 × 4 #> index .actual .fitted .resid #> #> 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"},{"path":"https://business-science.github.io/sweep/reference/tidiers_bats.html","id":null,"dir":"Reference","previous_headings":"","what":"Tidying methods for BATS and TBATS modeling of time series — tidiers_bats","title":"Tidying methods for BATS and TBATS modeling of time series — tidiers_bats","text":"Tidying methods BATS TBATS modeling time series","code":""},{"path":"https://business-science.github.io/sweep/reference/tidiers_bats.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Tidying methods for BATS and TBATS modeling of time series — tidiers_bats","text":"","code":"# 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\", ...)"},{"path":"https://business-science.github.io/sweep/reference/tidiers_bats.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Tidying methods for BATS and TBATS modeling of time series — tidiers_bats","text":"x object class \"bats\" \"tbats\" ... Additional parameters (used) data Used sw_augment . NULL default simply returns augmented columns . User can supply original data, returns data + augmented columns. rename_index Used sw_augment . string representing name index generated. timetk_idx Used sw_augment sw_tidy_decomp. TRUE, uses timetk index (irregular, typically date datetime) present.","code":""},{"path":"https://business-science.github.io/sweep/reference/tidiers_bats.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Tidying methods for BATS and TBATS modeling of time series — tidiers_bats","text":"sw_tidy() returns one row model parameter, two columns: term: various parameters (lambda, alpha, gamma, etc) estimate: estimated parameter value sw_glance() returns one row columns model.desc: description model including three integer components (p, d, q) AR order, degree differencing, MA order. sigma: square root estimated residual variance logLik: data's log-likelihood model AIC: Akaike Information Criterion BIC: Bayesian Information Criterion (NA bats / tbats) : 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 errors lag 1 sw_augment() returns tibble following time series attributes: index: index either attempted extracted model sequential index created plotting purposes .actual: original time series .fitted: fitted values model .resid: residual values model sw_tidy_decomp() returns tibble following time series attributes: index: index either attempted extracted model sequential index created plotting purposes observed: original time series level: level component slope: slope component (always present) season: seasonal component (always present)","code":""},{"path":[]},{"path":"https://business-science.github.io/sweep/reference/tidiers_bats.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Tidying methods for BATS and TBATS modeling of time series — tidiers_bats","text":"","code":"library(dplyr) library(forecast) fit_bats <- WWWusage %>% bats() sw_tidy(fit_bats) #> # A tibble: 7 × 2 #> term estimate #> #> 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 #> #> 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 #> #> 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"},{"path":"https://business-science.github.io/sweep/reference/tidiers_decomposed_ts.html","id":null,"dir":"Reference","previous_headings":"","what":"Tidying methods for decomposed time series — tidiers_decomposed_ts","title":"Tidying methods for decomposed time series — tidiers_decomposed_ts","text":"Tidying methods decomposed time series","code":""},{"path":"https://business-science.github.io/sweep/reference/tidiers_decomposed_ts.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Tidying methods for decomposed time series — tidiers_decomposed_ts","text":"","code":"# S3 method for decomposed.ts sw_tidy_decomp(x, timetk_idx = FALSE, rename_index = \"index\", ...)"},{"path":"https://business-science.github.io/sweep/reference/tidiers_decomposed_ts.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Tidying methods for decomposed time series — tidiers_decomposed_ts","text":"x object class \"decomposed.ts\" timetk_idx Used sw_augment sw_tidy_decomp. TRUE, uses timetk index (irregular, typically date datetime) present. rename_index Used sw_augment sw_tidy_decomp. string representing name index generated. ... used.","code":""},{"path":"https://business-science.github.io/sweep/reference/tidiers_decomposed_ts.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Tidying methods for decomposed time series — tidiers_decomposed_ts","text":"sw_tidy_decomp() returns tibble following time series attributes: index: index either attempted extracted model sequential index created plotting purposes season: seasonal component trend: trend component random: error component seasadj: observed - season","code":""},{"path":[]},{"path":"https://business-science.github.io/sweep/reference/tidiers_decomposed_ts.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Tidying methods for decomposed time series — tidiers_decomposed_ts","text":"","code":"library(dplyr) library(forecast) fit_decomposed <- USAccDeaths %>% decompose() sw_tidy_decomp(fit_decomposed) #> # A tibble: 72 × 6 #> index observed season trend random seasadj #> #> 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"},{"path":"https://business-science.github.io/sweep/reference/tidiers_ets.html","id":null,"dir":"Reference","previous_headings":"","what":"Tidying methods for ETS (Error, Trend, Seasonal) exponential smoothing\nmodeling of time series — tidiers_ets","title":"Tidying methods for ETS (Error, Trend, Seasonal) exponential smoothing\nmodeling of time series — tidiers_ets","text":"Tidying methods ETS (Error, Trend, Seasonal) exponential smoothing modeling time series","code":""},{"path":"https://business-science.github.io/sweep/reference/tidiers_ets.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Tidying methods for ETS (Error, Trend, Seasonal) exponential smoothing\nmodeling of time series — tidiers_ets","text":"","code":"# 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\", ...)"},{"path":"https://business-science.github.io/sweep/reference/tidiers_ets.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Tidying methods for ETS (Error, Trend, Seasonal) exponential smoothing\nmodeling of time series — tidiers_ets","text":"x object class \"ets\" ... used. data Used sw_augment . NULL default simply returns augmented columns . User can supply original data, returns data + augmented columns. timetk_idx Used sw_augment sw_tidy_decomp. TRUE, uses timetk index (irregular, typically date datetime) present. rename_index Used sw_augment sw_tidy_decomp. string representing name index generated.","code":""},{"path":"https://business-science.github.io/sweep/reference/tidiers_ets.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Tidying methods for ETS (Error, Trend, Seasonal) exponential smoothing\nmodeling of time series — tidiers_ets","text":"sw_tidy() returns one row model parameter, two columns: term: smoothing parameters (alpha, gamma) initial states (l, s0 s10) estimate: estimated parameter value sw_glance() returns one row columns model.desc: description model including three integer components (p, d, q) AR order, degree differencing, MA order. sigma: square root estimated residual variance logLik: data's log-likelihood model AIC: Akaike Information Criterion BIC: Bayesian Information Criterion : 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 errors lag 1 sw_augment() returns tibble following time series attributes: index: index either attempted extracted model sequential index created plotting purposes .actual: original time series .fitted: fitted values model .resid: residual values model sw_tidy_decomp() returns tibble following time series attributes: index: index either attempted extracted model sequential index created plotting purposes observed: original time series level: level component slope: slope component (always present) season: seasonal component (always present)","code":""},{"path":[]},{"path":"https://business-science.github.io/sweep/reference/tidiers_ets.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Tidying methods for ETS (Error, Trend, Seasonal) exponential smoothing\nmodeling of time series — tidiers_ets","text":"","code":"library(dplyr) library(forecast) fit_ets <- WWWusage %>% ets() sw_tidy(fit_ets) #> # A tibble: 5 × 2 #> term estimate #> #> 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 #> #> 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 #> #> 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 #> #> 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"},{"path":"https://business-science.github.io/sweep/reference/tidiers_nnetar.html","id":null,"dir":"Reference","previous_headings":"","what":"Tidying methods for Nural Network Time Series models — tidiers_nnetar","title":"Tidying methods for Nural Network Time Series models — tidiers_nnetar","text":"methods tidy coefficients NNETAR models univariate time series.","code":""},{"path":"https://business-science.github.io/sweep/reference/tidiers_nnetar.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Tidying methods for Nural Network Time Series models — tidiers_nnetar","text":"","code":"# 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\", ...)"},{"path":"https://business-science.github.io/sweep/reference/tidiers_nnetar.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Tidying methods for Nural Network Time Series models — tidiers_nnetar","text":"x object class \"nnetar\" ... Additional parameters (used) data Used sw_augment . NULL default simply returns augmented columns . User can supply original data, returns data + augmented columns. timetk_idx Used sw_augment . Uses irregular timetk index present. rename_index Used sw_augment . string representing name index generated.","code":""},{"path":"https://business-science.github.io/sweep/reference/tidiers_nnetar.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Tidying methods for Nural Network Time Series models — tidiers_nnetar","text":"sw_tidy() returns one row model parameter, two columns: term: smoothing parameters (alpha, gamma) initial states (l, s0 s10) estimate: estimated parameter value sw_glance() returns one row columns model.desc: description model including three integer components (p, d, q) AR order, degree differencing, MA order. sigma: square root estimated residual variance logLik: data's log-likelihood model (NA) AIC: Akaike Information Criterion (NA) BIC: Bayesian Information Criterion (NA) : 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 errors lag 1 sw_augment() returns tibble following time series attributes: index: index either attempted extracted model sequential index created plotting purposes .actual: original time series .fitted: fitted values model .resid: residual values model","code":""},{"path":[]},{"path":"https://business-science.github.io/sweep/reference/tidiers_nnetar.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Tidying methods for Nural Network Time Series models — tidiers_nnetar","text":"","code":"library(dplyr) library(forecast) fit_nnetar <- lynx %>% nnetar() sw_tidy(fit_nnetar) #> # A tibble: 4 × 2 #> term estimate #> #> 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 #> #> 1 NNAR(8,4) 313. NA NA NA -0.300 313. 226. -38.2 52.2 0.272 #> # ℹ 1 more variable: ACF1 sw_augment(fit_nnetar) #> # A tibble: 114 × 4 #> index .actual .fitted .resid #> #> 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 4560. 390. #> 10 1830 2577 2467. 110. #> # ℹ 104 more rows"},{"path":"https://business-science.github.io/sweep/reference/tidiers_stl.html","id":null,"dir":"Reference","previous_headings":"","what":"Tidying methods for STL (Seasonal, Trend, Level) decomposition of time series — tidiers_stl","title":"Tidying methods for STL (Seasonal, Trend, Level) decomposition of time series — tidiers_stl","text":"Tidying methods STL (Seasonal, Trend, Level) decomposition time series","code":""},{"path":"https://business-science.github.io/sweep/reference/tidiers_stl.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Tidying methods for STL (Seasonal, Trend, Level) decomposition of time series — tidiers_stl","text":"","code":"# 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, ...)"},{"path":"https://business-science.github.io/sweep/reference/tidiers_stl.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Tidying methods for STL (Seasonal, Trend, Level) decomposition of time series — tidiers_stl","text":"x object class \"stl\" ... used. timetk_idx Used sw_tidy_decomp. TRUE, uses timetk index (irregular, typically date datetime) present. rename_index Used sw_tidy_decomp. string representing name index generated. data Used sw_augment .","code":""},{"path":"https://business-science.github.io/sweep/reference/tidiers_stl.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Tidying methods for STL (Seasonal, Trend, Level) decomposition of time series — tidiers_stl","text":"sw_tidy() wraps sw_tidy_decomp() sw_tidy_decomp() returns tibble following time series attributes: index: index either attempted extracted model sequential index created plotting purposes season: seasonal component trend: trend component remainder: observed - (season + trend) seasadj: observed - season (trend + remainder) sw_glance() returns underlying ETS ARIMA model's sw_glance() results one row columns model.desc: description model including three integer components (p, d, q) AR order, degree differencing, MA order. sigma: square root estimated residual variance logLik: data's log-likelihood model AIC: Akaike Information Criterion BIC: Bayesian Information Criterion : 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 errors lag 1 sw_augment() returns tibble following time series attributes: index: index either attempted extracted model sequential index created plotting purposes .actual: original time series .fitted: fitted values model .resid: residual values model","code":""},{"path":[]},{"path":"https://business-science.github.io/sweep/reference/tidiers_stl.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Tidying methods for STL (Seasonal, Trend, Level) decomposition of time series — tidiers_stl","text":"","code":"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 #> #> 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"},{"path":"https://business-science.github.io/sweep/reference/validate_index.html","id":null,"dir":"Reference","previous_headings":"","what":"Validates data frame has column named the same name as variable rename_index — validate_index","title":"Validates data frame has column named the same name as variable rename_index — validate_index","text":"Validates data frame column named name variable rename_index","code":""},{"path":"https://business-science.github.io/sweep/reference/validate_index.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Validates data frame has column named the same name as variable rename_index — validate_index","text":"","code":"validate_index(ret, rename_index)"},{"path":"https://business-science.github.io/sweep/reference/validate_index.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Validates data frame has column named the same name as variable rename_index — validate_index","text":"ret object class tibble rename_index variable indicating index name used tibble returned","code":""},{"path":"https://business-science.github.io/sweep/news/index.html","id":"sweep-development-version","dir":"Changelog","previous_headings":"","what":"sweep (development version)","title":"sweep (development version)","text":"sweep longer imports tidyverse. (@olivroy, #22) Remove internal usage dplyr::select_(). (@olivroy, #22)","code":""},{"path":"https://business-science.github.io/sweep/news/index.html","id":"sweep-025","dir":"Changelog","previous_headings":"","what":"sweep 0.2.5","title":"sweep 0.2.5","text":"CRAN release: 2023-07-06 Fixes get sweep back CRAN following inadvertent timetk archival.","code":""},{"path":"https://business-science.github.io/sweep/news/index.html","id":"sweep-024","dir":"Changelog","previous_headings":"","what":"sweep 0.2.4","title":"sweep 0.2.4","text":"Remove support robets.","code":""},{"path":"https://business-science.github.io/sweep/news/index.html","id":"sweep-023","dir":"Changelog","previous_headings":"","what":"sweep 0.2.3","title":"sweep 0.2.3","text":"CRAN release: 2020-07-10 Fixes compatability broom v0.7.0 Add tidiers stlm() models","code":""},{"path":"https://business-science.github.io/sweep/news/index.html","id":"sweep-022","dir":"Changelog","previous_headings":"","what":"sweep 0.2.2","title":"sweep 0.2.2","text":"CRAN release: 2019-10-08 Fixes compatability tidyquant v0.5.7","code":""},{"path":"https://business-science.github.io/sweep/news/index.html","id":"sweep-021","dir":"Changelog","previous_headings":"","what":"sweep 0.2.1","title":"sweep 0.2.1","text":"CRAN release: 2018-03-03 Fixes forecast::mstl","code":""},{"path":"https://business-science.github.io/sweep/news/index.html","id":"sweep-020","dir":"Changelog","previous_headings":"","what":"sweep 0.2.0","title":"sweep 0.2.0","text":"CRAN release: 2017-07-26 Change timetk timekit. Fix Issue #2 - sw_tidy fails auto.arima() returns terms (coefficients).","code":""},{"path":"https://business-science.github.io/sweep/news/index.html","id":"sweep-010","dir":"Changelog","previous_headings":"","what":"sweep 0.1.0","title":"sweep 0.1.0","text":"CRAN release: 2017-07-03 Initial release sweep, tool “tidy” forecast modeling prediction workflow.","code":""}]