Skip to contents

Closes the loop from selection to a fitted model: estimates the order of integration (unless d is given), runs the chosen order selector on the suitably differenced series, and fits the resulting ARIMA specification with stats::arima(). The returned object is a standard "Arima" fit, so the usual ecosystem applies directly: predict(), forecast::forecast(), broom::tidy(), residual diagnostics, etc.

Usage

fit_arima(x, method = "pacf", d = NULL, include.mean = TRUE, ...)

Arguments

x

A numeric vector (a stationary series; see integration_order() first if in doubt).

method

As in order_select() (AR-targeted statistics and criteria give ARIMA(p, d, 0); MA-targeted statistics give ARIMA(0, d, q)), plus "hr" for Hannan-Rissanen, which selects p and q jointly. McMillan-degree methods do not define (p, q) and are not accepted.

d

Order of integration; NULL (default) estimates it with integration_order().

include.mean

Passed to stats::arima() (ignored when d > 0, as there).

...

Passed to the underlying selector.

Value

A stats::arima() fit with two extra attributes: tsorder (the selection object) and tsorder_d (the integration order used).

Examples

set.seed(1)
x <- arima.sim(list(ar = c(1.2, -0.6)), 300)
fit <- fit_arima(x)
fit
#> 
#> Call:
#> stats::arima(x = x, order = ord, include.mean = include.mean)
#> 
#> Coefficients:
#>          ar1      ar2  intercept
#>       1.1467  -0.5852     0.1128
#> s.e.  0.0465   0.0465     0.1267
#> 
#> sigma^2 estimated as 0.9263:  log likelihood = -414.99,  aic = 837.98
predict(fit, n.ahead = 6)$pred
#> Time Series:
#> Start = 301 
#> End = 306 
#> Frequency = 1 
#> [1] -0.6523649 -0.1791668  0.2257732  0.4132000  0.3911523  0.2561903