Simple Case Studies

library(srlTS)
library(magrittr) # for pipe

Lake Huron data set

data("LakeHuron")

fit_LH <- srlTS(LakeHuron)

fit_LH
#>  PF_gamma best_AICc best_BIC
#>      0.00  147.2053 159.8118
#>      0.25  146.3811 156.7937
#>      0.50  146.0177 156.4739
#>      1.00  144.1002 154.4967
#>      2.00  143.0362 153.2544
#>      4.00  149.8227 156.1558
#>      8.00  149.8227 156.1558
#>     16.00  149.8227 156.1558
#> 
#> Test-set prediction accuracy
#>       rmse       rsq       mae
#> AIC 0.7751 0.6203825 0.5888855
#> BIC 0.7751 0.6203825 0.5888855
coef(fit_LH)
#>                 0.00069
#> (Intercept) 111.8740292
#> lag1          1.1003545
#> lag2         -0.4732437
#> lag3          0.1796316
#> lag4          0.0000000
#> lag5          0.0000000
#> lag6          0.0000000
#> lag7          0.0000000
#> lag8          0.0000000
#> lag9          0.0000000

EuStockMarkets

If you have a univariate time series with suspected trend, such as the EuStockMarkets data set,

data("EuStockMarkets")
X <- as.numeric(time(EuStockMarkets))
X_sp <- splines::bs(X-min(X), df = 9)

fit_stock <- srlTS(log(EuStockMarkets[,1]), n_lags_max = 400, X = X_sp, w_exo = "unpenalized")
tail(coef(fit_stock), 11)
#>           0.0000096
#> lag399  0.000000000
#> lag400  0.000000000
#> 1       0.251818563
#> 2      -0.064008340
#> 3      -0.022147416
#> 4      -0.015421857
#> 5      -0.014734876
#> 6       0.001020223
#> 7       0.011708216
#> 8       0.311147538
#> 9       0.000000000

# insert plot? 

Seasonal examples

Nottem

data("nottem")
fit_nt <- srlTS(nottem, n_lags_max = 24)
coef(fit_nt)
#>                  0.0393
#> (Intercept) 11.89830169
#> lag1         0.40437830
#> lag2         0.00000000
#> lag3        -0.06838188
#> lag4        -0.09660138
#> lag5        -0.01640032
#> lag6         0.00000000
#> lag7        -0.04079986
#> lag8         0.00000000
#> lag9         0.00000000
#> lag10        0.00000000
#> lag11        0.16707390
#> lag12        0.00000000
#> lag13        0.05894906
#> lag14        0.00000000
#> lag15        0.00000000
#> lag16        0.00000000
#> lag17        0.00000000
#> lag18        0.00000000
#> lag19        0.00000000
#> lag20        0.00000000
#> lag21        0.00000000
#> lag22        0.00000000
#> lag23        0.00000000
#> lag24        0.34816025

UKDriverDeaths

data("UKDriverDeaths")
fit_ukdd <- srlTS(UKDriverDeaths, n_lags_max = 24)
coef(fit_ukdd)
#>                  0.0282
#> (Intercept) 198.6573213
#> lag1          0.3805100
#> lag2          0.0000000
#> lag3          0.0000000
#> lag4          0.0000000
#> lag5          0.0000000
#> lag6          0.0000000
#> lag7          0.0000000
#> lag8          0.0000000
#> lag9          0.0000000
#> lag10         0.0000000
#> lag11         0.1645141
#> lag12         0.4682378
#> lag13         0.0000000
#> lag14        -0.1357345
#> lag15         0.0000000
#> lag16         0.0000000
#> lag17         0.0000000
#> lag18         0.0000000
#> lag19         0.0000000
#> lag20         0.0000000
#> lag21         0.0000000
#> lag22         0.0000000
#> lag23         0.0000000
#> lag24         0.0000000

Adding holiday indicators…

sunspot


data("sunspot.month")
fit_ssm <- srlTS(sunspot.month)
fit_ssm
#>  PF_gamma best_AICc best_BIC
#>      0.00  18373.20 18506.04
#>      0.25  18356.15 18467.11
#>      0.50  18348.28 18467.59
#>      1.00  18417.42 18502.81
#>      2.00  18569.61 18598.12
#>      4.00  18782.77 18799.88
#>      8.00  18782.77 18799.88
#>     16.00  18782.77 18799.88
#> 
#> Test-set prediction accuracy
#>         rmse       rsq      mae
#> AIC 15.94153 0.8920872 11.85384
#> BIC 16.04978 0.8906613 11.99382

Model summaries

summary(fit_ssm)
#> Model summary at optimal AICc (lambda=0.0514; gamma=0.5)
#> lasso-penalized linear regression with n=2224, p=317
#> At lambda=0.0514:
#> -------------------------------------------------
#>   Nonzero coefficients         :  22
#>   Expected nonzero coefficients:  11.05
#>   Average mfdr (22 features)   :   0.502
#> 
#>         Estimate       z     mfdr Selected
#> lag1    0.543429 75.5671  < 1e-04        *
#> lag2    0.100936 14.3108  < 1e-04        *
#> lag9    0.095814 13.9892  < 1e-04        *
#> lag4    0.088981 12.7748  < 1e-04        *
#> lag3    0.077649 11.1365  < 1e-04        *
#> lag6    0.058591  8.7845  < 1e-04        *
#> lag5    0.031138  4.9444 0.001529        *
#> lag18  -0.028505 -4.4224 0.014416        *
#> lag102  0.021959  3.7402 0.166810        *
#> lag27  -0.019987 -3.4042 0.387958        *
#> lag212 -0.018947 -3.1479 0.588979        *
#> lag24  -0.018334 -3.0999 0.623896        *
#> lag111  0.017205  2.9704 0.709145        *
#> lag92   0.017222  2.8639 0.767884        *
#> lag12   0.012107  2.3759 0.921349        *
#> lag21  -0.009982 -2.0002 0.963700        *
#> lag292 -0.010658 -1.9653 0.966033        *
#> lag20  -0.007329 -1.6906 0.979140        *
#> lag34  -0.004472 -1.3302 0.987783        *
#> lag55  -0.003429 -1.2274 0.989271        *
#> lag96   0.001556  1.0625 0.991100        *
#> lag275  0.000595  0.8962 0.992427        *