Statistics and Algorithms / Spectral Analysis / Getting Output |
Use CPRINT to print complex series. You can also use DISPLAY or WRITE to print individual complex numbers or expressions. Other types of output (such as graphics) will require you to transfer data to real series (see below).
Reducing Ordinates
CPRINT can produce a vast amount of output when you have a long series or have padded it substantially. Since spectral densities and related functions are usually quite smooth, you lose little by printing just a subset of the frequencies. You can use the INTERVAL option on CPRINT to pick entries at a regular interval.
Also, because a spectral density is symmetric about 0 and a cross-spectral density is conjugate-symmetric, you really only need to look at frequencies 0 to \(\pi\). In RATS, these are entries 1 to \(\left( {{T \mathord{\left/{\vphantom {T 2}} \right.} 2}} \right) + 1\). If you cut the frequencies down to half in this way, use the option LENGTH=\(T\) on CPRINT so the entries will be labeled properly.
This cuts 288 ordinates by printing just half (to 144) then picking every 4th one.
cprint(lc=freq,length=288,interval=4) 1 144 3
Using GRAPH and SCATTER for Complex Series
Neither GRAPH nor SCATTER is designed to handle complex series directly, but you can use them to graph a real series which has been sent from the frequency domain using CTOR.
You can use either instruction to graph a spectral function. Each has minor advantages and disadvantages—we will demonstrate both.
GRAPH is good for quick views. The only drawback for this is that GRAPH will want to label the horizontal axis as if you were graphing a time series and not a function of frequencies. The option NOTICKS is handy to suppress the misleading labeling.
If you graph a spectral density estimate, the values will usually have a huge range. The peak values can easily be many orders of magnitude larger than most. Remember that this is a decomposition of the variance, so size differences get squared. In most cases it is more useful to graph the log of the spectrum rather than the spectrum. You can do this either by taking the log first, or by using the LOG option on GRAPH, such as LOG=10. For SCATTER, the analogous option is VLOG=10.
SCATTER is better for “production” graphs. It can do a better job of handling the “frequency” axis, though that comes at the cost of some additional instructions to create a series to represent the frequencies, of the form:
set frequencies = (t-1.0)/N
where “N” depends upon how much of the frequency range you’re graphing. The scaling doesn’t affect the appearance of the graph itself, just the labeling on the x axis.
Suppose you are graphing half the frequencies (thus 0 to \(\pi\)). If you use (T–1.0) divided by the number of frequencies, the x axis will run from 0 to 1.0 and is thus showing the fractions of \(\pi\). A slight change to
set frequencies = 6.0*(t-1.0)/N
would map the x-axis to 0.0 to 6.0. The integer x-values would be multiples of \({\pi \mathord{\left/{\vphantom {\pi 6}} \right.} 6}\), which are the harmonics for monthly data. The ultimate in fancy labeling uses the XLABELS option. This allows you to specify full strings which are equally spaced across the x axis. Using, for instance, XLABELS=||"0","p/6","p/3","p/2","2p/3","5p/6","p"|| will, when combined with the instruction
grparm(font="symbol") axislabels 12
give you labels of \(0,{\kern 1pt} {\kern 1pt} {\kern 1pt} {\pi \mathord{\left/{\vphantom {\pi 6}} \right.} 6},{\kern 1pt} {\kern 1pt} {\kern 1pt} {\pi \mathord{\left/{\vphantom {\pi 3}} \right.} 3}\), etc.
The following example is taken from the SPECTRUM.SRC procedure file. HALF is half the number of frequencies. The spectral density is plotted on a log scale.
ctor 1 half
# 2
# spect
set frequencies 1 half = (t-1.0)/half
scatter(style=lines,header=header,$
hlabel="Fractions of Pi",vlog=10.0) 1
# frequencies spect 1 half
Copyright © 2025 Thomas A. Doan