Skip to contents

Fits an ARIMA model with exogenous regressors (ARIMAX).

Usage

ts_arimax(
  x,
  xreg,
  order = NULL,
  seasonal = NULL,
  stepwise = TRUE,
  approximation = TRUE,
  ...
)

Arguments

x

A complete ts_df with no missing values.

xreg

A matrix or data.frame of exogenous regressors with nrow(xreg) == nrow(x).

order

Optional non-seasonal ARIMA order. If NULL (default), automatic order selection via forecast::auto.arima().

seasonal

Optional seasonal specification.

stepwise, approximation

Passed to forecast::auto.arima().

...

Additional arguments passed to the forecast fitting function.

Value

A list containing tidy model summaries, the raw model, input, and the exogenous regressors used.

Examples

x = as_ts_df(log(AirPassengers))
xreg = data.frame(trend = seq_len(nrow(x)))
ts_arimax(x, xreg = xreg)
#> $model_info
#> # A tibble: 1 × 5
#>   log_lik   aic  aicc   bic  sigma2
#>     <dbl> <dbl> <dbl> <dbl>   <dbl>
#> 1    212. -407. -406. -383. 0.00289
#> 
#> $coefficients
#> # A tibble: 7 × 3
#>   term      estimate std_error
#>   <chr>        <dbl>     <dbl>
#> 1 ma1        0.738    0.0835  
#> 2 ma2        0.596    0.0986  
#> 3 ma3        0.243    0.0823  
#> 4 sma1       0.828    0.0826  
#> 5 sma2       0.650    0.103   
#> 6 intercept  4.82     0.0469  
#> 7 trend      0.00992  0.000544
#> 
#> $fitted
#> # A tibble: 144 × 4
#>     time observed fitted residual
#>    <int>    <dbl>  <dbl>    <dbl>
#>  1     1     4.72   4.77 -0.0540 
#>  2     2     4.77   4.77  0.00443
#>  3     3     4.88   4.83  0.0491 
#>  4     4     4.86   4.89 -0.0285 
#>  5     5     4.80   4.85 -0.0574 
#>  6     6     4.91   4.84  0.0664 
#>  7     7     5.00   4.93  0.0669 
#>  8     8     5.00   5.00 -0.00652
#>  9     9     4.91   4.96 -0.0475 
#> 10    10     4.78   4.85 -0.0671 
#> # ℹ 134 more rows
#> 
#> $diagnostics
#> # A tibble: 1 × 5
#>   test        lag statistic p_value conclusion              
#>   <chr>     <int>     <dbl>   <dbl> <chr>                   
#> 1 Ljung-Box    13      50.9       0 Autocorrelation detected
#> 
#> $model
#> Series: x_ts 
#> Regression with ARIMA(0,0,3)(0,0,2)[12] errors 
#> 
#> Coefficients:
#>          ma1     ma2     ma3    sma1    sma2  intercept   trend
#>       0.7384  0.5956  0.2430  0.8282  0.6496     4.8183  0.0099
#> s.e.  0.0835  0.0986  0.0823  0.0826  0.1027     0.0469  0.0005
#> 
#> sigma^2 = 0.002887:  log likelihood = 211.57
#> AIC=-407.14   AICc=-406.08   BIC=-383.39
#> 
#> $input
#>     time    value
#> 1      1 4.718499
#> 2      2 4.770685
#> 3      3 4.882802
#> 4      4 4.859812
#> 5      5 4.795791
#> 6      6 4.905275
#> 7      7 4.997212
#> 8      8 4.997212
#> 9      9 4.912655
#> 10    10 4.779123
#> 11    11 4.644391
#> 12    12 4.770685
#> 13    13 4.744932
#> 14    14 4.836282
#> 15    15 4.948760
#> 16    16 4.905275
#> 17    17 4.828314
#> 18    18 5.003946
#> 19    19 5.135798
#> 20    20 5.135798
#> 21    21 5.062595
#> 22    22 4.890349
#> 23    23 4.736198
#> 24    24 4.941642
#> 25    25 4.976734
#> 26    26 5.010635
#> 27    27 5.181784
#> 28    28 5.093750
#> 29    29 5.147494
#> 30    30 5.181784
#> 31    31 5.293305
#> 32    32 5.293305
#> 33    33 5.214936
#> 34    34 5.087596
#> 35    35 4.983607
#> 36    36 5.111988
#> 37    37 5.141664
#> 38    38 5.192957
#> 39    39 5.262690
#> 40    40 5.198497
#> 41    41 5.209486
#> 42    42 5.384495
#> 43    43 5.438079
#> 44    44 5.488938
#> 45    45 5.342334
#> 46    46 5.252273
#> 47    47 5.147494
#> 48    48 5.267858
#> 49    49 5.278115
#> 50    50 5.278115
#> 51    51 5.463832
#> 52    52 5.459586
#> 53    53 5.433722
#> 54    54 5.493061
#> 55    55 5.575949
#> 56    56 5.605802
#> 57    57 5.468060
#> 58    58 5.351858
#> 59    59 5.192957
#> 60    60 5.303305
#> 61    61 5.318120
#> 62    62 5.236442
#> 63    63 5.459586
#> 64    64 5.424950
#> 65    65 5.455321
#> 66    66 5.575949
#> 67    67 5.710427
#> 68    68 5.680173
#> 69    69 5.556828
#> 70    70 5.433722
#> 71    71 5.313206
#> 72    72 5.433722
#> 73    73 5.488938
#> 74    74 5.451038
#> 75    75 5.587249
#> 76    76 5.594711
#> 77    77 5.598422
#> 78    78 5.752573
#> 79    79 5.897154
#> 80    80 5.849325
#> 81    81 5.743003
#> 82    82 5.613128
#> 83    83 5.468060
#> 84    84 5.627621
#> 85    85 5.648974
#> 86    86 5.624018
#> 87    87 5.758902
#> 88    88 5.746203
#> 89    89 5.762051
#> 90    90 5.924256
#> 91    91 6.023448
#> 92    92 6.003887
#> 93    93 5.872118
#> 94    94 5.723585
#> 95    95 5.602119
#> 96    96 5.723585
#> 97    97 5.752573
#> 98    98 5.707110
#> 99    99 5.874931
#> 100  100 5.852202
#> 101  101 5.872118
#> 102  102 6.045005
#> 103  103 6.142037
#> 104  104 6.146329
#> 105  105 6.001415
#> 106  106 5.849325
#> 107  107 5.720312
#> 108  108 5.817111
#> 109  109 5.828946
#> 110  110 5.762051
#> 111  111 5.891644
#> 112  112 5.852202
#> 113  113 5.894403
#> 114  114 6.075346
#> 115  115 6.196444
#> 116  116 6.224558
#> 117  117 6.001415
#> 118  118 5.883322
#> 119  119 5.736572
#> 120  120 5.820083
#> 121  121 5.886104
#> 122  122 5.834811
#> 123  123 6.006353
#> 124  124 5.981414
#> 125  125 6.040255
#> 126  126 6.156979
#> 127  127 6.306275
#> 128  128 6.326149
#> 129  129 6.137727
#> 130  130 6.008813
#> 131  131 5.891644
#> 132  132 6.003887
#> 133  133 6.033086
#> 134  134 5.968708
#> 135  135 6.037871
#> 136  136 6.133398
#> 137  137 6.156979
#> 138  138 6.282267
#> 139  139 6.432940
#> 140  140 6.406880
#> 141  141 6.230481
#> 142  142 6.133398
#> 143  143 5.966147
#> 144  144 6.068426
#> 
#> $xreg
#>        trend
#>   [1,]     1
#>   [2,]     2
#>   [3,]     3
#>   [4,]     4
#>   [5,]     5
#>   [6,]     6
#>   [7,]     7
#>   [8,]     8
#>   [9,]     9
#>  [10,]    10
#>  [11,]    11
#>  [12,]    12
#>  [13,]    13
#>  [14,]    14
#>  [15,]    15
#>  [16,]    16
#>  [17,]    17
#>  [18,]    18
#>  [19,]    19
#>  [20,]    20
#>  [21,]    21
#>  [22,]    22
#>  [23,]    23
#>  [24,]    24
#>  [25,]    25
#>  [26,]    26
#>  [27,]    27
#>  [28,]    28
#>  [29,]    29
#>  [30,]    30
#>  [31,]    31
#>  [32,]    32
#>  [33,]    33
#>  [34,]    34
#>  [35,]    35
#>  [36,]    36
#>  [37,]    37
#>  [38,]    38
#>  [39,]    39
#>  [40,]    40
#>  [41,]    41
#>  [42,]    42
#>  [43,]    43
#>  [44,]    44
#>  [45,]    45
#>  [46,]    46
#>  [47,]    47
#>  [48,]    48
#>  [49,]    49
#>  [50,]    50
#>  [51,]    51
#>  [52,]    52
#>  [53,]    53
#>  [54,]    54
#>  [55,]    55
#>  [56,]    56
#>  [57,]    57
#>  [58,]    58
#>  [59,]    59
#>  [60,]    60
#>  [61,]    61
#>  [62,]    62
#>  [63,]    63
#>  [64,]    64
#>  [65,]    65
#>  [66,]    66
#>  [67,]    67
#>  [68,]    68
#>  [69,]    69
#>  [70,]    70
#>  [71,]    71
#>  [72,]    72
#>  [73,]    73
#>  [74,]    74
#>  [75,]    75
#>  [76,]    76
#>  [77,]    77
#>  [78,]    78
#>  [79,]    79
#>  [80,]    80
#>  [81,]    81
#>  [82,]    82
#>  [83,]    83
#>  [84,]    84
#>  [85,]    85
#>  [86,]    86
#>  [87,]    87
#>  [88,]    88
#>  [89,]    89
#>  [90,]    90
#>  [91,]    91
#>  [92,]    92
#>  [93,]    93
#>  [94,]    94
#>  [95,]    95
#>  [96,]    96
#>  [97,]    97
#>  [98,]    98
#>  [99,]    99
#> [100,]   100
#> [101,]   101
#> [102,]   102
#> [103,]   103
#> [104,]   104
#> [105,]   105
#> [106,]   106
#> [107,]   107
#> [108,]   108
#> [109,]   109
#> [110,]   110
#> [111,]   111
#> [112,]   112
#> [113,]   113
#> [114,]   114
#> [115,]   115
#> [116,]   116
#> [117,]   117
#> [118,]   118
#> [119,]   119
#> [120,]   120
#> [121,]   121
#> [122,]   122
#> [123,]   123
#> [124,]   124
#> [125,]   125
#> [126,]   126
#> [127,]   127
#> [128,]   128
#> [129,]   129
#> [130,]   130
#> [131,]   131
#> [132,]   132
#> [133,]   133
#> [134,]   134
#> [135,]   135
#> [136,]   136
#> [137,]   137
#> [138,]   138
#> [139,]   139
#> [140,]   140
#> [141,]   141
#> [142,]   142
#> [143,]   143
#> [144,]   144
#>