#

#
STATISTICAL TIME SERIES ANALYSIS (STSA) module for O-Matrix.

#

# Written by Dr.
Dimitrios D. Thomakos

#

# e-mail:
thomakos@uop.gr

#

# STSA Version 2.0

#

# Example file #17

#

# In
this file the following functions are demonstrated:

#

# acvf_spectrum

# ar_order

# ar_spectrum

# arma_simulate

# plot_spectrum

# spectrum

#

# Initialize

clear

ginit

clc

# Simulate an
autoregressive model with an deterministic oscillating component

mu = 0.

phi = { 0.6, 0.2 }

theta = 0.

sigma = 0.4

N = 400.

u = arma_simulate(mu,phi,theta,sigma,N)

# Add the
deterministic component here

A = 0.7

B = -1.

omega = 2*pi*(12./N)

t = seq(int(N))

r = A%sin(omega*t+B)

# Put
them together

x = r + u

# Plot the
deterministic component and the series

gcolor({"black","green"})

gxaxis("linear",0,N,10)

gplot(r)

gplot(x)

# Compute the power
spectrum of the series using three methods;

# plot the output of
the first method using the plot_spectrum function

# and
the output of the other two methods together in a new window

#

# First method:
smooth the periodogram using a sine taper

K = 15.

[f,S1]
= spectrum(x,1,K)

plot_spectrum(f,S1,"linear",1,"X - first
method")

# Second method:
smooth the autocovariances

M = 100.

[f,S2]
= acvf_spectrum(x,M)

# Third method:
autoregressive approximation

# first
we select the order

[aic,bic]
= ar_order(x,12,1,1)

print "Selected AICc order = ", aic(1,1)

print "Selected BIC order = ", bic(1,1)

print

# then estimate
using the AICc order

[f,S3]
= ar_spectrum(x,aic(1,1),1)

# Now,
plot the second and thid method spectra

gaddwin("Spectra second (blue) and third (red)
methods")

gxaxis("linear",0,0.5,10)

gxtitle("Frequency")

gytitle("Power")

gcolor({"blue","red"})

gplot(f,[S2,S3])

print "You can manually adjust the following
parameters in experimenting with the"

print "different methods of spectral
estimation:"

print

print "sigma : controls the noise of the
series"

print "K : number of sine tapers used in the
first method"

print "M : number of autocovariances used in
the second method"

print

print "You can also try out different orders
for the autoregressive spectral"

print "estimation without having to estimate
the orders using the AICc and BIC criteria"

print