Skip to contents

Functions, classes and methods for time series modelling with ARIMA and related models. The aim of the package is to provide consistent interface for the user. For example, a single function autocorrelations() computes various kinds of theoretical and sample autocorrelations. This is work in progress, see the documentation and vignettes for the current functionality. Function sarima() fits extended multiplicative seasonal ARIMA models with trends, exogenous variables and arbitrary roots on the unit circle, which can be fixed or estimated (for the algebraic basis for this see <arXiv:2208.05055>, a paper on the methodology is being prepared).

Details

There is a large number of packages for time series modelling. They provide a huge number of functions, often with similar or overlapping functionality and different argument conventions. One of the aims of package sarima is to provide consistent interface to some frequently used functionality.

In package sarima a consistent naming scheme is used as much as possible. Names of functions start with a lowercase letter and consist of whole words, acronyms or commonly used abbreviations. In multiword names, the second and subsequent words start with capital letters (camelCase). Only the first letter in acronyms is capitalised, e.g. Arma stands for ARMA. Formal (S4) classes follow the same rules but the first letter of the first word is capitalised, as well.

For example, the functions that compute autocorrelations, autocovariances, partial autocorrelations are called autocorrelations, autocovariances, and partialAutocorrelations, respectively. Moreover, they recognise from their argument(s) what exactly is needed. If they are given times series, they compute sample autocorrelations, etc; if they are given model specifications, they compute the corresponding theoretical properties.

This is work in progress, see also the vignette(s).

Author

Georgi N. Boshnakov [aut, cre], Jamie Halliday [aut]

Maintainer: Georgi N. Boshnakov <georgi.boshnakov@manchester.ac.uk>

References

Boshnakov GN (1996). “Bartlett's formulae---closed forms and recurrent equations.” Ann. Inst. Statist. Math., 48(1), 49--59. ISSN 0020-3157, doi:10.1007/BF00049288 .

Halliday J, Boshnakov GN (2022). “Partial autocorrelation parameterisation of models with unit roots on the unit circle.” doi:10.48550/ARXIV.2208.05055 , https://arxiv.org/abs/2208.05055.

Brockwell PJ, Davis RA (1991). Time series: theory and methods. 2nd ed.. Springer Series in Statistics. Berlin etc.: Springer-Verlag..

Francq C, Zakoian J (2010). GARCH models: structure, statistical inference and financial applications. John Wiley & Sons. ISBN 978-0-470-68391-0.

Li WK (2004). Diagnostic checks in time series. Chapman & Hall/CRC Press.

McLeod AI, Yu H, Krougly Z (2007). “Algorithms for Linear Time Series Analysis: With R Package.” Journal of Statistical Software, 23(5). doi:10.18637/jss.v023.i05 .

Examples

## simulate a white noise ts (model from Francq & Zakoian)
n <- 5000
x <- sarima:::rgarch1p1(n, alpha = 0.3, beta = 0.55, omega = 1, n.skip = 100)

## acf and pacf
( x.acf <- autocorrelations(x) )
#> An object of class "SampleAutocorrelations"
#>         Lag_0         Lag_1         Lag_2         Lag_3         Lag_4 
#>  1.0000000000 -0.0328968366  0.0404686214 -0.0280091109 -0.0140648056 
#>         Lag_5         Lag_6         Lag_7         Lag_8         Lag_9 
#> -0.0011682836 -0.0270627319 -0.0129497797  0.0187398947 -0.0051402076 
#>        Lag_10        Lag_11        Lag_12        Lag_13        Lag_14 
#>  0.0407329366 -0.0039834520  0.0041946133 -0.0261820256 -0.0339899078 
#>        Lag_15        Lag_16        Lag_17        Lag_18        Lag_19 
#> -0.0069372701 -0.0095070191 -0.0273699085 -0.0038505927  0.0137267489 
#>        Lag_20        Lag_21        Lag_22        Lag_23        Lag_24 
#>  0.0150920891  0.0170354950 -0.0107532038 -0.0056515480  0.0125558356 
#>        Lag_25        Lag_26        Lag_27        Lag_28        Lag_29 
#> -0.0016884423 -0.0114251957  0.0006966703 -0.0027162658  0.0025002938 
#>        Lag_30        Lag_31        Lag_32        Lag_33        Lag_34 
#> -0.0044136980 -0.0053541785  0.0079752641 -0.0140166271 -0.0015153068 
#>        Lag_35        Lag_36 
#>  0.0173244245 -0.0067480160 
#> Slot n:
#> [1] 5000
#> Slot varnames:   <not set>
#> Slot objectname:  x
( x.pacf <- partialAutocorrelations(x) )
#> An object of class "SamplePartialAutocorrelations"
#>         Lag_0         Lag_1         Lag_2         Lag_3         Lag_4 
#>  1.000000e+00 -3.289684e-02  3.942909e-02 -2.550042e-02 -1.738071e-02 
#>         Lag_5         Lag_6         Lag_7         Lag_8         Lag_9 
#> -2.257911e-05 -2.666839e-02 -1.548717e-02  1.978796e-02 -4.342861e-03 
#>        Lag_10        Lag_11        Lag_12        Lag_13        Lag_14 
#>  3.748330e-02 -5.799137e-04  5.326288e-04 -2.471690e-02 -3.411923e-02 
#>        Lag_15        Lag_16        Lag_17        Lag_18        Lag_19 
#> -6.778488e-03 -6.982875e-03 -2.905399e-02 -7.754974e-03  1.408658e-02 
#>        Lag_20        Lag_21        Lag_22        Lag_23        Lag_24 
#>  1.061696e-02  1.568584e-02 -9.981396e-03 -6.378303e-03  1.604568e-02 
#>        Lag_25        Lag_26        Lag_27        Lag_28        Lag_29 
#>  1.548825e-03 -1.218114e-02  1.609845e-03 -3.060986e-03 -1.290919e-03 
#>        Lag_30        Lag_31        Lag_32        Lag_33        Lag_34 
#> -6.292693e-03 -9.091505e-03  7.522659e-03 -1.205336e-02 -3.298488e-03 
#>        Lag_35        Lag_36 
#>  1.924078e-02 -5.168478e-03 
#> Slot n:
#> [1] 5000
#> Slot varnames:   <not set>
#> Slot objectname:  x

## portmanteau test for iid, by default gives also ci's for the acf under H0
x.iid <- whiteNoiseTest(x.acf, h0 = "iid", nlags = c(5,10,20), x = x, method = "LiMcLeod")
x.iid
#> $test
#>         ChiSq DF       pvalue
#> [1,] 18.52103  5 0.0023595472
#> [2,] 33.21335 10 0.0002507838
#> [3,] 49.20894 20 0.0002871614
#> attr(,"method")
#> [1] "LiMcLeod"
#> 
#> $ci
#>               int           
#>  [1,] -0.02771808 0.02771808
#>  [2,] -0.02771808 0.02771808
#>  [3,] -0.02771808 0.02771808
#>  [4,] -0.02771808 0.02771808
#>  [5,] -0.02771808 0.02771808
#>  [6,] -0.02771808 0.02771808
#>  [7,] -0.02771808 0.02771808
#>  [8,] -0.02771808 0.02771808
#>  [9,] -0.02771808 0.02771808
#> [10,] -0.02771808 0.02771808
#> [11,] -0.02771808 0.02771808
#> [12,] -0.02771808 0.02771808
#> [13,] -0.02771808 0.02771808
#> [14,] -0.02771808 0.02771808
#> [15,] -0.02771808 0.02771808
#> [16,] -0.02771808 0.02771808
#> [17,] -0.02771808 0.02771808
#> [18,] -0.02771808 0.02771808
#> [19,] -0.02771808 0.02771808
#> [20,] -0.02771808 0.02771808
#> attr(,"level")
#> [1] 0.95
#> 

x.iid2 <- whiteNoiseTest(x.acf, h0 = "iid", nlags = c(5,10,20), x = x, method = "LjungBox")
x.iid2
#> $test
#>         ChiSq DF       pvalue
#> [1,] 18.53295  5 0.0023475578
#> [2,] 33.24841 10 0.0002473984
#> [3,] 49.26834 20 0.0002816355
#> attr(,"method")
#> [1] "LjungBox"
#> 
#> $ci
#>               int           
#>  [1,] -0.02771808 0.02771808
#>  [2,] -0.02771808 0.02771808
#>  [3,] -0.02771808 0.02771808
#>  [4,] -0.02771808 0.02771808
#>  [5,] -0.02771808 0.02771808
#>  [6,] -0.02771808 0.02771808
#>  [7,] -0.02771808 0.02771808
#>  [8,] -0.02771808 0.02771808
#>  [9,] -0.02771808 0.02771808
#> [10,] -0.02771808 0.02771808
#> [11,] -0.02771808 0.02771808
#> [12,] -0.02771808 0.02771808
#> [13,] -0.02771808 0.02771808
#> [14,] -0.02771808 0.02771808
#> [15,] -0.02771808 0.02771808
#> [16,] -0.02771808 0.02771808
#> [17,] -0.02771808 0.02771808
#> [18,] -0.02771808 0.02771808
#> [19,] -0.02771808 0.02771808
#> [20,] -0.02771808 0.02771808
#> attr(,"level")
#> [1] 0.95
#> 

## portmanteau test for garch H0
x.garch <- whiteNoiseTest(x.acf, h0 = "garch", nlags = c(5,10,20), x = x)
x.garch
#> $test
#>       h         Q       pval
#> [1,]  5  6.454586 0.26446280
#> [2,] 10 17.319319 0.06759019
#> [3,] 20 30.689383 0.05942694
#> 
#> $ci
#>               int           
#>  [1,] -0.04711984 0.04711984
#>  [2,] -0.04811414 0.04811414
#>  [3,] -0.04752476 0.04752476
#>  [4,] -0.04021118 0.04021118
#>  [5,] -0.03914635 0.03914635
#>  [6,] -0.03506707 0.03506707
#>  [7,] -0.03486665 0.03486665
#>  [8,] -0.03256475 0.03256475
#>  [9,] -0.03174065 0.03174065
#> [10,] -0.03108133 0.03108133
#> [11,] -0.03147183 0.03147183
#> [12,] -0.03050650 0.03050650
#> [13,] -0.03168418 0.03168418
#> [14,] -0.03164023 0.03164023
#> [15,] -0.03226080 0.03226080
#> [16,] -0.02995512 0.02995512
#> [17,] -0.03195747 0.03195747
#> [18,] -0.03187449 0.03187449
#> [19,] -0.02891890 0.02891890
#> [20,] -0.03169497 0.03169497
#> 

## plot methods give the CI's under H0
plot(x.acf)


## if the data are given, the CI's under garch H0 are also given.
plot(x.acf, data = x)


## Tests based on partial autocorrelations are also available:
plot(x.pacf)

plot(x.pacf, data = x)


## Models
## AR
( ar2a1 <- ArModel(ar = c(-0.3, -0.7), sigma2 = 1) )
#> An object of class "ArModel"
#> mean:  0 
#> sigmaSq:  1 
#> 
#> slot "ar":
#> An object of class "BJFilter"
#> order:  2 
#> Coefficients: 
#> [1] -0.3 -0.7
#> 
#> slot "ma":
#> An object of class "SPFilter"
#> order:  0 
#> Coefficients: 
#> numeric(0)
autocorrelations(ar2a1, maxlag = 6)
#> An object of class "Autocorrelations"
#>          0          1          2          3          4          5          6 
#>  1.0000000 -0.1764706 -0.6470588  0.3176471  0.3576471 -0.3296471 -0.1514588 
partialAutocorrelations(ar2a1, maxlag = 6)
#> An object of class "PartialAutocorrelations"
#>         Lag_0         Lag_1         Lag_2         Lag_3         Lag_4 
#>  1.000000e+00 -1.764706e-01 -7.000000e-01 -1.123440e-16  1.123440e-16 
#>         Lag_5         Lag_6 
#> -1.123440e-16 -5.617200e-17 
autocovariances(ar2a1, maxlag = 6)
#> An object of class "Autocovariances"
#>      Lag_0      Lag_1      Lag_2      Lag_3      Lag_4      Lag_5      Lag_6 
#>  2.0238095 -0.3571429 -1.3095238  0.6428571  0.7238095 -0.6671429 -0.3065238 
partialVariances(ar2a1, maxlag = 6)
#> An object of class "PartialVariances"
#>        0        1        2        3        4        5        6 
#> 2.023810 1.960784 1.000000 1.000000 1.000000 1.000000 1.000000 

## see examples for ArmaModel()