ARIMA, how extract the constant?

Dear all

i run the the following code

Load Libraries

{r}
library("tidyverse")
library("lubridate")
library("tsibble")
library("tsibbledata")
library("feasts")
library("fable")
library("distributional")

Create variables

{r}
victoria_pigs <- aus_livestock %>%
  filter(State == "Victoria" & Animal=="Pigs")

Fitting the model

{r}
fit <- victoria_pigs%>%
  model(ARIMA(Count))
report(fit)

Series: Count
Model: ARIMA(2,1,2)(0,0,2)[12]

Coefficients:
ar1 ar2 ma1 ma2 sma1 sma2
-1.0110 -0.2209 0.4194 -0.4604 0.4818 0.2070
s.e. 0.0767 0.0796 0.0752 0.0795 0.0432 0.0429

sigma^2 estimated as 65208832: log likelihood=-5800.22
AIC=11614.43 AICc=11614.63 BIC=11644.69

  1. how do i extract the constant c ? when i run the code i cannot see it, in fact is it possible to extract the whole equation? , 9.5 Non-seasonal ARIMA models | Forecasting: PrinciplesΒ andΒ Practice (3rd ed)

Tony

Not all models include a constant. Chapter 9 covers the effect of having c β‰  0. In the reprex below the model chosen by the ARIMA() function for the h02 data has a drift with non-zero value for c, while the model for victoria_pigs has no drift and c = 0.

library(fpp3)
#> ── Attaching packages ──────────────────────────────────────────── fpp3 0.4.0 ──
#> βœ” tibble      3.1.8           βœ” tsibble     1.1.3      
#> βœ” dplyr       1.0.99.9000     βœ” tsibbledata 0.4.1      
#> βœ” tidyr       1.2.1           βœ” feasts      0.3.0.9000 
#> βœ” lubridate   1.9.0           βœ” fable       0.3.2.9000 
#> βœ” ggplot2     3.4.0
#> ── Conflicts ───────────────────────────────────────────────── fpp3_conflicts ──
#> βœ– lubridate::date()    masks base::date()
#> βœ– dplyr::filter()      masks stats::filter()
#> βœ– tsibble::intersect() masks base::intersect()
#> βœ– tsibble::interval()  masks lubridate::interval()
#> βœ– dplyr::lag()         masks stats::lag()
#> βœ– tsibble::setdiff()   masks base::setdiff()
#> βœ– tsibble::union()     masks base::union()

victoria_pigs <- aus_livestock %>%
  filter(State == "Victoria" & Animal=="Pigs")

h02 <- PBS %>%
  filter(ATC2 == "H02") %>%
  summarise(Cost = sum(Cost)/1e6)

victoria_pigs %>%
  model(ARIMA(Count)) %>%
  report()
#> Series: Count 
#> Model: ARIMA(2,1,2)(0,0,2)[12] 
#> 
#> Coefficients:
#>           ar1      ar2     ma1      ma2    sma1    sma2
#>       -1.0110  -0.2209  0.4194  -0.4604  0.4818  0.2070
#> s.e.   0.0767   0.0796  0.0752   0.0795  0.0432  0.0429
#> 
#> sigma^2 estimated as 65208832:  log likelihood=-5800.22
#> AIC=11614.43   AICc=11614.63   BIC=11644.69

h02 %>% 
  model(ARIMA(Cost)) %>%
  report()
#> Series: Cost 
#> Model: ARIMA(4,0,0)(1,1,1)[12] w/ drift 
#> 
#> Coefficients:
#>          ar1     ar2     ar3      ar4    sar1     sma1  constant
#>       0.1381  0.4021  0.3031  -0.1577  0.1789  -0.6713    0.0080
#> s.e.  0.0764  0.0719  0.0753   0.0784  0.1261   0.0940    0.0014
#> 
#> sigma^2 estimated as 0.002767:  log likelihood=293.91
#> AIC=-571.83   AICc=-571.04   BIC=-545.77

Created on 2022-11-25 with reprex v2.0.2

To extract the estimated coefficients use the tidy() function from {fabletools}

library(fpp3)
#> ── Attaching packages ──────────────────────────────────────────── fpp3 0.4.0 ──
#> βœ” tibble      3.1.8           βœ” tsibble     1.1.3      
#> βœ” dplyr       1.0.99.9000     βœ” tsibbledata 0.4.1      
#> βœ” tidyr       1.2.1           βœ” feasts      0.3.0.9000 
#> βœ” lubridate   1.9.0           βœ” fable       0.3.2.9000 
#> βœ” ggplot2     3.4.0
#> ── Conflicts ───────────────────────────────────────────────── fpp3_conflicts ──
#> βœ– lubridate::date()    masks base::date()
#> βœ– dplyr::filter()      masks stats::filter()
#> βœ– tsibble::intersect() masks base::intersect()
#> βœ– tsibble::interval()  masks lubridate::interval()
#> βœ– dplyr::lag()         masks stats::lag()
#> βœ– tsibble::setdiff()   masks base::setdiff()
#> βœ– tsibble::union()     masks base::union()

victoria_pigs <- aus_livestock %>%
  filter(State == "Victoria" & Animal=="Pigs")

h02 <- PBS %>%
  filter(ATC2 == "H02") %>%
  summarise(Cost = sum(Cost)/1e6)

victoria_pigs %>%
  model(ARIMA(Count)) %>%
  tidy()
#> # A tibble: 6 Γ— 8
#>   Animal State    .model       term  estimate std.error statistic  p.value
#>   <fct>  <fct>    <chr>        <chr>    <dbl>     <dbl>     <dbl>    <dbl>
#> 1 Pigs   Victoria ARIMA(Count) ar1     -1.01     0.0767    -13.2  9.25e-35
#> 2 Pigs   Victoria ARIMA(Count) ar2     -0.221    0.0796     -2.78 5.68e- 3
#> 3 Pigs   Victoria ARIMA(Count) ma1      0.419    0.0752      5.58 3.75e- 8
#> 4 Pigs   Victoria ARIMA(Count) ma2     -0.460    0.0795     -5.79 1.19e- 8
#> 5 Pigs   Victoria ARIMA(Count) sma1     0.482    0.0432     11.1  3.47e-26
#> 6 Pigs   Victoria ARIMA(Count) sma2     0.207    0.0429      4.83 1.79e- 6

h02 %>% 
  model(ARIMA(Cost)) %>%
  tidy()
#> # A tibble: 7 Γ— 6
#>   .model      term     estimate std.error statistic  p.value
#>   <chr>       <chr>       <dbl>     <dbl>     <dbl>    <dbl>
#> 1 ARIMA(Cost) ar1       0.138     0.0764       1.81 7.23e- 2
#> 2 ARIMA(Cost) ar2       0.402     0.0719       5.59 7.53e- 8
#> 3 ARIMA(Cost) ar3       0.303     0.0753       4.02 8.22e- 5
#> 4 ARIMA(Cost) ar4      -0.158     0.0784      -2.01 4.56e- 2
#> 5 ARIMA(Cost) sar1      0.179     0.126        1.42 1.58e- 1
#> 6 ARIMA(Cost) sma1     -0.671     0.0940      -7.14 1.89e-11
#> 7 ARIMA(Cost) constant  0.00798   0.00136      5.86 2.00e- 8

Created on 2022-11-25 with reprex v2.0.2

2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.