Page 2 of 3

Re: procedure plotting the characteristic roots for ARIMA mo

Posted: Wed Apr 05, 2023 6:46 am
by ac_1
For the following specifications

Code: Select all

boxjenk(const,ar=1,diffs=1,ma=0,sar=1,sdiffs=0,sma=0,maxl,define=deq) writing
@acbjICRS deq writing

boxjenk(const,ar=0,diffs=0,ma=1,sar=0,sdiffs=1,sma=0,maxl,define=deq) writing
@acbjICRS deq writing

boxjenk(noconst,ar=2,diffs=1,ma=1,sar=1,sdiffs=1,sma=1,maxl,define=deq) writing
@acbjICRS deq writing

boxjenk(noconst,ar=0,diffs=1,ma=2,sar=0,sdiffs=1,sma=0,maxl,define=deq) writing
@acbjICRS deq writing
Running GCONTOUR version
- as individual models i.e clear memory each time and run each model seperately: plots correct inverse roots
- all 4 models back-to-back (as per in a loop) i.e. not clear memory and run all 4 models together: plots correct inverse roots

Running SCATTER version
- as individual models i.e clear memory each time and run each model seperately: plots correct inverse roots
- all 4 models back-to-back (as per in a loop) i.e. not clear memory and run all 4 models together: plots incorrect inverse roots


Attached
GCONTOUR version: acbjICRS_g.src
SCATTER version: acbjICRS_s.src

Re: procedure plotting the characteristic roots for ARIMA mo

Posted: Wed Apr 05, 2023 9:43 am
by TomDoan
So far as I can tell, it works fine.

Re: procedure plotting the characteristic roots for ARIMA mo

Posted: Wed Apr 05, 2023 1:56 pm
by ac_1
Attached are 2 plots running SCATTER (have included Hlabel="Real",Vlabel="Imaginary") version, for the last model

Code: Select all

boxjenk(noconst,ar=0,diffs=1,ma=2,sar=0,sdiffs=1,sma=0,maxl,define=deq) writing
@acbjICRS deq writing
the 1st being run individually: plot_s_IND_1.rgf
the 2nd being run from all 4 specifications back-to-back: plot_s_B2B_1.rgf

They are not the same, the 1st is correct, the 2nd is not.

The table from being run individually and from being run all 4 back-to-back is the same:

WRITING
inverse AR roots:
Real Imag Modulus Period
1.000 0.000 1.000
-1.000 -0.000 1.000
0.000 -1.000 1.000
-0.000 1.000 1.000 4.000
0.500 -0.866 1.000
0.500 0.866 1.000 6.000
-0.500 -0.866 1.000
-0.866 0.500 1.000 2.400
0.866 0.500 1.000 12.000
0.866 -0.500 1.000
-0.866 -0.500 1.000
-0.500 0.866 1.000 3.000
1.000 0.000 1.000
inverse MA roots:
Real Imag Modulus Period
0.167 0.000 0.167
0.743 0.000 0.743

Re: procedure plotting the characteristic roots for ARIMA mo

Posted: Wed Apr 05, 2023 4:44 pm
by TomDoan
I still can't reproduce your problem, but your method for handling the two graphs is wrong (and too complicated anyway). Just put the AR roots into the 1,1 pane and the MA roots into the 1,2 pane.

if (%size(arroots).ne.0) {
scatter(ROW=1,COL=1,style=dots,overlay=line,footer="If AR roots lie inside the unit circle ARIMA model is stationary", $
OVSAMESCALE,HMIN=-1.5,HMAX=+1.5,VMIN=-1.5,VMAX=1.5) 2
# arrealz arimagz
# unitr unitc
}

if (%size(maroots).ne.0) {
scatter(ROW=1,COL=2,style=dots,overlay=line,footer="If MA roots lie inside the unit circle ARIMA model is invertible", $
OVSAMESCALE,HMIN=-1.5,HMAX=+1.5,VMIN=-1.5,VMAX=1.5) 2
# marealz maimagz
# unitr unitc
}

Re: procedure plotting the characteristic roots for ARIMA mo

Posted: Thu Apr 06, 2023 7:57 am
by ac_1
On-my-side, regarding the 4 specifications as a back-to-back sequence only the last one plots incorrectly.

Attached is the latest SCATTER version: acbjICRS_s.src.

Re: procedure plotting the characteristic roots for ARIMA mo

Posted: Thu Apr 06, 2023 11:47 am
by TomDoan
Add a CLEAR instruction for the real and imag parts that you are graphing.

local series arrealz arimagz
local series marealz maimagz
local series unitr unitc

clear arrealz arimagz marealz maimagz


Which doesn't change the fact that this isn't going to provide any useful information.

Re: procedure plotting the characteristic roots for ARIMA mo

Posted: Thu Apr 06, 2023 2:53 pm
by ac_1
TomDoan wrote:Add a CLEAR instruction for the real and imag parts that you are graphing.

local series arrealz arimagz
local series marealz maimagz
local series unitr unitc

clear arrealz arimagz marealz maimagz
Works! Many thanks! :)
TomDoan wrote:Which doesn't change the fact that this isn't going to provide any useful information.
Maybe - however, within a recursive/rolling scheme it's easier to see the model structure, and I like the table with the numerical value's.

Although as previously stated
TomDoan wrote: I'm baffled about what you're trying to do. You *know* how many differences/seasonal differences you've done so you will know exactly how many unit roots you have. The AR parts are forced to be stationary by maximum likelihood. (There is no unconditional likelihood for a non-stationary model).

The MA's are also going to be forced inside or on the unit circle. An MA with a bad root has an equivalent model with the root flipped inside. (That has nothing to do with maximum likelihood). An MA with a unit root is permitted, but in practice would never be estimated since it's a boundary value, and is usually a sign of an overdifferenced model: for instance, if x is white noise, then x=u, so (1-L)x=(1-L)u so first differencing x induces a unit root MA process.

Visually it's better to define the inverse roots based on them being inside, on, or outside the complex unit circle with color. Is the indicator variables method the most appropriate way?

Re: procedure plotting the characteristic roots for ARIMA mo

Posted: Sat Apr 08, 2023 8:25 am
by TomDoan
My whole point is that the roots provide you with almost no useful information. You can have models with very different roots with very similar behavior. The dynamic behavior of an ARIMA model is a complex interaction between AR and MA parts and neither in isolation tells you much of anything.

Re: procedure plotting the characteristic roots for ARIMA mo

Posted: Mon Apr 10, 2023 4:37 am
by ac_1
TomDoan wrote:My whole point is that the roots provide you with almost no useful information. You can have models with very different roots with very similar behavior. The dynamic behavior of an ARIMA model is a complex interaction between AR and MA parts and neither in isolation tells you much of anything.
Acknowledged!


Would it be useful to include these explanations with each footer?

ARIMA model is stationary: AR roots lie inside the complex unit circle
ARIMA model has unit root(s): AR roots lie on the complex unit circle
ARIMA model is non-stationary: AR roots lie outside the complex unit circle

ARIMA model is invertible: MA roots lie inside the complex unit circle


I am having problems coloring the DOTS (a lot of code..., does not work for all scenario's, and there maybe DOTS on top of each other), as follows:
a) Generate Indicator Series: inside _0, on _1, outside _2
b) Remove NA's
c) Compute the number of obs
d) Scatter plot's for all 7 combinations

E.g. for the AR

Code: Select all

set arpatchz = %if( (%cabs(arroots(t)).eq.1.0), 1, 0)
set arpatchz = %if( (%cabs(arroots(t)).gt.1.0), 2, arpatchz)
set arrealz_0 1 %size(arroots) = %if(arpatchz == 0, %real(arroots(t)), %na); * inside
set arimagz_0 1 %size(arroots) = %if(arpatchz == 0, %imag(arroots(t)), %na); * inside
set arrealz_1 1 %size(arroots) = %if(arpatchz == 1, %real(arroots(t)), %na); * on
set arimagz_1 1 %size(arroots) = %if(arpatchz == 1, %imag(arroots(t)), %na); * on
set arrealz_2 1 %size(arroots) = %if(arpatchz == 2, %real(arroots(t)), %na); * outside
set arimagz_2 1 %size(arroots) = %if(arpatchz == 2, %imag(arroots(t)), %na); * outside
prin 1 %size(arroots) arpatchz arrealz_0 arimagz_0 arrealz_1 arimagz_1 arrealz_2 arimagz_2

set filter_missing = %valid(arrealz_0)
sample(smpl=filter_missing) arrealz_0 / arrealz_0
set filter_missing = %valid(arimagz_0)
sample(smpl=filter_missing) arimagz_0 / arimagz_0
prin / arrealz_0 arimagz_0

if (arrealz_0(t).ne.%na) {
stats arrealz_0
comp real_n0 = %nobs
}

* And for _1' s and _2's.

* Then all combinations for SCATTER

if (real_n0.ne.0).and.(real_n1.ne.0).and.(real_n2.ne.0) {
 SCATTER
}

else if (real_n0.ne.0).and.(real_n1.ne.0) {
 SCATTER
}

* etc

else if (real_n2.ne.0) {
 SCATTER
}

Re: procedure plotting the characteristic roots for ARIMA mo

Posted: Mon Apr 10, 2023 8:30 am
by TomDoan
An (x,y) where either x or y is %NA is simply skipped so you shouldn't need to do anything more than the set instructions as you've defined them. (In fact, you only have to do that for x or for y, not for both). You may have a problem with trying to do exact comparisons with 1.0 (for eq and gt)---the seasonals may have roundoff error. Anything between .9999999 and 1.0000001 should be considered to be 1. (It's probably more like 12 digits of accuracy, but 7 should be fine in practice).

Re: procedure plotting the characteristic roots for ARIMA mo

Posted: Tue Apr 11, 2023 4:51 am
by ac_1
TomDoan wrote: You may have a problem with trying to do exact comparisons with 1.0 (for eq and gt)---the seasonals may have roundoff error. Anything between .9999999 and 1.0000001 should be considered to be 1. (It's probably more like 12 digits of accuracy, but 7 should be fine in practice).
I can generate the DOTS with colors (all scenarios, AR models only) but the DOTS are not exactly on the complex unit circle.

Attached acbjICRS_s_c.src

Re: procedure plotting the characteristic roots for ARIMA mo

Posted: Tue Apr 11, 2023 2:00 pm
by TomDoan
You have the problem that I cited in the last reply---you are testing for exact 1's for calculations that will rarely be exact 1's. Try testing sin(x)^2+cos(x)^2==1 for various values of x, and you'll probably find half don't satisfy that. And the roots aren't even computed as exactly as sin and cos---roots are estimated to about eight digit precision.

But more important, you seem to be under the impression that if you change the labels, or make the graph more complicated, that you will get something useful out of it. You won't. The roots tell you basically nothing other than what you put into the model. If SDIFFS=1, you will get 12 unit roots equally spaced at the same locations regardless of whether SDIFFS=1 was a good choice. ARMA models are useful because for a wide variety of types of dynamic behavior, you can find an ARMA model which at least reasonably approximates it. In fact, they are particularly useful because sometimes there is more than one such model. There are series that are a reasonable fit for an AR(2), for an ARMA(1,1) and for a relatively low order MA. Those will have widely different root patterns even though they imply very similar dynamic behavior---because the AR and MA roots don't really tell you much.

Re: procedure plotting the characteristic roots for ARIMA mo

Posted: Wed Apr 12, 2023 4:21 am
by ac_1
TomDoan wrote:You have the problem that I cited in the last reply---you are testing for exact 1's for calculations that will rarely be exact 1's. Try testing sin(x)^2+cos(x)^2==1 for various values of x, and you'll probably find half don't satisfy that. And the roots aren't even computed as exactly as sin and cos---roots are estimated to about eight digit precision.
In the procedure I have included the following

Code: Select all

set unitr 1 1001 = %round(unitr, 8)
set unitc 1 1001 = %round(unitc, 8)
and rounded these to 8

Code: Select all

set arrealz_0 1 %size(arroots) = %round(arrealz_0, 8)
set arimagz_0 1 %size(arroots) = %round(arimagz_0, 8)
set arrealz_1 1 %size(arroots) = %round(arrealz_1, 8)
set arimagz_1 1 %size(arroots) = %round(arimagz_1, 8)
set arrealz_2 1 %size(arroots) = %round(arrealz_2, 8)
set arimagz_2 1 %size(arroots) = %round(arimagz_2, 8)
also print

Code: Select all

prin / unitr unitc arrealz_0 arimagz_0 arrealz_1 arimagz_1 arrealz_2 arimagz_2
In the main program run the following model

Code: Select all

boxjenk(const,diffs=0,sdiffs=1,ar=0,sar=0,maxl,define=deq) writing
@acbjICRS deq writing
Resulting in, (only first 12 printed the rest are NA's)

ENTRY UNITR UNITC ARREALZ_0 ARIMAGZ_0 ARREALZ_1 ARIMAGZ_1 ARREALZ_2
1963:01 1.00000000 0.00000000 NA NA 1.0000000 0.0 NA
1963:02 0.99998026 0.00628314 NA NA 0.0000000 1.0 NA
1963:03 0.99992104 0.01256604 NA NA -0.8660254 0.5 NA
1963:04 0.99982235 0.01884844 NA NA NA NA -0.5000000
1963:05 0.99968419 0.02513010 NA NA NA NA -0.5000000
1963:06 0.99950656 0.03141076 NA NA -0.0000000 -1.0 NA
1963:07 0.99928947 0.03769018 NA NA NA NA 0.5000000
1963:08 0.99903293 0.04396812 NA NA -1.0000000 0.0 NA
1963:09 0.99873696 0.05024432 NA NA NA NA 0.5000000
1963:10 0.99840155 0.05651853 NA NA NA NA 0.8660254
1963:11 0.99802673 0.06279052 NA NA NA NA -0.8660254
1963:12 0.99761251 0.06906003 NA NA NA NA 0.8660254


ENTRY ARIMAGZ_2
1963:01 NA
1963:02 NA
1963:03 NA
1963:04 -0.8660254
1963:05 0.8660254
1963:06 NA
1963:07 0.8660254
1963:08 NA
1963:09 -0.8660254
1963:10 -0.5000000
1963:11 -0.5000000
1963:12 0.5000000


WRITING
inverse AR roots:
Real Imag Modulus Period
1.000 0.000 1.000
0.000 1.000 1.000 4.000
-0.866 0.500 1.000 2.400
-0.500 -0.866 1.000
-0.500 0.866 1.000 3.000
-0.000 -1.000 1.000
0.500 0.866 1.000 6.000
-1.000 -0.000 1.000
0.500 -0.866 1.000
0.866 -0.500 1.000
-0.866 -0.500 1.000
0.866 0.500 1.000 12.000
inverse MA roots:
Real Imag Modulus Period


I would expect the following
_0's = all NA's
_1's = UNITR and UNITC, aligned but not exact to 8 digit say
_2's = all NA's

i.e. SDIFFS=1, 12 unit roots equally spaced with the DOTS colored BLACK on the BLUE complex unit circle, as calculated in the report/table.
TomDoan wrote: But more important, you seem to be under the impression that if you change the labels, or make the graph more complicated, that you will get something useful out of it. You won't.
No. It is useful as a visual-aid. Further via color's I am just trying to make the DOTS easier to define. The labels is an explanation for ease in interpretation. As previously stated IMHO this is already a lot of code to color DOTS based on boundary values!
TomDoan wrote: The roots tell you basically nothing other than what you put into the model. If SDIFFS=1, you will get 12 unit roots equally spaced at the same locations regardless of the whether SDIFFS=1 was a good choice. ARMA models are useful because for a wide variety of types of dynamic behavior, you can find an ARMA model which at least reasonably approximates it. In fact, they are particularly useful because someone there is more than one such model. There are series that are a reasonable fit for an AR(2), for an ARMA(1,1) and for a relatively low order MA. Those will have widely different root patterns even though they imply very similar dynamic behavior---because the AR and MA roots don't really tell you much.
I have gained a better appreciation for ARIMA modelling. Thanks.

Re: procedure plotting the characteristic roots for ARIMA mo

Posted: Wed Apr 12, 2023 8:01 am
by TomDoan
1. Why would you round the unit circle values? Those are just being graphed---you aren't doing any calculations with them.
2. Rounding the components of a complex number makes things worse (as you can see). You want to compute the modulus first and round *that*. Probably to four or five digits.

Re: procedure plotting the characteristic roots for ARIMA mo

Posted: Wed Apr 12, 2023 11:03 am
by ac_1
TomDoan wrote: 2. Rounding the components of a complex number makes things worse (as you can see). You want to compute the modulus first and round *that*. Probably to four or five digits.
In the procedure:

I have removed all rounding.

I have calculated the modulus and rounded to five digits - thus I have the following, before the plotting

Code: Select all

* AR indicator series
set arpatchz = %if((%cabs(arroots(t)).eq.1.0),1,0)
set arpatchz = %if((%cabs(arroots(t)).gt.1.0),2,arpatchz)
set arrealz_0 1 %size(arroots) = %if(arpatchz == 0, %real(arroots(t)), %na); * inside
set arimagz_0 1 %size(arroots) = %if(arpatchz == 0, %imag(arroots(t)), %na); * inside
set arrealz_1 1 %size(arroots) = %if(arpatchz == 1, %real(arroots(t)), %na); * on
set arimagz_1 1 %size(arroots) = %if(arpatchz == 1, %imag(arroots(t)), %na); * on
set arrealz_2 1 %size(arroots) = %if(arpatchz == 2, %real(arroots(t)), %na); * outside
set arimagz_2 1 %size(arroots) = %if(arpatchz == 2, %imag(arroots(t)), %na); * outside

prin / unitr unitc arrealz_0 arimagz_0 arrealz_1 arimagz_1 arrealz_2 arimagz_2

set armodz_0 1 %size(arroots) = %if(arpatchz == 0, %cabs(arroots(t)), %na); * inside
set armodz_1 1 %size(arroots) = %if(arpatchz == 1, %cabs(arroots(t)), %na); * on
set armodz_2 1 %size(arroots) = %if(arpatchz == 2, %cabs(arroots(t)), %na); * outside
set armodz_0 1 %size(arroots) = %round(armodz_0, 5)
set armodz_1 1 %size(arroots) = %round(armodz_1, 5)
set armodz_2 1 %size(arroots) = %round(armodz_2, 5)

prin / armodz_0 armodz_1 armodz_2

set arres_0 = %if(%valid(arrealz_0),1,0)
set arres_1 = %if(%valid(arrealz_1),1,0)
set arres_2 = %if(%valid(arrealz_2),1,0)

stats(noprint) arres_0
comp arreal_n0 = %mean
stats(noprint) arres_1
comp arreal_n1 = %mean
stats(noprint) arres_2
comp arreal_n2 = %mean
In the main program:

run the same model

Code: Select all

boxjenk(const,diffs=0,sdiffs=1,ar=0,sar=0,maxl,define=deq) writing
@acbjICRS deq writing
the rounded values are:

ENTRY ARMODZ_0 ARMODZ_1 ARMODZ_2
1963:01 NA 1 NA
1963:02 NA 1 NA
1963:03 NA 1 NA
1963:04 NA NA 1
1963:05 NA NA 1
1963:06 NA 1 NA
1963:07 NA NA 1
1963:08 NA 1 NA
1963:09 NA NA 1
1963:10 NA NA 1
1963:11 NA NA 1
1963:12 NA NA 1


How to proceed?