Time Series 002

## -- Attaching packages ------------------------------------------------------------------------------------ tidyverse 1.2.1 --
## v ggplot2 3.1.0     v purrr   0.3.2
## v tibble  2.1.3     v dplyr   0.8.3
## v tidyr   0.8.2     v stringr 1.4.0
## v readr   1.1.1     v forcats 0.3.0
## -- Conflicts --------------------------------------------------------------------------------------- tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()
## Loading required package: lubridate
## 
## Attaching package: 'lubridate'
## The following object is masked from 'package:base':
## 
##     date
## Loading required package: PerformanceAnalytics
## Loading required package: xts
## Loading required package: zoo
## 
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
## 
##     as.Date, as.Date.numeric
## 
## Attaching package: 'xts'
## The following objects are masked from 'package:dplyr':
## 
##     first, last
## 
## Attaching package: 'PerformanceAnalytics'
## The following object is masked from 'package:graphics':
## 
##     legend
## Loading required package: quantmod
## Loading required package: TTR
## Version 0.4-0 included new data defaults. See ?getSymbols.
## # A tibble: 6 x 17
##   order.date order.id order.line quantity price price.ext customer.id
##   <date>        <dbl>      <int>    <dbl> <dbl>     <dbl>       <dbl>
## 1 2011-01-07        1          1        1  6070      6070           2
## 2 2011-01-07        1          2        1  5970      5970           2
## 3 2011-01-10        2          1        1  2770      2770          10
## 4 2011-01-10        2          2        1  5970      5970          10
## 5 2011-01-10        3          1        1 10660     10660           6
## 6 2011-01-10        3          2        1  3200      3200           6
## # ... with 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>
## [1] 15644    17
##    order.date            order.id        order.line        quantity       
##  Min.   :2011-01-07   Min.   :   1.0   Min.   : 1.000   Min.   :   1.000  
##  1st Qu.:2012-07-10   1st Qu.: 520.0   1st Qu.: 3.000   1st Qu.:   1.000  
##  Median :2013-08-25   Median : 985.5   Median : 7.000   Median :   1.000  
##  Mean   :2013-08-30   Mean   : 998.0   Mean   : 8.472   Mean   :   8.567  
##  3rd Qu.:2014-11-17   3rd Qu.:1490.0   3rd Qu.:13.000   3rd Qu.:   1.000  
##  Max.   :2015-12-25   Max.   :2000.0   Max.   :30.000   Max.   :1000.000  
##      price         price.ext         customer.id    bikeshop.name     
##  Min.   :  415   Min.   :     415   Min.   : 1.00   Length:15644      
##  1st Qu.: 1840   1st Qu.:    1950   1st Qu.: 8.00   Class :character  
##  Median : 2700   Median :    3200   Median :10.00   Mode  :character  
##  Mean   : 3521   Mean   :   30170   Mean   :13.46                     
##  3rd Qu.: 4260   3rd Qu.:    7000   3rd Qu.:19.00                     
##  Max.   :12790   Max.   :10660000   Max.   :30.00                     
##  bikeshop.city      bikeshop.state        latitude       longitude      
##  Length:15644       Length:15644       Min.   :25.76   Min.   :-122.68  
##  Class :character   Class :character   1st Qu.:35.47   1st Qu.:-104.99  
##  Mode  :character   Mode  :character   Median :39.11   Median : -94.63  
##                                        Mean   :37.94   Mean   : -95.05  
##                                        3rd Qu.:40.44   3rd Qu.: -83.74  
##                                        Max.   :47.61   Max.   : -71.41  
##    product.id       model           category.primary   category.secondary
##  Min.   : 1.00   Length:15644       Length:15644       Length:15644      
##  1st Qu.:25.00   Class :character   Class :character   Class :character  
##  Median :48.00   Mode  :character   Mode  :character   Mode  :character  
##  Mean   :49.48                                                           
##  3rd Qu.:75.00                                                           
##  Max.   :97.00                                                           
##     frame          
##  Length:15644      
##  Class :character  
##  Mode  :character  
##                    
##                    
## 
## # A tibble: 60 x 3
## # Groups:   year [5]
##     year month total.qty
##    <dbl> <ord>     <dbl>
##  1  2011 Jan         440
##  2  2011 Feb        2017
##  3  2011 Mar        1584
##  4  2011 Apr        4478
##  5  2011 May        4112
##  6  2011 Jun        4251
##  7  2011 Jul        1550
##  8  2011 Aug        1470
##  9  2011 Sep         975
## 10  2011 Oct         697
## # ... with 50 more rows

## # A tibble: 538 x 3
## # Groups:   category.secondary [9]
##    category.secondary order.month total.qty
##    <chr>              <date>          <dbl>
##  1 Cross Country Race 2011-01-01        122
##  2 Cross Country Race 2011-02-01        489
##  3 Cross Country Race 2011-03-01        505
##  4 Cross Country Race 2011-04-01        343
##  5 Cross Country Race 2011-05-01        263
##  6 Cross Country Race 2011-06-01        735
##  7 Cross Country Race 2011-07-01        183
##  8 Cross Country Race 2011-08-01         66
##  9 Cross Country Race 2011-09-01         97
## 10 Cross Country Race 2011-10-01        189
## # ... with 528 more rows
## # A tibble: 9 x 2
##   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]>
## # A tibble: 9 x 3
##   category.secondary data              data.ts 
##   <chr>              <list>            <list>  
## 1 Cross Country Race <tibble [60 x 2]> <S3: ts>
## 2 Cyclocross         <tibble [60 x 2]> <S3: ts>
## 3 Elite Road         <tibble [60 x 2]> <S3: ts>
## 4 Endurance Road     <tibble [60 x 2]> <S3: ts>
## 5 Fat Bike           <tibble [58 x 2]> <S3: ts>
## 6 Over Mountain      <tibble [60 x 2]> <S3: ts>
## 7 Sport              <tibble [60 x 2]> <S3: ts>
## 8 Trail              <tibble [60 x 2]> <S3: ts>
## 9 Triathalon         <tibble [60 x 2]> <S3: ts>
## # A tibble: 9 x 4
##   category.secondary data              data.ts  fit.ets  
##   <chr>              <list>            <list>   <list>   
## 1 Cross Country Race <tibble [60 x 2]> <S3: ts> <S3: ets>
## 2 Cyclocross         <tibble [60 x 2]> <S3: ts> <S3: ets>
## 3 Elite Road         <tibble [60 x 2]> <S3: ts> <S3: ets>
## 4 Endurance Road     <tibble [60 x 2]> <S3: ts> <S3: ets>
## 5 Fat Bike           <tibble [58 x 2]> <S3: ts> <S3: ets>
## 6 Over Mountain      <tibble [60 x 2]> <S3: ts> <S3: ets>
## 7 Sport              <tibble [60 x 2]> <S3: ts> <S3: ets>
## 8 Trail              <tibble [60 x 2]> <S3: ts> <S3: ets>
## 9 Triathalon         <tibble [60 x 2]> <S3: ts> <S3: ets>
## # A tibble: 16 x 10
##    term  `Cross Country ~ Cyclocross `Elite Road` `Endurance Road`
##    <chr>            <dbl>      <dbl>        <dbl>            <dbl>
##  1 alpha         0.0398     0.000110     0.0651           0.107   
##  2 b            NA         NA           NA               NA       
##  3 beta         NA         NA           NA               NA       
##  4 gamma         0.000101   0.00256      0.000100         0.000899
##  5 l           321.       210.         490.             394.      
##  6 s0            0.503      0.0788       0.871            0.312   
##  7 s1            1.10       1.32         0.556            1.47    
##  8 s10           0.643      0.212        0.266            0.730   
##  9 s2            0.375      0.0969       0.617            1.13    
## 10 s3            1.12       0.349        1.52             0.554   
## 11 s4            0.630      1.34         0.663            1.06    
## 12 s5            2.06       2.06         0.545            1.99    
## 13 s6            0.873      2.01         1.69             1.14    
## 14 s7            1.64       1.38         1.91             0.836   
## 15 s8            0.487      2.29         1.27             0.694   
## 16 s9            1.41       0.754        1.86             1.83    
## # ... with 5 more variables: `Fat Bike` <dbl>, `Over Mountain` <dbl>,
## #   Sport <dbl>, Trail <dbl>, Triathalon <dbl>
## # A tibble: 9 x 16
##   category.second~ data  data.ts fit.ets model.desc sigma logLik   AIC
##   <chr>            <lis> <list>  <list>  <chr>      <dbl>  <dbl> <dbl>
## 1 Cross Country R~ <tib~ <S3: t~ <S3: e~ ETS(M,N,M) 1.06   -464.  957.
## 2 Cyclocross       <tib~ <S3: t~ <S3: e~ ETS(M,N,M) 1.12   -409.  848.
## 3 Elite Road       <tib~ <S3: t~ <S3: e~ ETS(M,N,M) 0.895  -471.  972.
## 4 Endurance Road   <tib~ <S3: t~ <S3: e~ ETS(M,N,M) 0.759  -439.  909.
## 5 Fat Bike         <tib~ <S3: t~ <S3: e~ ETS(M,N,M) 2.73   -343.  715.
## 6 Over Mountain    <tib~ <S3: t~ <S3: e~ ETS(M,N,M) 0.910  -423.  877.
## 7 Sport            <tib~ <S3: t~ <S3: e~ ETS(M,N,M) 0.872  -427.  884.
## 8 Trail            <tib~ <S3: t~ <S3: e~ ETS(M,A,M) 0.741  -411.  855.
## 9 Triathalon       <tib~ <S3: t~ <S3: e~ ETS(M,N,M) 1.52   -410.  850.
## # ... with 8 more variables: BIC <dbl>, ME <dbl>, RMSE <dbl>, MAE <dbl>,
## #   MPE <dbl>, MAPE <dbl>, MASE <dbl>, ACF1 <dbl>
## # A tibble: 538 x 5
##    category.secondary date       .actual .fitted  .resid
##    <chr>              <date>       <dbl>   <dbl>   <dbl>
##  1 Cross Country Race 2011-01-01     122    373. -0.673 
##  2 Cross Country Race 2011-02-01     489    201.  1.43  
##  3 Cross Country Race 2011-03-01     505    465.  0.0864
##  4 Cross Country Race 2011-04-01     343    161.  1.12  
##  5 Cross Country Race 2011-05-01     263    567. -0.537 
##  6 Cross Country Race 2011-06-01     735    296.  1.48  
##  7 Cross Country Race 2011-07-01     183    741. -0.753 
##  8 Cross Country Race 2011-08-01      66    220. -0.700 
##  9 Cross Country Race 2011-09-01      97    381. -0.745 
## 10 Cross Country Race 2011-10-01     189    123.  0.534 
## # ... with 528 more rows

2019-10-09