Spectrum

Questions and discussions on Time Series Analysis
ivory4
Posts: 144
Joined: Mon Aug 24, 2009 12:16 pm

Spectrum

Unread post by ivory4 »

According to BN decomposition, Cycle is defined to be Psi(L)(et)
Psi(L) is defined to be (P(L)-P(1))/(1-L), P(L)=Theta(L)/Phi(L), Thetas are MA coefficients and Phis are AR coefficients.

C_t=Psi(L)e_t
Spe(C_t)=|PSI(L)|^2Sig_e^2/2PI

I tried to draw Spectrum of C_t and delta(C_t)

The latter seems to be

Code: Select all

equation(noconstant,coeffs=||-%beta(4), -%beta(5),-%beta(2), -%beta(3)||) arma22 y 2 2  

* %beta() is from Boxjenk function, I switch the order of AR and MA coefficients in order to get Theta(z)/Phi(z) directly

frequency 2 512
trfunc(equation=arma22) 1
cset 2 = %z(t,1)-%z(1,1)
cmult(scale=(2*%pi)/scale) 2 2

ctor 1 256
# 2
# ab
set bn_spect 1 256 = ab
But How to draw C_t?

Code: Select all

* continue from previous case
cset 1= 2/(1-%zlag(t,1)
cmult(scale=(2*%pi)/scale) 1 1
?

I end up with C_t's spectrum at zero frequency extremely high which is consistent with deltaCt's zero spectrum at zero frequency.
Is there a way that I use spectrum at some smal positive frequency to guess this zero frequency?
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: Spectrum

Unread post by TomDoan »

ivory4 wrote:According to BN decomposition, Cycle is defined to be Psi(L)(et)
Psi(L) is defined to be (P(L)-P(1))/(1-L), P(L)=Theta(L)/Phi(L), Thetas are MA coefficients and Phis are AR coefficients.

C_t=Psi(L)e_t
Spe(C_t)=|PSI(L)|^2Sig_e^2/2PI

I tried to draw Spectrum of C_t and delta(C_t)

The latter seems to be

Code: Select all

equation(noconstant,coeffs=||-%beta(4), -%beta(5),-%beta(2), -%beta(3)||) arma22 y 2 2  

* %beta() is from Boxjenk function, I switch the order of AR and MA coefficients in order to get Theta(z)/Phi(z) directly

frequency 2 512
trfunc(equation=arma22) 1
cset 2 = %z(t,1)-%z(1,1)
cmult(scale=(2*%pi)/scale) 2 2

ctor 1 256
# 2
# ab
set bn_spect 1 256 = ab
But How to draw C_t?

Code: Select all

* continue from previous case
cset 1= 2/(1-%zlag(t,1)
cmult(scale=(2*%pi)/scale) 1 1
?

I end up with C_t's spectrum at zero frequency extremely high which is consistent with deltaCt's zero spectrum at zero frequency.
Is there a way that I use spectrum at some smal positive frequency to guess this zero frequency?
Obviously, there is a problem evaluating this directly at 0 frequency:

(P(L)-P(1))/(1-L)

since it's 0/0. Because of round-off errors, you can get almost anything when you try to compute it. You can apply L'Hopital's rule to the z transform to evaluate it exactly at z=0, though you can also just use the limit of nearby values.
ivory4
Posts: 144
Joined: Mon Aug 24, 2009 12:16 pm

Re: Spectrum

Unread post by ivory4 »

TomDoan wrote: since it's 0/0. Because of round-off errors, you can get almost anything when you try to compute it. You can apply L'Hopital's rule to the z transform to evaluate it exactly at z=0, though you can also just use the limit of nearby values.
The nearby ones, I think at least many of them are extremely high. If zero frequency is estimated using L'Hopital'rule, then a hump near zero frequency would be created. To adjust them using analytical spectrum (after L'Hopital's rule applied to the z transform to evaluate it exactly at z=0) or it is better to use right side values ( I mean frequency corresponding bigger w)
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: Spectrum

Unread post by TomDoan »

Since L'Hopital's rule is exact, you would prefer that over an eyeball limit from nearby values.
ivory4
Posts: 144
Joined: Mon Aug 24, 2009 12:16 pm

Re: Spectrum

Unread post by ivory4 »

If I would like to draw Theoretical spectrum of various ARIMA model, is it better to use @specth ?
I check the source and found that it requires ACFMORIN.SRC instead of ACF.SRC
And also the default for NCOV is 20 instead of 200.

I add this one to the original src and the example in the file, but RATS still says that ACFMORIN is not a procedure (did you forget to source?)

Code: Select all

Source(noecho) acfmorin.src

Code: Select all

 ALL 250
 DECL VECT a(2) b(1) c(1)
 INPUT(unit=keyboard) a b c
 -.3 .2
 .8
 .5

 SOURCE(NOECHO) POLYMULT.SRC
 @POLYMULT(span=12) a b ab
 DECL vect invec(15)
 DO i = 1,14
	COMPUTE invec(i) = ab(i)
 END DO
 COMPUTE invec(15) = c(1)
 SOURCE(noecho) ACFMORIN.SRC
 SOURCE(noecho) SPECTH.SRC
 @SPECTH(nfreq=201,ncov=250,ma=1) invec specs freqs
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: Spectrum

Unread post by TomDoan »

Use ARMASPECTRUM rather than SPETHE.
ivory4
Posts: 144
Joined: Mon Aug 24, 2009 12:16 pm

Re: Spectrum

Unread post by ivory4 »

For comparison purpose;

Code: Select all

all 1000
set y = 0.0
equation(variance=1.0, coeffs=||0.0,1.4,-0.8||) arma y 2 0
simulate(from=3, step=998) 1
# arma y
@spectrum y
@armaspectrum y

When I try to simulate data with non-stationary coeffs like AR(1)=1.4 or AR(2)=1.9, -0.5; SIMULATE does not generate data but instead filled y with "F" ?
SPECTRUM in this case still generate graph if ALL 1000 while STEP=100; Otherwise it generates blank graph.

What is wrong here?
Last edited by ivory4 on Sun Dec 26, 2010 11:08 am, edited 2 times in total.
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: Spectrum

Unread post by TomDoan »

ivory4 wrote:For comparison purpose;

Code: Select all

all 1000
set y = 0.0
equation(variance=1.0, coeffs=||0.0,1.4,-0.8||) arma y 2 0
simulate(from=3, step=998) 1
# arma y
@spectrum y
@armaspectrum y
When I try to simulate data with non-stationary coeffs like AR(1)=1.4 or AR(2)=1.9, -0.5; SIMULATE does not generate data but instead filled y with "F" ?
SPECTRUM in this case still generate graph if ALL 1000 while STEP=100; Otherwise it generates blank graph.

What is wrong here?
The SPECTRUM seems to be OK. It's the ARMASPECTRUM, which takes the equation (ARMA) rather than the series Y as the input.
ivory4
Posts: 144
Joined: Mon Aug 24, 2009 12:16 pm

Re: Spectrum

Unread post by ivory4 »

Question when (1-L) is involved
Equation looks like this: yt=PSI(L)(et-et-1) (Yt=Phi*1Y_t-1+Phi2*Y_t-2+e_t - e_t-1)

To draw arma spectrum of yt, which of the following is correct?

Code: Select all

equation(noconstant,coeffs=||@@, @@,-1||) arma21 y 2 1 
frequency 1 512
com scale=@@^2
trfunc(equation=arma21) 1 
cmult(scale=(2*%Pi)/scale) 1 1 
cset 1 =1.0/%z(t,1)
ctor 1 256
# 1
# abc
OR

Code: Select all

equation(noconstant,coeffs=||@@, @@||) arma y 2 0 
frequency 1 512
com scale=@@^2
trfunc(equation=arma) 1
cset 1 = (1-%zlag(t,1))/%z(t,1)
cmult(scale=(2*%Pi)/scale) 1 1 
ctor 1 256
# 1
# abc
It seems that the graph look the same but the scale is different now. The former seems to be more reasonable.

How to fix it ?


Thanks :-)
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: Spectrum

Unread post by TomDoan »

In the first case, you're squaring, then inverting; in the second, you're inverting, then squaring. But you're using the same scale factor in the square in both cases, which can't be correct. You need to multiply in one and divide in the other.
ivory4
Posts: 144
Joined: Mon Aug 24, 2009 12:16 pm

Re: Spectrum

Unread post by ivory4 »

Equation: yt=PSI(L)(et-et-1) and assume we do not have MA terms here and only AR(2) terms.

I correct the squaring error in previous post

The spectrum are still not the same. What is the reason? Which calculation is wrong?

ivory4 wrote:

Code: Select all

equation(noconstant,coeffs=||@@, @@,-1||) arma21 y 2 1 
frequency 1 512
com scale=@@^2
trfunc(equation=arma21) 1 
cmult(scale=(2*%Pi)/scale) 1 1 
cset 1 =1.0/%z(t,1)
ctor 1 256
# 1
# abc

*****same as******
cset 1 =(1.0-@@*%zlag(t,1)-@@*%zlag(t,2))/(1.0-%zlag(t,1))
com scale=@@^2
cmult(scale=(2*%Pi)/scale) 1 1 
cset 1 =1.0/%z(t,1)
ctor 1 256
# 1
# abc

OR

Code: Select all

equation(noconstant,coeffs=||@@, @@||) arma y 2 0 
frequency 1 512
com scale=@@^2
trfunc(equation=arma) 1
cmult(scale=(2*%Pi)/scale) 1 1 
cset 1 = (1-%zlag(t,1))/%z(t,1)
ctor 1 256
# 1
# abc
Another problem is when we have MA terms, say et-et-1 follow MA(1), then the first approach (especially the part below ******the same as******) is very different from the second approach.

Code: Select all

****when MA terms exist***********
cset 1 = (1.0-@@*%zlag(t,1)-@*%zlag(t,2))/((1.0+##*%zlag(t,1))*(1.0-%zlag(t,1)))
Or I think the following is correct?

Code: Select all

equation(noconstant,coeffs=||%beta(4),%beta(5),%beta(6)-1.0,-1.0*%beta(6)||) arma y 2 2
          frequency 1 512
          trfunc(equation=arma) 1
          com scale = ###^2    
          cmult(scale=(2*%pi)/scale) 1 1
          cset 1 =1.0/%z(t,1) 
          ctor 1 256
          # 1
          # ab

TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: Spectrum

Unread post by TomDoan »

It might be easier to understand if ARMASPECTRUM had been written like this:

Code: Select all

trfunc(equation=eqn) 1
cmult 1 1
*
* Take the scaled reciprocal and send half of the resulting series back to the
* time domain.
*
cset 1 = (scale/(2*%pi))/%z(t,1)
Multiplying by sigma^2/(2pi) is the final step after you've finished manipulating the squared transfer function. The spectral density is

sigma^2/(2*pi)*|C(w)|^2

where C(w) is the transfer function from epsilon to y. Since TRFUNC generates the transfer from Y to epsilon (not epsilon to Y), you need the reciprocal of the squared transfer function to make the |C(w)|^2.
ivory4
Posts: 144
Joined: Mon Aug 24, 2009 12:16 pm

Re: Spectrum

Unread post by ivory4 »

What I got wrong is the use of (1-%zlag(t,1) to represent (1-L) part after calculating |C(w)|^2, when I have the equation like (1-Phi(L))yt=THETA(L)(1-L)et

Now I define the EQUATION using parameters in Phi(L) and Theta(L) by expanding Theta(L)(1-L)

Code: Select all

equation(noconstant,coeffs=||phi1, phi2, theta1-1,-theta1||) arma21 y 2 1 
Then with TRFUNC and CMULT to square, CSET to invert, it seems correct.
Post Reply