diff --git a/docs/404.html b/docs/404.html index e86407d..3639341 100644 --- a/docs/404.html +++ b/docs/404.html @@ -4,126 +4,108 @@ - + Page not found (404) • sweep - - - + + + + + + + + + - - + + + - + + Skip to contents -
-
-
- Content not found. Please use links in the navbar. -
- - - +
- -
- diff --git a/docs/articles/SW00_Introduction_to_sweep.html b/docs/articles/SW00_Introduction_to_sweep.html index 0481b54..58f9d5b 100644 --- a/docs/articles/SW00_Introduction_to_sweep.html +++ b/docs/articles/SW00_Introduction_to_sweep.html @@ -4,104 +4,97 @@ - + + Introduction to sweep • sweep - - - + + + + + + + + + - - + + + - + + Skip to contents -
-
-
-

Forecasting Sales of Beer, Wine, and Distilled Alcohol @@ -155,13 +141,13 @@

Forecast sales, which comes from the FRED data base (the origin is the US Bureau of the Census, one of the 80+ data sources FRED connects to). The FRED code is “S4248SM144NCEN” and the data set can be found here.

-
+
 alcohol_sales_tbl <- tq_get("S4248SM144NCEN", 
                             get  = "economic.data", 
                             from = "2007-01-01",
                             to   = "2016-12-31")
 alcohol_sales_tbl
-
## # A tibble: 120 x 3
+
## # A tibble: 120 × 3
 ##    symbol         date       price
 ##    <chr>          <date>     <int>
 ##  1 S4248SM144NCEN 2007-01-01  6627
@@ -174,24 +160,19 @@ 

Forecast ## 8 S4248SM144NCEN 2007-08-01 9543 ## 9 S4248SM144NCEN 2007-09-01 8123 ## 10 S4248SM144NCEN 2007-10-01 9649 -## # i 110 more rows

+## # ℹ 110 more rows

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

-
+
 alcohol_sales_tbl %>%
     ggplot(aes(x = date, y = price)) +
-    geom_line(size = 1, color = palette_light()[[1]]) +
+    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()
-
## Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
-## i Please use `linewidth` instead.
-## This warning is displayed once every 8 hours.
-## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
-## generated.
## `geom_smooth()` using formula = 'y ~ x'

@@ -226,7 +207,7 @@

Step 1: Coerce to a ts skip the warning notifying us that the “date” column is being dropped. Non-numeric columns must be dropped for ts class, which is matrix based and a homogeneous data class.

-
+
 alcohol_sales_ts <- tk_ts(alcohol_sales_tbl, start = 2007, freq = 12, silent = TRUE)
 alcohol_sales_ts
##        Jan   Feb   Mar   Apr   May   Jun   Jul   Aug   Sep   Oct   Nov   Dec
@@ -244,7 +225,7 @@ 

Step 1: Coerce to a ts maintains a “timetk index”, which will help with forecasting dates later. We can verify this using has_timetk_idx() from the timetk package.

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

Now that a time series has been coerced, let’s proceed with @@ -257,7 +238,7 @@

Step 2: Modeling a time seriesets() function from the forecast package to get an Exponential Smoothing ETS (Error, Trend, Seasonal) model.

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

Where sweep can help is in the evaluation of a model. @@ -441,9 +422,9 @@

Step 2: Modeling a time seriessw_tidy

sw_tidy() returns the model parameters.

-
+
 sw_tidy(fit_ets)
-
## # A tibble: 17 x 2
+
## # A tibble: 17 × 2
 ##    term     estimate
 ##    <chr>       <dbl>
 ##  1 alpha    0.159   
@@ -468,23 +449,23 @@ 

sw_tidysw_glance

sw_glance() returns the model quality parameters.

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

sw_augment

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

-
+
 augment_fit_ets <- sw_augment(fit_ets)
 augment_fit_ets
-
## # A tibble: 120 x 4
+
## # A tibble: 120 × 4
 ##    index     .actual .fitted   .resid
 ##    <yearmon>   <dbl>   <dbl>    <dbl>
 ##  1 Jan 2007     6627   6446.  0.0280 
@@ -497,11 +478,11 @@ 

sw_augment## 8 Aug 2007 9543 8932. 0.0684 ## 9 Sep 2007 8123 8694. -0.0657 ## 10 Oct 2007 9649 8977. 0.0749 -## # i 110 more rows

+## # ℹ 110 more rows

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

-
+
 augment_fit_ets %>%
     ggplot(aes(x = index, y = .resid)) +
     geom_hline(yintercept = 0, color = "grey40") +
@@ -518,10 +499,10 @@ 

sw_tidy_decomp

sw_tidy_decomp() returns the decomposition of the ETS model.

-
+
 decomp_fit_ets <- sw_tidy_decomp(fit_ets)
 decomp_fit_ets 
-
## # A tibble: 121 x 5
+
## # A tibble: 121 × 5
 ##    index     observed level slope season
 ##    <yearmon>    <dbl> <dbl> <dbl>  <dbl>
 ##  1 Dec 2006        NA 8389.  38.9  1.17 
@@ -534,19 +515,19 @@ 

sw_tidy_decomp## 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 -## # i 111 more rows

+## # ℹ 111 more rows

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

-
+
 decomp_fit_ets %>%
-    gather(key = key, value = value, -index) %>%
-    mutate(key = forcats::as_factor(key)) %>%
+    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) +
@@ -556,7 +537,7 @@ 

sw_tidy_decomp 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.
-## i Please use `linewidth` in the `default_aes` field and elsewhere instead.
+##  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.
@@ -572,13 +553,13 @@

sw_tidy_decomp

Step 3: Forecasting the model

-

Next we forecast the ETS model using the forecast() +

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

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

Step 4: Tidy the forecast object @@ -588,9 +569,9 @@

Step 4: Tidy the forecast objectsw_sweep() function then coerces the forecast object into a tibble that can be sent to ggplot for visualization. Let’s inspect the result.

-
+
 sw_sweep(fcast_ets, fitted = TRUE)
-
## # A tibble: 252 x 7
+
## # A tibble: 252 × 7
 ##    index     key    price lo.80 lo.95 hi.80 hi.95
 ##    <yearmon> <chr>  <dbl> <dbl> <dbl> <dbl> <dbl>
 ##  1 Jan 2007  actual  6627    NA    NA    NA    NA
@@ -603,7 +584,7 @@ 

Step 4: Tidy the forecast object## 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 -## # i 242 more rows

+## # ℹ 242 more rows

The tibble returned contains “index”, “key” and “value” (or in this case “price”) columns in a long or “tidy” format that is ideal for visualization with ggplot2. The “index” is in a regularized @@ -621,7 +602,7 @@

Step 4: Tidy the forecast objectets() function (excluded by default)
  • forecast: the predicted values from the -forecast() function
  • +forecast() function

    The sw_sweep() function contains an argument fitted = FALSE by default meaning that the model “fitted” @@ -636,17 +617,17 @@

    Step 4: Tidy the forecast objectyearmon class, we need to add scale_x_yearmon().

    -
    +
     sw_sweep(fcast_ets) %>%
         ggplot(aes(x = index, y = price, color = key)) +
         geom_ribbon(aes(ymin = lo.95, ymax = hi.95), 
    -                fill = "#D5DBFF", color = NA, size = 0) +
    +                fill = "#D5DBFF", color = NA, linewidth = 0) +
         geom_ribbon(aes(ymin = lo.80, ymax = hi.80, fill = key), 
    -                fill = "#596DD5", color = NA, size = 0, alpha = 0.8) +
    -    geom_line(size = 1) +
    +                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::dollar) +
    +    scale_y_continuous(labels = scales::label_dollar()) +
         scale_x_yearmon(n = 12, format = "%Y") +
         scale_color_tq() +
         scale_fill_tq() +
    @@ -661,10 +642,11 @@ 

    Step 4: Tidy the forecast objectforecast objects. Notice that the index is returned as date class.

    -
    +
     sw_sweep(fcast_ets, timetk_idx = TRUE) %>%
         head()
    -
    ## # A tibble: 6 x 7
    +
    ## Warning in .check_tzones(e1, e2): 'tzone' attributes are inconsistent
    +
    ## # A tibble: 6 × 7
     ##   index      key    price lo.80 lo.95 hi.80 hi.95
     ##   <date>     <chr>  <dbl> <dbl> <dbl> <dbl> <dbl>
     ## 1 2007-01-01 actual  6627    NA    NA    NA    NA
    @@ -673,10 +655,11 @@ 

    Step 4: Tidy the forecast object## 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()
    -
    ## # A tibble: 6 x 7
    +
    ## Warning in .check_tzones(e1, e2): 'tzone' attributes are inconsistent
    +
    ## # A tibble: 6 × 7
     ##   index      key       price  lo.80  lo.95  hi.80  hi.95
     ##   <date>     <chr>     <dbl>  <dbl>  <dbl>  <dbl>  <dbl>
     ## 1 2017-07-01 forecast 12117. 11309. 10882. 12924. 13351.
    @@ -686,14 +669,14 @@ 

    Step 4: Tidy the forecast object## 5 2017-11-01 forecast 12559. 11619. 11122. 13499. 13996. ## 6 2017-12-01 forecast 14499. 13380. 12788. 15618. 16211.

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

    -
    +
     sw_sweep(fcast_ets, timetk_idx = TRUE) %>%
         ggplot(aes(x = index, y = price, color = key)) +
         geom_ribbon(aes(ymin = lo.95, ymax = hi.95), 
    -                fill = "#D5DBFF", color = NA, size = 0) +
    +                fill = "#D5DBFF", color = NA, linewidth = 0) +
         geom_ribbon(aes(ymin = lo.80, ymax = hi.80, fill = key), 
    -                fill = "#596DD5", color = NA, size = 0, alpha = 0.8) +
    -    geom_line(size = 1) +
    +                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) +
    @@ -701,6 +684,7 @@ 

    Step 4: Tidy the forecast object scale_color_tq() + scale_fill_tq() + theme_tq()

    +
    ## Warning in .check_tzones(e1, e2): 'tzone' attributes are inconsistent

    In this example, there is not much benefit to returning an irregular time series. However, when working with frequencies below monthly, the @@ -715,34 +699,27 @@

    Recap In the next vignette, we discuss some more powerful concepts including forecasting at scale with grouped time series analysis.

    -
    - - - +
    -

    - diff --git a/docs/articles/SW00_Introduction_to_sweep_files/figure-html/unnamed-chunk-12-1.png b/docs/articles/SW00_Introduction_to_sweep_files/figure-html/unnamed-chunk-12-1.png index cda06bf..d7d6835 100644 Binary files a/docs/articles/SW00_Introduction_to_sweep_files/figure-html/unnamed-chunk-12-1.png and b/docs/articles/SW00_Introduction_to_sweep_files/figure-html/unnamed-chunk-12-1.png differ diff --git a/docs/articles/SW00_Introduction_to_sweep_files/figure-html/unnamed-chunk-14-1.png b/docs/articles/SW00_Introduction_to_sweep_files/figure-html/unnamed-chunk-14-1.png index b3531e8..e7619a6 100644 Binary files a/docs/articles/SW00_Introduction_to_sweep_files/figure-html/unnamed-chunk-14-1.png and b/docs/articles/SW00_Introduction_to_sweep_files/figure-html/unnamed-chunk-14-1.png differ diff --git a/docs/articles/SW00_Introduction_to_sweep_files/figure-html/unnamed-chunk-17-1.png b/docs/articles/SW00_Introduction_to_sweep_files/figure-html/unnamed-chunk-17-1.png index 5fea758..1ccf56b 100644 Binary files a/docs/articles/SW00_Introduction_to_sweep_files/figure-html/unnamed-chunk-17-1.png and b/docs/articles/SW00_Introduction_to_sweep_files/figure-html/unnamed-chunk-17-1.png differ diff --git a/docs/articles/SW00_Introduction_to_sweep_files/figure-html/unnamed-chunk-20-1.png b/docs/articles/SW00_Introduction_to_sweep_files/figure-html/unnamed-chunk-20-1.png index c9671e0..69a3935 100644 Binary files a/docs/articles/SW00_Introduction_to_sweep_files/figure-html/unnamed-chunk-20-1.png and b/docs/articles/SW00_Introduction_to_sweep_files/figure-html/unnamed-chunk-20-1.png differ diff --git a/docs/articles/SW00_Introduction_to_sweep_files/figure-html/unnamed-chunk-4-1.png b/docs/articles/SW00_Introduction_to_sweep_files/figure-html/unnamed-chunk-4-1.png index af133e8..3a6e4d4 100644 Binary files a/docs/articles/SW00_Introduction_to_sweep_files/figure-html/unnamed-chunk-4-1.png and b/docs/articles/SW00_Introduction_to_sweep_files/figure-html/unnamed-chunk-4-1.png differ diff --git a/docs/articles/SW01_Forecasting_Time_Series_Groups.html b/docs/articles/SW01_Forecasting_Time_Series_Groups.html index 6ef0020..a153606 100644 --- a/docs/articles/SW01_Forecasting_Time_Series_Groups.html +++ b/docs/articles/SW01_Forecasting_Time_Series_Groups.html @@ -4,105 +4,97 @@ - + + Forecasting Time Series Groups in the tidyverse • sweep - - - + + + + + + + + + - - + + + - + + Skip to contents -
    -
    -
    -

    Bike Sales @@ -147,9 +136,9 @@

    Bike Sales
    +
     bike_sales
    -
    ## # A tibble: 15,644 x 17
    +
    ## # A tibble: 15,644 × 17
     ##    order.date order.id order.line quantity price price.ext customer.id
     ##    <date>        <dbl>      <int>    <dbl> <dbl>     <dbl>       <dbl>
     ##  1 2011-01-07        1          1        1  6070      6070           2
    @@ -162,13 +151,13 @@ 

    Bike Sales## 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 -## # i 15,634 more rows -## # i 10 more variables: bikeshop.name <chr>, bikeshop.city <chr>, +## # ℹ 15,634 more rows +## # ℹ 10 more variables: bikeshop.name <chr>, bikeshop.city <chr>, ## # bikeshop.state <chr>, latitude <dbl>, longitude <dbl>, product.id <dbl>, ## # model <chr>, category.primary <chr>, category.secondary <chr>, frame <chr>

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

    -
    +
     bike_sales_monthly <- bike_sales %>%
         mutate(month = month(order.date, label = TRUE),
                year  = year(order.date)) %>%
    @@ -176,9 +165,9 @@ 

    Bike Salessummarise(total.qty = sum(quantity))

    ## `summarise()` has grouped output by 'year'. You can override using the
     ## `.groups` argument.
    -
    +
     bike_sales_monthly
    -
    ## # A tibble: 60 x 3
    +
    ## # A tibble: 60 × 3
     ## # Groups:   year [5]
     ##     year month total.qty
     ##    <dbl> <ord>     <dbl>
    @@ -192,10 +181,10 @@ 

    Bike Sales## 8 2011 Aug 1470 ## 9 2011 Sep 975 ## 10 2011 Oct 697 -## # i 50 more rows

    +## # ℹ 50 more rows

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

    -
    +
     bike_sales_monthly %>%
         ggplot(aes(x = month, y = total.qty, group = year)) +
         geom_area(aes(fill = year), position = "stack") +
    @@ -217,16 +206,16 @@ 

    Performing Forecasts on Groupszoo::as.yearmon() that captures the year and month information from the “order.date” and then passing this to lubridate::as_date() to convert to date format.

    -
    +
     monthly_qty_by_cat2 <- bike_sales %>%
         mutate(order.month = as_date(as.yearmon(order.date))) %>%
         group_by(category.secondary, order.month) %>%
         summarise(total.qty = sum(quantity))
    ## `summarise()` has grouped output by 'category.secondary'. You can override
     ## using the `.groups` argument.
    -
    +
     monthly_qty_by_cat2
    -
    ## # A tibble: 538 x 3
    +
    ## # A tibble: 538 × 3
     ## # Groups:   category.secondary [9]
     ##    category.secondary order.month total.qty
     ##    <chr>              <date>          <dbl>
    @@ -240,31 +229,31 @@ 

    Performing Forecasts on Groups## 8 Cross Country Race 2011-08-01 66 ## 9 Cross Country Race 2011-09-01 97 ## 10 Cross Country Race 2011-10-01 189 -## # i 528 more rows

    +## # ℹ 528 more rows

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

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

    Step 2: Modeling a time series
    +
     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 x 4
    +
    ## # A tibble: 9 × 4
     ## # Groups:   category.secondary [9]
     ##   category.secondary data              data.ts       fit.ets
     ##   <chr>              <list>            <list>        <list> 
    -## 1 Cross Country Race <tibble [60 x 2]> <ts [60 x 1]> <ets>  
    -## 2 Cyclocross         <tibble [60 x 2]> <ts [60 x 1]> <ets>  
    -## 3 Elite Road         <tibble [60 x 2]> <ts [60 x 1]> <ets>  
    -## 4 Endurance Road     <tibble [60 x 2]> <ts [60 x 1]> <ets>  
    -## 5 Fat Bike           <tibble [58 x 2]> <ts [58 x 1]> <ets>  
    -## 6 Over Mountain      <tibble [60 x 2]> <ts [60 x 1]> <ets>  
    -## 7 Sport              <tibble [60 x 2]> <ts [60 x 1]> <ets>  
    -## 8 Trail              <tibble [60 x 2]> <ts [60 x 1]> <ets>  
    -## 9 Triathalon         <tibble [60 x 2]> <ts [60 x 1]> <ets>
    +## 1 Cross Country Race <tibble [60 × 2]> <ts [60 × 1]> <ets> +## 2 Cyclocross <tibble [60 × 2]> <ts [60 × 1]> <ets> +## 3 Elite Road <tibble [60 × 2]> <ts [60 × 1]> <ets> +## 4 Endurance Road <tibble [60 × 2]> <ts [60 × 1]> <ets> +## 5 Fat Bike <tibble [58 × 2]> <ts [58 × 1]> <ets> +## 6 Over Mountain <tibble [60 × 2]> <ts [60 × 1]> <ets> +## 7 Sport <tibble [60 × 2]> <ts [60 × 1]> <ets> +## 8 Trail <tibble [60 × 2]> <ts [60 × 1]> <ets> +## 9 Triathalon <tibble [60 × 2]> <ts [60 × 1]> <ets>

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

    @@ -361,26 +350,26 @@

    sw_tidyspread() from the tidyr package.

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

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

    @@ -416,32 +405,40 @@

    sw_augment
    +
     augment_fit_ets <- monthly_qty_by_cat2_fit %>%
         mutate(augment = map(fit.ets, sw_augment, timetk_idx = TRUE, rename_index = "date")) %>%
    -    unnest(augment)
    -
    -augment_fit_ets
    -
    ## # A tibble: 538 x 8
    +    unnest(augment)

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

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

    -
    +
     augment_fit_ets %>%
         ggplot(aes(x = date, y = .resid, group = category.secondary)) +
         geom_hline(yintercept = 0, color = "grey40") +
    @@ -461,26 +458,34 @@ 

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

    -
    +
     monthly_qty_by_cat2_fit %>%
         mutate(decomp = map(fit.ets, sw_tidy_decomp, timetk_idx = TRUE, rename_index = "date")) %>%
         unnest(decomp)
    -
    ## # A tibble: 538 x 9
    +
    ## 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
    -##    <chr>              <list>   <list>        <list>  <date>        <dbl> <dbl>
    -##  1 Cross Country Race <tibble> <ts [60 x 1]> <ets>   2011-01-01      122  313.
    -##  2 Cross Country Race <tibble> <ts [60 x 1]> <ets>   2011-02-01      489  331.
    -##  3 Cross Country Race <tibble> <ts [60 x 1]> <ets>   2011-03-01      505  332.
    -##  4 Cross Country Race <tibble> <ts [60 x 1]> <ets>   2011-04-01      343  347.
    -##  5 Cross Country Race <tibble> <ts [60 x 1]> <ets>   2011-05-01      263  339.
    -##  6 Cross Country Race <tibble> <ts [60 x 1]> <ets>   2011-06-01      735  359.
    -##  7 Cross Country Race <tibble> <ts [60 x 1]> <ets>   2011-07-01      183  348.
    -##  8 Cross Country Race <tibble> <ts [60 x 1]> <ets>   2011-08-01       66  339.
    -##  9 Cross Country Race <tibble> <ts [60 x 1]> <ets>   2011-09-01       97  329.
    -## 10 Cross Country Race <tibble> <ts [60 x 1]> <ets>   2011-10-01      189  336.
    -## # i 528 more rows
    -## # i 2 more variables: season <dbl>, slope <dbl>
    +## category.secondary data data.ts fit.ets date observed level season +## <chr> <list> <list> <list> <date> <dbl> <dbl> <dbl> +## 1 Cross Country Race <tibble> <ts[…]> <ets> 2011-01-01 122 313. 1.16 +## 2 Cross Country Race <tibble> <ts[…]> <ets> 2011-02-01 489 331. 0.643 +## 3 Cross Country Race <tibble> <ts[…]> <ets> 2011-03-01 505 332. 1.41 +## 4 Cross Country Race <tibble> <ts[…]> <ets> 2011-04-01 343 347. 0.487 +## 5 Cross Country Race <tibble> <ts[…]> <ets> 2011-05-01 263 339. 1.64 +## 6 Cross Country Race <tibble> <ts[…]> <ets> 2011-06-01 735 359. 0.873 +## 7 Cross Country Race <tibble> <ts[…]> <ets> 2011-07-01 183 348. 2.06 +## 8 Cross Country Race <tibble> <ts[…]> <ets> 2011-08-01 66 339. 0.630 +## 9 Cross Country Race <tibble> <ts[…]> <ets> 2011-09-01 97 329. 1.12 +## 10 Cross Country Race <tibble> <ts[…]> <ets> 2011-10-01 189 336. 0.375 +## # ℹ 528 more rows +## # ℹ 1 more variable: slope <dbl>

    @@ -489,25 +494,25 @@

    Step 3: Forecasting the model?forecast for all of the parameters you can add, there’s +?forecast for all of the parameters you can add, there’s quite a few).

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

    Step 4: Tidy the forecast @@ -519,36 +524,45 @@

    Step 4: Tidy the forecastunnest() to drop the left over list-columns and return an unnested data frame.

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

    Visualization is just one final step.

    -
    +
     monthly_qty_by_cat2_fcast_tidy %>%
         ggplot(aes(x = index, y = total.qty, color = key, group = category.secondary)) +
         geom_ribbon(aes(ymin = lo.95, ymax = hi.95), 
    -                fill = "#D5DBFF", color = NA, size = 0) +
    +                fill = "#D5DBFF", color = NA, linewidth = 0) +
         geom_ribbon(aes(ymin = lo.80, ymax = hi.80, fill = key), 
    -                fill = "#596DD5", color = NA, size = 0, alpha = 0.8) +
    +                fill = "#596DD5", color = NA, linewidth = 0, alpha = 0.8) +
         geom_line() +
         labs(title = "Bike Quantity Sold By Secondary Category",
              subtitle = "ETS Model Forecasts",
    @@ -559,11 +573,6 @@ 

    Step 4: Tidy the forecast facet_wrap(~ category.secondary, scales = "free_y", ncol = 3) + theme_tq() + theme(axis.text.x = element_text(angle = 45, hjust = 1))

    -
    ## Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
    -## i Please use `linewidth` instead.
    -## This warning is displayed once every 8 hours.
    -## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
    -## generated.

    @@ -574,34 +583,27 @@

    Recap time series. In the next vignette we will review how to apply multiple models to a time series.

    -
    - - - +

    -
    - diff --git a/docs/articles/SW01_Forecasting_Time_Series_Groups_files/figure-html/unnamed-chunk-13-1.png b/docs/articles/SW01_Forecasting_Time_Series_Groups_files/figure-html/unnamed-chunk-13-1.png index eafd595..4b6310f 100644 Binary files a/docs/articles/SW01_Forecasting_Time_Series_Groups_files/figure-html/unnamed-chunk-13-1.png and b/docs/articles/SW01_Forecasting_Time_Series_Groups_files/figure-html/unnamed-chunk-13-1.png differ diff --git a/docs/articles/SW01_Forecasting_Time_Series_Groups_files/figure-html/unnamed-chunk-17-1.png b/docs/articles/SW01_Forecasting_Time_Series_Groups_files/figure-html/unnamed-chunk-17-1.png index 8f8128d..2abe0e4 100644 Binary files a/docs/articles/SW01_Forecasting_Time_Series_Groups_files/figure-html/unnamed-chunk-17-1.png and b/docs/articles/SW01_Forecasting_Time_Series_Groups_files/figure-html/unnamed-chunk-17-1.png differ diff --git a/docs/articles/SW01_Forecasting_Time_Series_Groups_files/figure-html/unnamed-chunk-5-1.png b/docs/articles/SW01_Forecasting_Time_Series_Groups_files/figure-html/unnamed-chunk-5-1.png index 74580fc..a0b3cd9 100644 Binary files a/docs/articles/SW01_Forecasting_Time_Series_Groups_files/figure-html/unnamed-chunk-5-1.png and b/docs/articles/SW01_Forecasting_Time_Series_Groups_files/figure-html/unnamed-chunk-5-1.png differ diff --git a/docs/articles/SW02_Forecasting_Multiple_Models.html b/docs/articles/SW02_Forecasting_Multiple_Models.html index 4c5f92f..22a3f3d 100644 --- a/docs/articles/SW02_Forecasting_Multiple_Models.html +++ b/docs/articles/SW02_Forecasting_Multiple_Models.html @@ -4,104 +4,97 @@ - + + Forecasting Using Multiple Models • sweep - - - + + + + + + + + + - - + + + - + + Skip to contents -
    -
    -
    -

    Forecasting Gasoline Prices

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

    -
    +Gasoline Prices from 1990 through today (2023-12-08).

    +
     gas_prices_monthly_raw <- tq_get(
         x    = "GASREGCOVM", 
         get  = "economic.data", 
         from = "1990-01-01", 
         to   = "2016-12-31") 
     gas_prices_monthly_raw
    -
    ## # A tibble: 316 x 3
    +
    ## # A tibble: 316 × 3
     ##    symbol     date       price
     ##    <chr>      <date>     <dbl>
     ##  1 GASREGCOVM 1990-09-01  1.26
    @@ -163,10 +153,10 @@ 

    Forecasting Gasoline Prices## 8 GASREGCOVM 1991-04-01 1.08 ## 9 GASREGCOVM 1991-05-01 1.13 ## 10 GASREGCOVM 1991-06-01 1.13 -## # i 306 more rows

    +## # ℹ 306 more rows

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

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

    Forecasting Gasoline Prices
    %>%
         fill(price, .direction = "down") %>%
         fill(price, .direction = "up")

    We can now visualize the data.

    -
    +
     gas_prices_monthly %>%
         ggplot(aes(x = date, y = price)) +
         geom_line(color = palette_light()[[1]]) +
    @@ -193,11 +183,11 @@ 

    Forecasting Gasoline Prices
    +
     gas_prices_quarterly <- gas_prices_monthly %>%
         tq_transmute(mutate_fun = to.period, period = "quarters") 
     gas_prices_quarterly
    -
    ## # A tibble: 106 x 2
    +
    ## # A tibble: 106 × 2
     ##    date       price
     ##    <date>     <dbl>
     ##  1 1990-09-01  1.26
    @@ -210,21 +200,16 @@ 

    Forecasting Gasoline Prices## 8 1992-06-01 1.14 ## 9 1992-09-01 1.12 ## 10 1992-12-01 1.08 -## # i 96 more rows

    +## # ℹ 96 more rows

    Another quick visualization to show the reduction in granularity.

    -
    +
     gas_prices_quarterly %>%
         ggplot(aes(x = date, y = price)) +
    -    geom_line(color = palette_light()[[1]], size = 1) +
    +    geom_line(color = palette_light()[[1]], linewidth = 1) +
         labs(title = "Gasoline Prices, Quarterly", x = "", y = "USD") +
    -    scale_y_continuous(labels = scales::dollar) +
    +    scale_y_continuous(labels = scales::label_dollar()) +
         scale_x_date(date_breaks = "5 years", date_labels = "%Y") +
         theme_tq()
    -
    ## Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
    -## i Please use `linewidth` instead.
    -## This warning is displayed once every 8 hours.
    -## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
    -## generated.

    @@ -246,7 +231,7 @@

    Multiple Models Concept -
    +
     df <- tibble(
       f = c("runif", "rpois", "rnorm"),
       params = list(
    @@ -256,7 +241,7 @@ 

    Multiple Models Concept ) ) df

    -
    ## # A tibble: 3 x 2
    +
    ## # A tibble: 3 × 2
     ##   f     params          
     ##   <chr> <list>          
     ## 1 runif <named list [1]>
    @@ -266,7 +251,7 @@ 

    Multiple Models Concept -
    +
     df$params
    ## [[1]]
     ## [[1]]$n
    @@ -294,17 +279,18 @@ 

    Multiple Models Conceptinvoke_map(). The parameter lists in the “params” column are passed to the function in the “f” column. The output is in a nested list-column named “out”.

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

    Multiple Models Concept## 3 rnorm <named list [3]> <dbl [10]>

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

    -
    +
     df_out$out
    ## [[1]]
    -##  [1] 0.7168111 0.3362430 0.2672394 0.2628689 0.2739463 0.3113810 0.2149605
    -##  [8] 0.7853907 0.1273967 0.8142541
    +##  [1] 0.1098369 0.2182292 0.2080745 0.3216613 0.7630704 0.8901244 0.6546826
    +##  [8] 0.3674819 0.9361377 0.3130597
     ## 
     ## [[2]]
    -## [1] 10  7  8  8 10
    +## [1] 10  8  9 15  7
     ## 
     ## [[3]]
    -##  [1]   0.9099061  -3.5457637  -3.2317158   9.2689360 -10.9789443   9.3618392
    -##  [7]  -6.9495087 -17.2391453 -15.9990590 -11.2272643
    +## [1] 4.015239 -22.284868 -21.065887 -11.125433 -13.054968 -3.462979 +## [7] -21.647962 -12.730876 6.930670 -5.200764

    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.

    @@ -341,7 +327,7 @@

    Multiple Model Implementationtk_ts().

    -
    +
     gas_prices_quarterly_ts <- gas_prices_quarterly %>% 
         tk_ts(select = -date, start = c(1990, 3), freq = 4)
     gas_prices_quarterly_ts
    @@ -376,7 +362,7 @@

    Multiple Model Implementation
    list(
         auto.arima = list(
             y = gas_prices_quarterly_ts
    @@ -390,14 +376,14 @@ 

    Multiple Model Implementation) )

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

    -
    -models_tbl <- enframe(models_list, name = "f", value = "params")
    +
    +models_tbl <- tibble::enframe(models_list, name = "f", value = "params")
     models_tbl
    -
    ## # A tibble: 3 x 2
    +
    ## # A tibble: 3 × 2
     ##   f          params          
     ##   <chr>      <list>          
     ## 1 auto.arima <named list [1]>
    @@ -406,11 +392,11 @@ 

    Multiple Model Implementationmutate() with invoke_map() as follows. Bada bing, bada boom, we now have models fitted using the parameters we defined previously.

    -
    +
     models_tbl_fit <- models_tbl %>%
    -    mutate(fit = invoke_map(f, params))
    +    mutate(fit = purrr::invoke_map(f, params))
     models_tbl_fit
    -
    ## # A tibble: 3 x 3
    +
    ## # A tibble: 3 × 3
     ##   f          params           fit       
     ##   <chr>      <list>           <list>    
     ## 1 auto.arima <named list [1]> <fr_ARIMA>
    @@ -433,12 +419,12 @@ 

    sw_tidysw_tidy() function as a new column named “tidy”. Then we unnest and spread to review the terms by model function.

    -
    +
     models_tbl_fit %>%
         mutate(tidy = map(fit, sw_tidy)) %>%
         unnest(tidy) %>%
         spread(key = f, value = estimate)
    -
    ## # A tibble: 20 x 6
    +
    ## # A tibble: 20 × 6
     ##    params           fit        term              auto.arima       bats       ets
     ##    <list>           <list>     <chr>                  <dbl>      <dbl>     <dbl>
     ##  1 <named list [1]> <fr_ARIMA> ar1                    0.834 NA         NA       
    @@ -470,21 +456,21 @@ 

    sw_glance
    +
     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.
    -## i All list-columns are now preserved.
    +##  All list-columns are now preserved.
     ## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
     ## generated.
    -
    ## # A tibble: 3 x 15
    +
    ## # A tibble: 3 × 15
     ##   f     params       fit        model.desc sigma logLik   AIC   BIC     ME  RMSE
     ##   <chr> <list>       <list>     <chr>      <dbl>  <dbl> <dbl> <dbl>  <dbl> <dbl>
    -## 1 auto~ <named list> <fr_ARIMA> ARIMA(1,1~ 0.298  -20.6  51.2  64.4 0.0180 0.291
    -## 2 ets   <named list> <ets>      ETS(M,Ad,~ 0.118  -76.6 173.  200.  0.0149 0.292
    -## 3 bats  <named list> <bats>     BATS(0, {~ 0.116  159.  179.  184.  0.0193 0.259
    -## # i 5 more variables: MAE <dbl>, MPE <dbl>, MAPE <dbl>, MASE <dbl>, ACF1 <dbl>
    +## 1 auto… <named list> <fr_ARIMA> ARIMA(1,1… 0.298 -20.6 51.2 64.4 0.0180 0.291 +## 2 ets <named list> <ets> ETS(M,Ad,… 0.118 -76.6 173. 200. 0.0149 0.292 +## 3 bats <named list> <bats> BATS(0, {… 0.116 159. 179. 184. 0.0193 0.259 +## # ℹ 5 more variables: MAE <dbl>, MPE <dbl>, MAPE <dbl>, MASE <dbl>, ACF1 <dbl>

    sw_augment @@ -494,7 +480,7 @@

    sw_augmentggplot() for plotting. Notice the ARIMA model has the largest residuals especially as the model index increases whereas the bats model has relatively low residuals.

    -
    +
     models_tbl_fit %>%
         mutate(augment = map(fit, sw_augment, rename_index = "date")) %>%
         unnest(augment) %>%
    @@ -515,11 +501,11 @@ 

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

    -
    +
     models_tbl_fcast <- models_tbl_fit %>%
         mutate(fcast = map(fit, forecast, h = 6))
     models_tbl_fcast
    -
    ## # A tibble: 3 x 4
    +
    ## # A tibble: 3 × 4
     ##   f          params           fit        fcast     
     ##   <chr>      <list>           <list>     <list>    
     ## 1 auto.arima <named list [1]> <fr_ARIMA> <forecast>
    @@ -534,52 +520,60 @@ 

    Tidying the forecast
    +
     models_tbl_fcast_tidy <- models_tbl_fcast %>%
    -    mutate(sweep = map(fcast, sw_sweep, fitted = FALSE, timetk_idx = TRUE, rename_index = "date"))
    -models_tbl_fcast_tidy
    -
    ## # A tibble: 3 x 5
    +    mutate(sweep = map(fcast, sw_sweep, fitted = FALSE, timetk_idx = TRUE, rename_index = "date"))

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

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

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

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

    -
    +
     models_tbl_fcast_tidy %>%
         unnest(sweep) %>%
         ggplot(aes(x = date, y = price, color = key, group = f)) +
         geom_ribbon(aes(ymin = lo.95, ymax = hi.95), 
    -                fill = "#D5DBFF", color = NA, size = 0) +
    +                fill = "#D5DBFF", color = NA, linewidth = 0) +
         geom_ribbon(aes(ymin = lo.80, ymax = hi.80, fill = key), 
    -                fill = "#596DD5", color = NA, size = 0, alpha = 0.8) +
    -    geom_line(size = 1) +
    +                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::dollar) +
    +    scale_y_continuous(labels = scales::label_dollar()) +
         scale_x_date(date_breaks = "5 years", date_labels = "%Y") +
         theme_tq() +
         scale_color_tq()
    @@ -592,34 +586,27 @@

    Recap models. In the next vignette we will review time series object coercion with sweep.

    -
    - - -
    - -
    - diff --git a/docs/articles/SW02_Forecasting_Multiple_Models_files/figure-html/unnamed-chunk-19-1.png b/docs/articles/SW02_Forecasting_Multiple_Models_files/figure-html/unnamed-chunk-19-1.png index 9c5349b..66250d3 100644 Binary files a/docs/articles/SW02_Forecasting_Multiple_Models_files/figure-html/unnamed-chunk-19-1.png and b/docs/articles/SW02_Forecasting_Multiple_Models_files/figure-html/unnamed-chunk-19-1.png differ diff --git a/docs/articles/SW02_Forecasting_Multiple_Models_files/figure-html/unnamed-chunk-23-1.png b/docs/articles/SW02_Forecasting_Multiple_Models_files/figure-html/unnamed-chunk-23-1.png index c0f9817..a89ca19 100644 Binary files a/docs/articles/SW02_Forecasting_Multiple_Models_files/figure-html/unnamed-chunk-23-1.png and b/docs/articles/SW02_Forecasting_Multiple_Models_files/figure-html/unnamed-chunk-23-1.png differ diff --git a/docs/articles/SW02_Forecasting_Multiple_Models_files/figure-html/unnamed-chunk-6-1.png b/docs/articles/SW02_Forecasting_Multiple_Models_files/figure-html/unnamed-chunk-6-1.png index f92276e..4a4010e 100644 Binary files a/docs/articles/SW02_Forecasting_Multiple_Models_files/figure-html/unnamed-chunk-6-1.png and b/docs/articles/SW02_Forecasting_Multiple_Models_files/figure-html/unnamed-chunk-6-1.png differ diff --git a/docs/articles/SW02_Forecasting_Multiple_Models_files/figure-html/unnamed-chunk-8-1.png b/docs/articles/SW02_Forecasting_Multiple_Models_files/figure-html/unnamed-chunk-8-1.png index eb2261f..29f4495 100644 Binary files a/docs/articles/SW02_Forecasting_Multiple_Models_files/figure-html/unnamed-chunk-8-1.png and b/docs/articles/SW02_Forecasting_Multiple_Models_files/figure-html/unnamed-chunk-8-1.png differ diff --git a/docs/articles/index.html b/docs/articles/index.html index d182b83..bcca420 100644 --- a/docs/articles/index.html +++ b/docs/articles/index.html @@ -1,74 +1,60 @@ -Articles • sweepArticles • sweep + gtag('config', 'G-20GDZ5LL77'); + + Skip to contents -
    -
    -
    - +
    +
    +
    @@ -82,23 +68,21 @@

    All vignettes

    Forecasting Using Multiple Models
    -
    -
    +
    -
    +
    - diff --git a/docs/authors.html b/docs/authors.html index 69ccbd6..1a34fd2 100644 --- a/docs/authors.html +++ b/docs/authors.html @@ -1,77 +1,64 @@ -Authors and Citation • sweepAuthors and Citation • sweep + gtag('config', 'G-20GDZ5LL77'); + + Skip to contents -
    -
    -
    -
    - + +
    +
    +
    +
    +
    +

    Authors

    • Matt Dancho. Author, maintainer. @@ -82,45 +69,38 @@

      Authors

    -
    -
    -

    Citation

    - Source: DESCRIPTION -
    -
    +
    +

    Citation

    +

    Source: DESCRIPTION

    -

    Dancho M, Vaughan D (2023). +

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

    -
    @Manual{,
    +      
    @Manual{,
       title = {sweep: Tidy Tools for Forecasting},
       author = {Matt Dancho and Davis Vaughan},
       year = {2023},
    -  note = {R package version 0.2.5},
    -  url = {https://github.com/business-science/sweep},
    +  note = {https://business-science.github.io/sweep/, https://github.com/business-science/sweep},
     }
    - -
    - -
    - +
    +
    -
    +
    - diff --git a/docs/index.html b/docs/index.html index 7e89ca0..bda55f7 100644 --- a/docs/index.html +++ b/docs/index.html @@ -4,14 +4,27 @@ - + + Tidy Tools for Forecasting • sweep - - - + + + + + + + + + - - + + + - + + Skip to contents -
    -
    -
    -
    - - -

    Extending broom to time series forecasting

    + +

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

    Benefits

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

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

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

    @@ -345,10 +343,7 @@

    Further Information - -

    - diff --git a/docs/news/index.html b/docs/news/index.html index 9686abb..feac0bb 100644 --- a/docs/news/index.html +++ b/docs/news/index.html @@ -1,130 +1,115 @@ -Changelog • sweepChangelog • sweep + gtag('config', 'G-20GDZ5LL77'); + + Skip to contents -
    -
    -
    - +
    +
    +
    - +

    sweep (development version)

    +
    +
    +

    sweep 0.2.5

    CRAN release: 2023-07-06

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

    sweep 0.2.4

    • Remove support for robets.
    - +

    sweep 0.2.3

    CRAN release: 2020-07-10

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

    sweep 0.2.2

    CRAN release: 2019-10-08

    • Fixes for compatability with tidyquant v0.5.7
    - +

    sweep 0.2.1

    CRAN release: 2018-03-03

    - +

    sweep 0.2.0

    CRAN release: 2017-07-26

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

    sweep 0.1.0

    CRAN release: 2017-07-03

    • Initial release of sweep, a tool to “tidy” the forecast modeling and prediction workflow.
    -
    +
    - -
    - - -
    +
    - diff --git a/docs/pkgdown.js b/docs/pkgdown.js index 6f0eee4..5fccd9c 100644 --- a/docs/pkgdown.js +++ b/docs/pkgdown.js @@ -2,70 +2,30 @@ (function($) { $(function() { - $('.navbar-fixed-top').headroom(); + $('nav.navbar').headroom(); - $('body').css('padding-top', $('.navbar').height() + 10); - $(window).resize(function(){ - $('body').css('padding-top', $('.navbar').height() + 10); + Toc.init({ + $nav: $("#toc"), + $scope: $("main h2, main h3, main h4, main h5, main h6") }); - $('[data-toggle="tooltip"]').tooltip(); - - var cur_path = paths(location.pathname); - var links = $("#navbar ul li a"); - var max_length = -1; - var pos = -1; - for (var i = 0; i < links.length; i++) { - if (links[i].getAttribute("href") === "#") - continue; - // Ignore external links - if (links[i].host !== location.host) - continue; - - var nav_path = paths(links[i].pathname); - - var length = prefix_length(nav_path, cur_path); - if (length > max_length) { - max_length = length; - pos = i; - } - } - - // Add class to parent
  • , and enclosing
  • if in dropdown - if (pos >= 0) { - var menu_anchor = $(links[pos]); - menu_anchor.parent().addClass("active"); - menu_anchor.closest("li.dropdown").addClass("active"); - } - }); - - function paths(pathname) { - var pieces = pathname.split("/"); - pieces.shift(); // always starts with / - - var end = pieces[pieces.length - 1]; - if (end === "index.html" || end === "") - pieces.pop(); - return(pieces); - } - - // Returns -1 if not found - function prefix_length(needle, haystack) { - if (needle.length > haystack.length) - return(-1); - - // Special case for length-0 haystack, since for loop won't run - if (haystack.length === 0) { - return(needle.length === 0 ? 0 : -1); + if ($('#toc').length) { + $('body').scrollspy({ + target: '#toc', + offset: $("nav.navbar").outerHeight() + 1 + }); } - for (var i = 0; i < haystack.length; i++) { - if (needle[i] != haystack[i]) - return(i); - } + // Activate popovers + $('[data-bs-toggle="popover"]').popover({ + container: 'body', + html: true, + trigger: 'focus', + placement: "top", + sanitize: false, + }); - return(haystack.length); - } + $('[data-bs-toggle="tooltip"]').tooltip(); /* Clipboard --------------------------*/ @@ -78,7 +38,7 @@ if(ClipboardJS.isSupported()) { $(document).ready(function() { - var copyButton = ""; + var copyButton = ""; $("div.sourceCode").addClass("hasCopyButton"); @@ -89,20 +49,108 @@ $('.btn-copy-ex').tooltip({container: 'body'}); // Initialize clipboard: - var clipboardBtnCopies = new ClipboardJS('[data-clipboard-copy]', { + var clipboard = new ClipboardJS('[data-clipboard-copy]', { text: function(trigger) { return trigger.parentNode.textContent.replace(/\n#>[^\n]*/g, ""); } }); - clipboardBtnCopies.on('success', function(e) { + clipboard.on('success', function(e) { changeTooltipMessage(e.trigger, 'Copied!'); e.clearSelection(); }); - clipboardBtnCopies.on('error', function() { + clipboard.on('error', function() { changeTooltipMessage(e.trigger,'Press Ctrl+C or Command+C to copy'); }); + }); } + + /* Search marking --------------------------*/ + var url = new URL(window.location.href); + var toMark = url.searchParams.get("q"); + var mark = new Mark("main#main"); + if (toMark) { + mark.mark(toMark, { + accuracy: { + value: "complementary", + limiters: [",", ".", ":", "/"], + } + }); + } + + /* Search --------------------------*/ + /* Adapted from https://github.com/rstudio/bookdown/blob/2d692ba4b61f1e466c92e78fd712b0ab08c11d31/inst/resources/bs4_book/bs4_book.js#L25 */ + // Initialise search index on focus + var fuse; + $("#search-input").focus(async function(e) { + if (fuse) { + return; + } + + $(e.target).addClass("loading"); + var response = await fetch($("#search-input").data("search-index")); + var data = await response.json(); + + var options = { + keys: ["what", "text", "code"], + ignoreLocation: true, + threshold: 0.1, + includeMatches: true, + includeScore: true, + }; + fuse = new Fuse(data, options); + + $(e.target).removeClass("loading"); + }); + + // Use algolia autocomplete + var options = { + autoselect: true, + debug: true, + hint: false, + minLength: 2, + }; + var q; +async function searchFuse(query, callback) { + await fuse; + + var items; + if (!fuse) { + items = []; + } else { + q = query; + var results = fuse.search(query, { limit: 20 }); + items = results + .filter((x) => x.score <= 0.75) + .map((x) => x.item); + if (items.length === 0) { + items = [{dir:"Sorry 😿",previous_headings:"",title:"No results found.",what:"No results found.",path:window.location.href}]; + } + } + callback(items); +} + $("#search-input").autocomplete(options, [ + { + name: "content", + source: searchFuse, + templates: { + suggestion: (s) => { + if (s.title == s.what) { + return `${s.dir} >
    ${s.title}
    `; + } else if (s.previous_headings == "") { + return `${s.dir} >
    ${s.title}
    > ${s.what}`; + } else { + return `${s.dir} >
    ${s.title}
    > ${s.previous_headings} > ${s.what}`; + } + }, + }, + }, + ]).on('autocomplete:selected', function(event, s) { + window.location.href = s.path + "?q=" + q + "#" + s.id; + }); + }); })(window.jQuery || window.$) + + diff --git a/docs/pkgdown.yml b/docs/pkgdown.yml index f6628ab..d2e4b7c 100644 --- a/docs/pkgdown.yml +++ b/docs/pkgdown.yml @@ -1,9 +1,12 @@ pandoc: 3.1.1 -pkgdown: 2.0.6 +pkgdown: 2.0.7 pkgdown_sha: ~ articles: SW00_Introduction_to_sweep: SW00_Introduction_to_sweep.html SW01_Forecasting_Time_Series_Groups: SW01_Forecasting_Time_Series_Groups.html SW02_Forecasting_Multiple_Models: SW02_Forecasting_Multiple_Models.html -last_built: 2023-07-04T12:58Z +last_built: 2023-12-08T16:49Z +urls: + reference: https://business-science.github.io/sweep/reference + article: https://business-science.github.io/sweep/articles diff --git a/docs/reference/add_index.html b/docs/reference/add_index.html index 7861244..ca18bbd 100644 --- a/docs/reference/add_index.html +++ b/docs/reference/add_index.html @@ -1,88 +1,75 @@ -Adds a sequential index column to a data frame — add_index • sweepAdds a sequential index column to a data frame — add_index • sweep + gtag('config', 'G-20GDZ5LL77'); + + Skip to contents -
    -
    -
    - + + +
    +
    +
    +
    -
    +

    Adds a sequential index column to a data frame

    -
    +
    +

    Usage

    add_index(ret, rename_index)
    -
    -

    Arguments

    +
    +

    Arguments

    ret

    An object of class tibble

    @@ -93,26 +80,22 @@

    Arguments

    -
    - -
    +
    -
    +
    - diff --git a/docs/reference/arima_string.html b/docs/reference/arima_string.html index 05d21bb..52c57e2 100644 --- a/docs/reference/arima_string.html +++ b/docs/reference/arima_string.html @@ -1,90 +1,78 @@ -Print the ARIMA model parameters — arima_string • sweepPrint the ARIMA model parameters — arima_string • sweep + gtag('config', 'G-20GDZ5LL77'); + + Skip to contents -
    -
    -
    - + + +
    +
    +
    +
    -
    +

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

    -
    +
    +

    Usage

    arima_string(object, padding = FALSE)
    -
    -

    Arguments

    +
    +

    Arguments

    object

    An object of class Arima

    @@ -94,26 +82,22 @@

    Arguments

    -
    - -
    +
    -
    +
    - diff --git a/docs/reference/bats_string.html b/docs/reference/bats_string.html index 58e9293..00d283a 100644 --- a/docs/reference/bats_string.html +++ b/docs/reference/bats_string.html @@ -1,115 +1,99 @@ -Print the BATS model parameters — bats_string • sweepPrint the BATS model parameters — bats_string • sweep + gtag('config', 'G-20GDZ5LL77'); + + Skip to contents -
    -
    -
    - + + +
    +
    +
    +
    -
    +

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

    -
    +
    +

    Usage

    bats_string(object)
    -
    -

    Arguments

    +
    +

    Arguments

    object

    An object of class bats

    -
    - -
    +
    -
    +
    - diff --git a/docs/reference/bike_sales.html b/docs/reference/bike_sales.html index 3845e43..eb8688e 100644 --- a/docs/reference/bike_sales.html +++ b/docs/reference/bike_sales.html @@ -1,86 +1,79 @@ -Fictional sales data for bike shops purchasing Cannondale bikes — bike_sales • sweep + gtag('config', 'G-20GDZ5LL77'); + + Skip to contents -
    -
    -
    - + + +
    +
    +
    +
    -
    +

    A dataset containing the fictional bicycle orders spanning 2011 through 2015. Hypothetically, the bike_sales data are similar to sales data mainatained in a business' sales data base. The unit price and model names come from @@ -91,12 +84,13 @@

    Fictional sales data for bike shops purchasing Cannondale bikes

    (e.g. forecast, clustering, etc) to identify underlying trends.

    -
    +
    +

    Usage

    bike_sales
    -
    -

    Format

    +
    +

    Format

    A data frame with 15644 rows and 17 variables:

    order.date

    Date the order was placed

    @@ -150,31 +144,27 @@

    Format

    -
    -

    Source

    +
    +

    Source

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

    -
    - -
    +
    -
    +
    - diff --git a/docs/reference/index.html b/docs/reference/index.html index 30b6dde..98beab1 100644 --- a/docs/reference/index.html +++ b/docs/reference/index.html @@ -1,200 +1,207 @@ -Function reference • sweepFunction reference • sweep + gtag('config', 'G-20GDZ5LL77'); + + Skip to contents -
    -
    -
    - +
    +
    +
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -

    All functions

    -

    -
    -

    add_index()

    -

    Adds a sequential index column to a data frame

    -

    arima_string()

    -

    Print the ARIMA model parameters

    -

    bats_string()

    -

    Print the BATS model parameters

    -

    bike_sales

    -

    Fictional sales data for bike shops purchasing Cannondale bikes

    -

    sweep_package

    -

    sweep: Extending broom to time series forecasting

    -

    sw_augment(<default>)

    -

    Default augment method

    -

    sw_augment()

    -

    Augment data according to a tidied model

    -

    sw_augment_columns()

    -

    Augments data

    -

    sw_glance(<default>)

    -

    Default glance method

    -

    sw_glance()

    -

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

    -

    sw_sweep()

    -

    Tidy forecast objects

    -

    sw_tidy(<default>)

    -

    Default tidying method

    -

    sw_tidy()

    -

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

    -

    sw_tidy_decomp()

    -

    Coerces decomposed time-series objects to tibble format.

    -

    tbats_string()

    -

    Print the TBATS model parameters

    -

    sw_tidy(<Arima>) sw_glance(<Arima>) sw_augment(<Arima>) sw_tidy(<stlm>)

    -

    Tidying methods for ARIMA modeling of time series

    -

    sw_tidy(<bats>) sw_glance(<bats>) sw_augment(<bats>) sw_tidy_decomp(<bats>)

    -

    Tidying methods for BATS and TBATS modeling of time series

    -

    sw_tidy_decomp(<decomposed.ts>)

    -

    Tidying methods for decomposed time series

    -

    sw_tidy(<ets>) sw_glance(<ets>) sw_augment(<ets>) sw_tidy_decomp(<ets>)

    -

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

    -

    sw_tidy(<HoltWinters>) sw_glance(<HoltWinters>) sw_augment(<HoltWinters>) sw_tidy_decomp(<HoltWinters>)

    -

    Tidying methods for HoltWinters modeling of time series

    -

    sw_tidy(<nnetar>) sw_glance(<nnetar>) sw_augment(<nnetar>)

    -

    Tidying methods for Nural Network Time Series models

    -

    sw_tidy(<stl>) sw_tidy_decomp(<stl>) sw_tidy_decomp(<stlm>) sw_glance(<stlm>) sw_augment(<stlm>)

    -

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

    -

    sw_tidy(<StructTS>) sw_glance(<StructTS>) sw_augment(<StructTS>)

    -

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

    -

    validate_index()

    -

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

    - - -
    +
    +

    All functions

    + + + +
    + + + -
    + + +
    -
    -

    Site built with pkgdown 2.0.6.

    + -
    +
    - diff --git a/docs/reference/reexports.html b/docs/reference/reexports.html index 01f14a4..e3d5bb0 100644 --- a/docs/reference/reexports.html +++ b/docs/reference/reexports.html @@ -1,86 +1,79 @@ -Objects exported from other packages — reexports • sweep + gtag('config', 'G-20GDZ5LL77'); + + Skip to contents -
    -
    -
    - + + +
    +
    +
    +
    -
    +

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

    dplyr
    @@ -91,26 +84,21 @@

    Objects exported from other packages

    -
    - -
    +
    -
    +
    - diff --git a/docs/reference/sw_augment.default.html b/docs/reference/sw_augment.default.html index 896053c..245ae42 100644 --- a/docs/reference/sw_augment.default.html +++ b/docs/reference/sw_augment.default.html @@ -1,89 +1,76 @@ -Default augment method — sw_augment.default • sweepDefault augment method — sw_augment.default • sweep + gtag('config', 'G-20GDZ5LL77'); + + Skip to contents -
    -
    -
    - + + +
    +
    +
    +
    -
    +

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

    -
    +
    +

    Usage

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

    Arguments

    +
    +

    Arguments

    x

    an object to be tidied

    @@ -92,8 +79,8 @@

    Arguments

    extra arguments passed to broom::augment()

    -
    -

    Value

    +
    +

    Value

    A tibble generated by broom::augment()

    @@ -101,26 +88,22 @@

    Value

    -
    - -
    +
    -
    +
    - diff --git a/docs/reference/sw_augment.html b/docs/reference/sw_augment.html index 7639033..a5f426e 100644 --- a/docs/reference/sw_augment.html +++ b/docs/reference/sw_augment.html @@ -1,90 +1,78 @@ -Augment data according to a tidied model — sw_augment • sweepAugment data according to a tidied model — sw_augment • sweep + gtag('config', 'G-20GDZ5LL77'); + + Skip to contents -
    -
    -
    - + + +
    +
    +
    +
    -
    +

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

    -
    +
    +

    Usage

    sw_augment(x, ...)
    -
    -

    Arguments

    +
    +

    Arguments

    x

    model or other R object to convert to data frame

    @@ -93,8 +81,8 @@

    Arguments

    other arguments passed to methods

    -
    -

    Details

    +
    +

    Details

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

    @@ -105,31 +93,27 @@

    Details

    signature, partly because it prevents rowwise_df_tidiers from taking a column name as the first argument.

    -
    -

    See also

    +
    +

    See also

    -
    - -
    +
    -
    +
    - diff --git a/docs/reference/sw_augment_columns.html b/docs/reference/sw_augment_columns.html index f6b6088..a9a677b 100644 --- a/docs/reference/sw_augment_columns.html +++ b/docs/reference/sw_augment_columns.html @@ -1,88 +1,75 @@ -Augments data — sw_augment_columns • sweepAugments data — sw_augment_columns • sweep + gtag('config', 'G-20GDZ5LL77'); + + Skip to contents -
    -
    -
    - + + +
    +
    +
    +
    -
    +

    Augments data

    -
    +
    +

    Usage

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

    Arguments

    +
    +

    Arguments

    ret

    An object of class tibble

    @@ -101,26 +88,22 @@

    Arguments

    -
    - -
    +
    -
    +
    - diff --git a/docs/reference/sw_glance.default.html b/docs/reference/sw_glance.default.html index 3695f0c..6528d55 100644 --- a/docs/reference/sw_glance.default.html +++ b/docs/reference/sw_glance.default.html @@ -1,89 +1,76 @@ -Default glance method — sw_glance.default • sweepDefault glance method — sw_glance.default • sweep + gtag('config', 'G-20GDZ5LL77'); + + Skip to contents -
    -
    -
    - + + +
    +
    +
    +
    -
    +

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

    -
    +
    +

    Usage

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

    Arguments

    +
    +

    Arguments

    x

    an object to be tidied

    @@ -92,8 +79,8 @@

    Arguments

    extra arguments passed to broom::glance()

    -
    -

    Value

    +
    +

    Value

    A tibble generated by broom::glance()

    @@ -101,26 +88,22 @@

    Value

    -
    - -
    +
    -
    +
    - diff --git a/docs/reference/sw_glance.html b/docs/reference/sw_glance.html index 44625d3..4d48761 100644 --- a/docs/reference/sw_glance.html +++ b/docs/reference/sw_glance.html @@ -1,92 +1,80 @@ -Construct a single row summary "glance" of a model, fit, or other -object — sw_glance • sweepConstruct a single row summary "glance" of a model, fit, or other +object — sw_glance • sweep + gtag('config', 'G-20GDZ5LL77'); + + Skip to contents -
    -
    -
    - +
    +
    +
    -
    +

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

    -
    +
    +

    Usage

    sw_glance(x, ...)
    -
    -

    Arguments

    +
    +

    Arguments

    x

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

    @@ -95,14 +83,14 @@

    Arguments

    other arguments passed to methods

    -
    -

    Value

    +
    +

    Value

    single-row tibble with model summary information.

    -
    -

    Details

    +
    +

    Details

    sw_glance() is a wrapper for broom::glance(). The benefit of sw_glance is that it has methods for various time-series model classes such as HoltWinters, ets, Arima, etc. @@ -112,31 +100,27 @@

    Details

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

    -
    -

    See also

    +
    +

    See also

    -
    - -
    +
    -
    +
    - diff --git a/docs/reference/sw_sweep.html b/docs/reference/sw_sweep.html index 6e14d44..51b83e3 100644 --- a/docs/reference/sw_sweep.html +++ b/docs/reference/sw_sweep.html @@ -1,88 +1,75 @@ -Tidy forecast objects — sw_sweep • sweepTidy forecast objects — sw_sweep • sweep + gtag('config', 'G-20GDZ5LL77'); + + Skip to contents -
    -
    -
    - + + +
    +
    +
    +
    -
    +

    Tidy forecast objects

    -
    +
    +

    Usage

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

    Arguments

    +
    +

    Arguments

    x

    A time-series forecast of class forecast.

    @@ -105,14 +92,14 @@

    Arguments

    Additional arguments passed to tk_make_future_timeseries()

    -
    -

    Value

    +
    +

    Value

    Returns a tibble object.

    -
    -

    Details

    +
    +

    Details

    sw_sweep is designed to coerce forecast objects from the forecast package into tibble objects in a "tidy" format (long). @@ -131,35 +118,33 @@

    Details

    that can be useful in tuning the future time series sequence.

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

    -
    -

    See also

    +
    +

    See also

    tk_make_future_timeseries()

    -
    -

    Examples

    +
    +

    Examples

    library(forecast)
    -#> Warning: package 'forecast' was built under R version 4.0.5
     #> Registered S3 method overwritten by 'quantmod':
     #>   method            from
     #>   as.zoo.data.frame zoo 
    -library(sweep)
     library(dplyr)
     #> 
    -#> Attaching package: 'dplyr'
    -#> The following objects are masked from 'package:stats':
    +#> Attaching package: ‘dplyr’
    +#> The following objects are masked from ‘package:stats’:
     #> 
     #>     filter, lag
    -#> The following objects are masked from 'package:base':
    +#> The following objects are masked from ‘package:base’:
     #> 
     #>     intersect, setdiff, setequal, union
     
     # ETS forecasts
     USAccDeaths %>%
         ets() %>%
    -    forecast(level = c(80, 95, 99)) %>%
    +    forecast(level = c(80, 95, 99)) %>%
         sw_sweep()
    -#> # A tibble: 96 x 9
    +#> # A tibble: 96 × 9
     #>    index     key    value lo.80 lo.95 lo.99 hi.80 hi.95 hi.99
     #>    <yearmon> <chr>  <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
     #>  1 Jan 1973  actual  9007    NA    NA    NA    NA    NA    NA
    @@ -172,31 +157,27 @@ 

    Examples

    #> 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 -#> # i 86 more rows +#> # ℹ 86 more rows
    -
    - -
    +

    -
    +

    - diff --git a/docs/reference/sw_tidy.default.html b/docs/reference/sw_tidy.default.html index b9172ea..1da3195 100644 --- a/docs/reference/sw_tidy.default.html +++ b/docs/reference/sw_tidy.default.html @@ -1,89 +1,76 @@ -Default tidying method — sw_tidy.default • sweepDefault tidying method — sw_tidy.default • sweep + gtag('config', 'G-20GDZ5LL77'); + + Skip to contents -
    -
    -
    - + + +
    +
    +
    +
    -
    +

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

    -
    +
    +

    Usage

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

    Arguments

    +
    +

    Arguments

    x

    an object to be tidied

    @@ -92,8 +79,8 @@

    Arguments

    extra arguments passed to broom::tidy()

    -
    -

    Value

    +
    +

    Value

    A tibble generated by broom::tidy()

    @@ -101,26 +88,22 @@

    Value

    -
    - -
    +
    -
    +
    - diff --git a/docs/reference/sw_tidy.html b/docs/reference/sw_tidy.html index a953d05..0991f46 100644 --- a/docs/reference/sw_tidy.html +++ b/docs/reference/sw_tidy.html @@ -1,88 +1,75 @@ -Tidy the result of a time-series model into a summary tibble — sw_tidy • sweepTidy the result of a time-series model into a summary tibble — sw_tidy • sweep + gtag('config', 'G-20GDZ5LL77'); + + Skip to contents -
    -
    -
    - + + +
    +
    +
    +
    -
    +

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

    -
    +
    +

    Usage

    sw_tidy(x, ...)
    -
    -

    Arguments

    +
    +

    Arguments

    x

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

    @@ -91,14 +78,14 @@

    Arguments

    extra arguments

    -
    -

    Value

    +
    +

    Value

    a tibble

    -
    -

    Details

    +
    +

    Details

    sw_tidy() is a wrapper for broom::tidy(). The main benefit of sw_tidy() is that it has methods for various time-series model classes such as HoltWinters, ets, Arima, etc. @@ -109,21 +96,20 @@

    Details

    therefore suited for further manipulation by packages like dplyr and ggplot2.

    -
    -

    See also

    +
    +

    See also

    -
    -

    Examples

    +
    +

    Examples

    library(dplyr)
     library(forecast)
    -library(sweep)
     
     WWWusage %>%
         auto.arima() %>%
         sw_tidy(conf.int = TRUE)
    -#> # A tibble: 2 x 2
    +#> # A tibble: 2 × 2
     #>   term  estimate
     #>   <chr>    <dbl>
     #> 1 ar1      0.650
    @@ -131,26 +117,22 @@ 

    Examples

    -
    - -
    +
    -
    +
    - diff --git a/docs/reference/sw_tidy_decomp.html b/docs/reference/sw_tidy_decomp.html index 893a373..1b49e9d 100644 --- a/docs/reference/sw_tidy_decomp.html +++ b/docs/reference/sw_tidy_decomp.html @@ -1,88 +1,75 @@ -Coerces decomposed time-series objects to tibble format. — sw_tidy_decomp • sweepCoerces decomposed time-series objects to tibble format. — sw_tidy_decomp • sweep + gtag('config', 'G-20GDZ5LL77'); + + Skip to contents -
    -
    -
    - + + +
    +
    +
    +
    -
    +

    Coerces decomposed time-series objects to tibble format.

    -
    +
    +

    Usage

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

    Arguments

    +
    +

    Arguments

    x

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

    @@ -100,14 +87,14 @@

    Arguments

    Not used.

    -
    -

    Value

    +
    +

    Value

    Returns a tibble object.

    -
    -

    Details

    +
    +

    Details

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

    A regularized time index is always constructed. If no time index is @@ -115,17 +102,17 @@

    Details

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

    -
    -

    Examples

    +
    +

    Examples

    library(dplyr)
     library(forecast)
    -library(sweep)
    +library(sweep)
     
     # Decompose ETS model
     USAccDeaths %>%
         ets() %>%
         sw_tidy_decomp()
    -#> # A tibble: 73 x 4
    +#> # A tibble: 73 × 4
     #>    index     observed level  season
     #>    <yearmon>    <dbl> <dbl>   <dbl>
     #>  1 Dec 1972        NA 9248.   -51.3
    @@ -138,13 +125,13 @@ 

    Examples

    #> 8 Jul 1973 11317 9746. 1683. #> 9 Aug 1973 10744 9762. 971. #> 10 Sep 1973 9713 9805. -122. -#> # i 63 more rows +#> # ℹ 63 more rows # Decompose STL object USAccDeaths %>% stl(s.window = 'periodic') %>% sw_tidy_decomp() -#> # A tibble: 72 x 6 +#> # A tibble: 72 × 6 #> index observed season trend remainder seasadj #> <yearmon> <dbl> <dbl> <dbl> <dbl> <dbl> #> 1 Jan 1973 9007 -820. 9935. -108. 9827. @@ -157,31 +144,27 @@

    Examples

    #> 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. -#> # i 62 more rows +#> # ℹ 62 more rows
    -
    - -
    +
    -
    +
    - diff --git a/docs/reference/tbats_string.html b/docs/reference/tbats_string.html index 2ef3b54..001c3d2 100644 --- a/docs/reference/tbats_string.html +++ b/docs/reference/tbats_string.html @@ -1,115 +1,99 @@ -Print the TBATS model parameters — tbats_string • sweepPrint the TBATS model parameters — tbats_string • sweep + gtag('config', 'G-20GDZ5LL77'); + + Skip to contents -
    -
    -
    - + + +
    +
    +
    +
    -
    +

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

    -
    +
    +

    Usage

    tbats_string(object)
    -
    -

    Arguments

    +
    +

    Arguments

    object

    An object of class bats or tbats

    -
    - -
    +
    -
    +
    - diff --git a/docs/reference/tidiers_HoltWinters.html b/docs/reference/tidiers_HoltWinters.html index 47c3d57..609dade 100644 --- a/docs/reference/tidiers_HoltWinters.html +++ b/docs/reference/tidiers_HoltWinters.html @@ -1,85 +1,73 @@ -Tidying methods for HoltWinters modeling of time series — tidiers_HoltWinters • sweepTidying methods for HoltWinters modeling of time series — tidiers_HoltWinters • sweep + gtag('config', 'G-20GDZ5LL77'); + + Skip to contents -
    -
    -
    - + + +
    +
    +
    +
    -
    +

    These methods tidy HoltWinters models of univariate time series.

    -
    +
    +

    Usage

    # S3 method for HoltWinters
     sw_tidy(x, ...)
     
    @@ -93,8 +81,8 @@ 

    Tidying methods for HoltWinters modeling of time series

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

    Arguments

    +
    +

    Arguments

    x

    An object of class "HoltWinters"

    @@ -119,8 +107,8 @@

    Arguments

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

    -
    -

    Value

    +
    +

    Value

    sw_tidy() returns one row for each model parameter, @@ -151,22 +139,21 @@

    Value

  • remainder: observed - (season + trend)

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

  • -
    -

    See also

    +
    +

    See also

    -
    -

    Examples

    +
    +

    Examples

    library(dplyr)
     library(forecast)
    -library(sweep)
     
     fit_hw <- USAccDeaths %>%
         stats::HoltWinters()
     
     sw_tidy(fit_hw)
    -#> # A tibble: 17 x 2
    +#> # A tibble: 17 × 2
     #>    term    estimate
     #>    <chr>      <dbl>
     #>  1 alpha     0.738 
    @@ -187,12 +174,12 @@ 

    Examples

    #> 16 s11 128. #> 17 s12 441. sw_glance(fit_hw) -#> # A tibble: 1 x 12 +#> # A tibble: 1 × 12 #> model.desc sigma logLik AIC BIC ME RMSE MAE MPE MAPE MASE ACF1 #> <chr> <dbl> <lgl> <lgl> <lgl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> -#> 1 HoltWinte~ 2939. NA NA NA 61.4 379. 274. 0.727 3.21 0.626 0.0569 +#> 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 x 4 +#> # A tibble: 72 × 4 #> index .actual .fitted .resid #> <yearmon> <dbl> <dbl> <dbl> #> 1 Jan 1973 9007 NA NA @@ -205,9 +192,9 @@

    Examples

    #> 8 Aug 1973 10744 NA NA #> 9 Sep 1973 9713 NA NA #> 10 Oct 1973 9938 NA NA -#> # i 62 more rows +#> # ℹ 62 more rows sw_tidy_decomp(fit_hw) -#> # A tibble: 72 x 6 +#> # A tibble: 72 × 6 #> index observed season trend remainder seasadj #> <yearmon> <dbl> <dbl> <dbl> <dbl> <dbl> #> 1 Jan 1973 9007 NA NA NA NA @@ -220,30 +207,26 @@

    Examples

    #> 8 Aug 1973 10744 NA NA NA NA #> 9 Sep 1973 9713 NA NA NA NA #> 10 Oct 1973 9938 NA NA NA NA -#> # i 62 more rows +#> # ℹ 62 more rows
    -
    - -
    +
    -
    +
    - diff --git a/docs/reference/tidiers_StructTS.html b/docs/reference/tidiers_StructTS.html index 5e968cc..53cc2a3 100644 --- a/docs/reference/tidiers_StructTS.html +++ b/docs/reference/tidiers_StructTS.html @@ -1,88 +1,76 @@ -Tidying methods for StructTS (Error, Trend, Seasonal) / exponential smoothing -modeling of time series — tidiers_StructTS • sweepTidying methods for StructTS (Error, Trend, Seasonal) / exponential smoothing +modeling of time series — tidiers_StructTS • sweep + gtag('config', 'G-20GDZ5LL77'); + + Skip to contents -
    -
    -
    - +
    +
    +
    -
    +

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

    -
    +
    +

    Usage

    # S3 method for StructTS
     sw_tidy(x, ...)
     
    @@ -93,8 +81,8 @@ 

    Tidying methods for StructTS (Error, Trend, Seasonal) / exponential smoothin sw_augment(x, data = NULL, timetk_idx = FALSE, rename_index = "index", ...)

    -
    -

    Arguments

    +
    +

    Arguments

    x

    An object of class "StructTS"

    @@ -119,8 +107,8 @@

    Arguments

    A string representing the name of the index generated.

    -
    -

    Value

    +
    +

    Value

    sw_tidy() returns one row for each model parameter, @@ -146,35 +134,34 @@

    Value

  • .fitted: The fitted values from the model

  • .resid: The residual values from the model

  • -
    -

    See also

    +
    +

    See also

    -
    -

    Examples

    +
    +

    Examples

    library(dplyr)
     library(forecast)
    -library(sweep)
     
     fit_StructTS <- WWWusage %>%
         StructTS()
     
     sw_tidy(fit_StructTS)
    -#> # A tibble: 3 x 2
    +#> # A tibble: 3 × 2
     #>   term    estimate
     #>   <chr>      <dbl>
     #> 1 level        0  
     #> 2 slope       13.0
     #> 3 epsilon      0  
     sw_glance(fit_StructTS)
    -#> # A tibble: 1 x 12
    +#> # A tibble: 1 × 12
     #>   model.desc      sigma logLik   AIC   BIC      ME  RMSE   MAE   MPE  MAPE  MASE
     #>   <chr>           <dbl>  <dbl> <dbl> <dbl>   <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
    -#> 1 Local linear s~ 0.995  -277.  559.  564. -0.0200  3.59  2.96 0.140  2.32 0.654
    -#> # i 1 more variable: ACF1 <dbl>
    +#> 1 Local linear s… 0.995  -277.  559.  564. -0.0200  3.59  2.96 0.140  2.32 0.654
    +#> # ℹ 1 more variable: ACF1 <dbl>
     sw_augment(fit_StructTS)
    -#> # A tibble: 100 x 4
    +#> # A tibble: 100 × 4
     #>    index .actual .fitted .resid
     #>    <int>   <dbl>   <dbl>  <dbl>
     #>  1     1      88    88     0   
    @@ -187,30 +174,26 @@ 

    Examples

    #> 8 8 85 81 4 #> 9 9 88 87 1 #> 10 10 89 91 -2 -#> # i 90 more rows +#> # ℹ 90 more rows
    -
    - -
    +
    -
    +
    - diff --git a/docs/reference/tidiers_arima.html b/docs/reference/tidiers_arima.html index 4333073..8c149d0 100644 --- a/docs/reference/tidiers_arima.html +++ b/docs/reference/tidiers_arima.html @@ -1,85 +1,73 @@ -Tidying methods for ARIMA modeling of time series — tidiers_arima • sweepTidying methods for ARIMA modeling of time series — tidiers_arima • sweep + gtag('config', 'G-20GDZ5LL77'); + + Skip to contents -
    -
    -
    - + + +
    +
    +
    +
    -
    +

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

    -
    +
    +

    Usage

    # S3 method for Arima
     sw_tidy(x, ...)
     
    @@ -93,8 +81,8 @@ 

    Tidying methods for ARIMA modeling of time series

    sw_tidy(x, ...)
    -
    -

    Arguments

    +
    +

    Arguments

    x

    An object of class "Arima"

    @@ -119,8 +107,8 @@

    Arguments

    Uses a irregular timetk index if present.

    -
    -

    Value

    +
    +

    Value

    sw_tidy() returns one row for each coefficient in the model, @@ -152,39 +140,33 @@

    Value

    with five columns:

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

    • estimate: The estimated coefficient

    -
    -

    See also

    +
    +

    See also

    -
    -

    Examples

    +
    +

    Examples

    library(dplyr)
     library(forecast)
    -library(sweep)
     
     fit_arima <- WWWusage %>%
         auto.arima()
     
     sw_tidy(fit_arima)
    -#> # A tibble: 2 x 2
    +#> # A tibble: 2 × 2
     #>   term  estimate
     #>   <chr>    <dbl>
     #> 1 ar1      0.650
     #> 2 ma1      0.526
     sw_glance(fit_arima)
    -#> # A tibble: 1 x 12
    +#> # A tibble: 1 × 12
     #>   model.desc   sigma logLik   AIC   BIC    ME  RMSE   MAE   MPE  MAPE  MASE
     #>   <chr>        <dbl>  <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
     #> 1 ARIMA(1,1,1)  3.16  -254.  514.  522. 0.304  3.11  2.41 0.281  1.92 0.532
    -#> # i 1 more variable: ACF1 <dbl>
    +#> # ℹ 1 more variable: ACF1 <dbl>
     sw_augment(fit_arima)
    -#> Warning: `select_()` was deprecated in dplyr 0.7.0.
    -#> i Please use `select()` instead.
    -#> i The deprecated feature was likely used in the sweep package.
    -#>   Please report the issue at
    -#>   <https://github.com/business-science/sweep/issues>.
    -#> # A tibble: 100 x 4
    +#> # A tibble: 100 × 4
     #>    index .actual .fitted  .resid
     #>    <int>   <dbl>   <dbl>   <dbl>
     #>  1     1      88    87.9  0.0880
    @@ -197,31 +179,27 @@ 

    Examples

    #> 8 8 85 79.9 5.11 #> 9 9 88 89.0 -0.985 #> 10 10 89 89.4 -0.433 -#> # i 90 more rows +#> # ℹ 90 more rows
    -
    - -
    +
    -
    +
    - diff --git a/docs/reference/tidiers_bats.html b/docs/reference/tidiers_bats.html index 14c6bbd..41110a7 100644 --- a/docs/reference/tidiers_bats.html +++ b/docs/reference/tidiers_bats.html @@ -1,83 +1,70 @@ -Tidying methods for BATS and TBATS modeling of time series — tidiers_bats • sweepTidying methods for BATS and TBATS modeling of time series — tidiers_bats • sweep + gtag('config', 'G-20GDZ5LL77'); + + Skip to contents -
    -
    -
    - + + +
    +
    +
    +
    -
    +

    Tidying methods for BATS and TBATS modeling of time series

    -
    +
    +

    Usage

    # S3 method for bats
     sw_tidy(x, ...)
     
    @@ -91,8 +78,8 @@ 

    Tidying methods for BATS and TBATS modeling of time series

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

    Arguments

    +
    +

    Arguments

    x

    An object of class "bats" or "tbats"

    @@ -117,8 +104,8 @@

    Arguments

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

    -
    -

    Value

    +
    +

    Value

    sw_tidy() returns one row for each model parameter, @@ -150,22 +137,21 @@

    Value

  • slope: The slope component (Not always present)

  • season: The seasonal component (Not always present)

  • -
    -

    See also

    +
    +

    See also

    -
    -

    Examples

    +
    +

    Examples

    library(dplyr)
     library(forecast)
    -library(sweep)
     
     fit_bats <- WWWusage %>%
         bats()
     
     sw_tidy(fit_bats)
    -#> # A tibble: 7 x 2
    +#> # A tibble: 7 × 2
     #>   term              estimate
     #>   <chr>                <dbl>
     #> 1 lambda               1.00 
    @@ -176,12 +162,12 @@ 

    Examples

    #> 6 ar.coefficients NA #> 7 ma.coefficients -0.666 sw_glance(fit_bats) -#> # A tibble: 1 x 12 +#> # A tibble: 1 × 12 #> model.desc sigma logLik AIC BIC ME RMSE MAE MPE MAPE MASE ACF1 #> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> -#> 1 BATS(1, {~ 3.47 709. 727. 732. 0.217 3.47 2.62 0.261 2.13 0.579 0.0445 +#> 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 x 4 +#> # A tibble: 100 × 4 #> index .actual .fitted .resid #> <int> <dbl> <dbl> <dbl> #> 1 1 88 101. -12.7 @@ -194,30 +180,26 @@

    Examples

    #> 8 8 85 80.2 4.78 #> 9 9 88 88.1 -0.125 #> 10 10 89 89.3 -0.284 -#> # i 90 more rows +#> # ℹ 90 more rows
    -
    - -
    +
    -
    +
    - diff --git a/docs/reference/tidiers_decomposed_ts.html b/docs/reference/tidiers_decomposed_ts.html index cb3a78f..ef68ff9 100644 --- a/docs/reference/tidiers_decomposed_ts.html +++ b/docs/reference/tidiers_decomposed_ts.html @@ -1,89 +1,76 @@ -Tidying methods for decomposed time series — tidiers_decomposed_ts • sweepTidying methods for decomposed time series — tidiers_decomposed_ts • sweep + gtag('config', 'G-20GDZ5LL77'); + + Skip to contents -
    -
    -
    - + + +
    +
    +
    +
    -
    +

    Tidying methods for decomposed time series

    -
    +
    +

    Usage

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

    Arguments

    +
    +

    Arguments

    x

    An object of class "decomposed.ts"

    @@ -102,8 +89,8 @@

    Arguments

    Not used.

    -
    -

    Value

    +
    +

    Value

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

    • index: An index is either attempted to be extracted from the model or @@ -113,22 +100,21 @@

      Value

    • random: The error component

    • seasadj: observed - season

    -
    -

    See also

    +
    +

    See also

    -
    -

    Examples

    +
    +

    Examples

    library(dplyr)
     library(forecast)
    -library(sweep)
     
     fit_decomposed <- USAccDeaths %>%
         decompose()
     
     sw_tidy_decomp(fit_decomposed)
    -#> # A tibble: 72 x 6
    +#> # A tibble: 72 × 6
     #>    index     observed season trend random seasadj
     #>    <yearmon>    <dbl>  <dbl> <dbl>  <dbl>   <dbl>
     #>  1 Jan 1973      9007  -806.   NA    NA     9813.
    @@ -141,30 +127,26 @@ 

    Examples

    #> 8 Aug 1973 10744 986. 9500. 258. 9758. #> 9 Sep 1973 9713 -109. 9416. 406. 9822. #> 10 Oct 1973 9938 264. 9349. 325. 9674. -#> # i 62 more rows +#> # ℹ 62 more rows
    -
    - -
    +
    -
    +
    - diff --git a/docs/reference/tidiers_ets.html b/docs/reference/tidiers_ets.html index d2b4edf..7513274 100644 --- a/docs/reference/tidiers_ets.html +++ b/docs/reference/tidiers_ets.html @@ -1,88 +1,76 @@ -Tidying methods for ETS (Error, Trend, Seasonal) exponential smoothing -modeling of time series — tidiers_ets • sweepTidying methods for ETS (Error, Trend, Seasonal) exponential smoothing +modeling of time series — tidiers_ets • sweep + gtag('config', 'G-20GDZ5LL77'); + + Skip to contents -
    -
    -
    - +
    +
    +
    -
    +

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

    -
    +
    +

    Usage

    # S3 method for ets
     sw_tidy(x, ...)
     
    @@ -96,8 +84,8 @@ 

    Tidying methods for ETS (Error, Trend, Seasonal) exponential smoothing sw_tidy_decomp(x, timetk_idx = FALSE, rename_index = "index", ...)

    -
    -

    Arguments

    +
    +

    Arguments

    x

    An object of class "ets"

    @@ -122,8 +110,8 @@

    Arguments

    A string representing the name of the index generated.

    -
    -

    Value

    +
    +

    Value

    sw_tidy() returns one row for each model parameter, @@ -156,22 +144,21 @@

    Value

  • slope: The slope component (Not always present)

  • season: The seasonal component (Not always present)

  • -
    -

    See also

    +
    +

    See also

    -
    -

    Examples

    +
    +

    Examples

    library(dplyr)
     library(forecast)
    -library(sweep)
     
     fit_ets <- WWWusage %>%
         ets()
     
     sw_tidy(fit_ets)
    -#> # A tibble: 5 x 2
    +#> # A tibble: 5 × 2
     #>   term  estimate
     #>   <chr>    <dbl>
     #> 1 alpha   1.00  
    @@ -180,12 +167,12 @@ 

    Examples

    #> 4 l 90.4 #> 5 b -0.0173 sw_glance(fit_ets) -#> # A tibble: 1 x 12 +#> # A tibble: 1 × 12 #> model.desc sigma logLik AIC BIC ME RMSE MAE MPE MAPE MASE ACF1 #> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> #> 1 ETS(A,Ad,N) 3.50 -353. 718. 733. 0.224 3.41 2.76 0.263 2.16 0.610 0.231 sw_augment(fit_ets) -#> # A tibble: 100 x 4 +#> # A tibble: 100 × 4 #> index .actual .fitted .resid #> <int> <dbl> <dbl> <dbl> #> 1 1 88 90.3 -2.34 @@ -198,9 +185,9 @@

    Examples

    #> 8 8 85 81.4 3.62 #> 9 9 88 86.6 1.38 #> 10 10 89 90.4 -1.44 -#> # i 90 more rows +#> # ℹ 90 more rows sw_tidy_decomp(fit_ets) -#> # A tibble: 101 x 4 +#> # A tibble: 101 × 4 #> index observed level slope #> <dbl> <dbl> <dbl> <dbl> #> 1 0 NA 90.4 -0.0173 @@ -213,30 +200,26 @@

    Examples

    #> 8 7 83 83.0 -1.99 #> 9 8 85 85.0 1.99 #> 10 9 88 88.0 3.00 -#> # i 91 more rows +#> # ℹ 91 more rows
    -
    - -
    +
    -
    +
    - diff --git a/docs/reference/tidiers_nnetar.html b/docs/reference/tidiers_nnetar.html index 7581120..936c9dc 100644 --- a/docs/reference/tidiers_nnetar.html +++ b/docs/reference/tidiers_nnetar.html @@ -1,85 +1,73 @@ -Tidying methods for Nural Network Time Series models — tidiers_nnetar • sweepTidying methods for Nural Network Time Series models — tidiers_nnetar • sweep + gtag('config', 'G-20GDZ5LL77'); + + Skip to contents -
    -
    -
    - + + +
    +
    +
    +
    -
    +

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

    -
    +
    +

    Usage

    # S3 method for nnetar
     sw_tidy(x, ...)
     
    @@ -90,8 +78,8 @@ 

    Tidying methods for Nural Network Time Series models

    sw_augment(x, data = NULL, timetk_idx = FALSE, rename_index = "index", ...)
    -
    -

    Arguments

    +
    +

    Arguments

    x

    An object of class "nnetar"

    @@ -116,8 +104,8 @@

    Arguments

    A string representing the name of the index generated.

    -
    -

    Value

    +
    +

    Value

    sw_tidy() returns one row for each model parameter, @@ -144,22 +132,21 @@

    Value

  • .fitted: The fitted values from the model

  • .resid: The residual values from the model

  • -
    -

    See also

    +
    +

    See also

    -
    -

    Examples

    +
    +

    Examples

    library(dplyr)
     library(forecast)
    -library(sweep)
     
     fit_nnetar <- lynx %>%
         nnetar()
     
     sw_tidy(fit_nnetar)
    -#> # A tibble: 4 x 2
    +#> # A tibble: 4 × 2
     #>   term  estimate
     #>   <chr>    <dbl>
     #> 1 m            1
    @@ -167,12 +154,13 @@ 

    Examples

    #> 3 P 0 #> 4 size 4 sw_glance(fit_nnetar) -#> # A tibble: 1 x 12 -#> model.desc sigma logLik AIC BIC ME RMSE MAE MPE MAPE MASE ACF1 -#> <chr> <dbl> <lgl> <lgl> <lgl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> -#> 1 NNAR(8,4) 294. NA NA NA 0.127 294. 216. -40.4 54.1 0.260 0.0290 +#> # 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) 301. NA NA NA -0.893 301. 217. -35.3 49.3 0.261 +#> # ℹ 1 more variable: ACF1 <dbl> sw_augment(fit_nnetar) -#> # A tibble: 114 x 4 +#> # A tibble: 114 × 4 #> index .actual .fitted .resid #> <dbl> <dbl> <dbl> <dbl> #> 1 1821 269 NA NA @@ -183,32 +171,28 @@

    Examples

    #> 6 1826 2821 NA NA #> 7 1827 3928 NA NA #> 8 1828 5943 NA NA -#> 9 1829 4950 4560. 390. -#> 10 1830 2577 2549. 28.4 -#> # i 104 more rows +#> 9 1829 4950 4558. 392. +#> 10 1830 2577 2516. 61.3 +#> # ℹ 104 more rows
    -
    - -
    +
    -
    +
    - diff --git a/docs/reference/tidiers_stl.html b/docs/reference/tidiers_stl.html index b86f9cd..7927294 100644 --- a/docs/reference/tidiers_stl.html +++ b/docs/reference/tidiers_stl.html @@ -1,83 +1,70 @@ -Tidying methods for STL (Seasonal, Trend, Level) decomposition of time series — tidiers_stl • sweepTidying methods for STL (Seasonal, Trend, Level) decomposition of time series — tidiers_stl • sweep + gtag('config', 'G-20GDZ5LL77'); + + Skip to contents -
    -
    -
    - + + +
    +
    +
    +
    -
    +

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

    -
    +
    +

    Usage

    # S3 method for stl
     sw_tidy(x, ...)
     
    @@ -94,8 +81,8 @@ 

    Tidying methods for STL (Seasonal, Trend, Level) decomposition of time serie sw_augment(x, data = NULL, rename_index = "index", timetk_idx = FALSE, ...)

    -
    -

    Arguments

    +
    +

    Arguments

    x

    An object of class "stl"

    @@ -118,8 +105,8 @@

    Arguments

    Used with sw_augment only.

    -
    -

    Value

    +
    +

    Value

    sw_tidy() wraps sw_tidy_decomp()

    @@ -152,22 +139,22 @@

    Value

  • .fitted: The fitted values from the model

  • .resid: The residual values from the model

  • -
    -

    See also

    +
    +

    See also

    -
    -

    Examples

    +
    +

    Examples

    library(dplyr)
     library(forecast)
    -library(sweep)
    +library(sweep)
     
     fit_stl <- USAccDeaths %>%
         stl(s.window = "periodic")
     
     sw_tidy_decomp(fit_stl)
    -#> # A tibble: 72 x 6
    +#> # A tibble: 72 × 6
     #>    index     observed  season trend remainder seasadj
     #>    <yearmon>    <dbl>   <dbl> <dbl>     <dbl>   <dbl>
     #>  1 Jan 1973      9007  -820.  9935.    -108.    9827.
    @@ -180,30 +167,26 @@ 

    Examples

    #> 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. -#> # i 62 more rows +#> # ℹ 62 more rows
    -
    - -
    +
    -
    +
    - diff --git a/docs/reference/validate_index.html b/docs/reference/validate_index.html index bb290a2..5f1c042 100644 --- a/docs/reference/validate_index.html +++ b/docs/reference/validate_index.html @@ -1,88 +1,75 @@ -Validates data frame has column named the same name as variable rename_index — validate_index • sweepValidates data frame has column named the same name as variable rename_index — validate_index • sweep + gtag('config', 'G-20GDZ5LL77'); + + Skip to contents -
    -
    -
    - + + +
    +
    +
    +
    -
    +

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

    -
    +
    +

    Usage

    validate_index(ret, rename_index)
    -
    -

    Arguments

    +
    +

    Arguments

    ret

    An object of class tibble

    @@ -93,26 +80,22 @@

    Arguments

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