*
*  @CUMPDGM   series  start  end
*     Performs a Durbin's Cumulated Periodogram for serial correlation.
*     The test statistic is a Kolmogorov-Smirnov statistic.  Check advanced
*     statistics books for a table of significance points.
*
*  Reference: J. Durbin, "Tests for Serial Correlation in Regression
*     Analysis Based on the Periodogram of Least Squares Residuals",
*     Biometrika, 1969, 1-16.
*
*  Revision Schedule:
*    January, 1992   - Converted to RATS 4.0, Rejection Limits Added
*    February, 1995  - Added symbol font Xlabels, GRTEXT
*
procedure cumpdgm series start end
type series series
type integer start end

local integer nobs startl endl span ordinate half
local series  white_noise actual freqs
local string  gaplabel

if .not.%defined(series) {
   display 'Syntax: @CUMPDGM   series  start  end'
   return
}

inquire(series=series)  startl>>start   endl>>end

compute nobs=endl-startl+1
compute ordinate=%freqsize(nobs)

compute half = (ordinate+1)/2

frequency 3 ordinate
rtoc(pad)  startl  endl  1
# series
#   1
fft 1
cmult 1 1
cacc(scale) 1 1 half
cunits 2
cacc(scale) 2 1 half
cset 3 1 half = %z(t,1)-%z(t,2)
cxt(noprint,part=absval) 3 1 half
display 'Cumulated Periodogram Test for Series' %LABEL(SERIES)
display 'Maximum Gap = ' #.#### %MAXIMUM 'At Frequency' #.####  $
    2*%pi*float(%maxent)/ordinate
display 'Approximate Rejection Limits'
display '1% = ' #.#### 1.63/SQRT(HALF) $
        '5% = ' #.#### 1.36/SQRT(HALF) $
        '10% = ' #.#### 1.22/SQRT(HALF)
*
*
*
ctor 1 half
# 1 2
# actual white_noise
label actual white_noise
# 'Actual' 'White Noise'
set freqs 1 half = t-1
*
grparm(font='symbol') axislabels *
spgraph
scatter(style=line,key=upleft,header='cumulated periodogram test',xlabels=||'0','p/4','p/2','3p/4','p'||) 2
# freqs white_noise 1 half
# freqs actual      1 half
display(store=gaplabel) 'gap = ' #.#### %maximum
if actual(%maxent)<white_noise(%maxent)
   grtext(alignment=left,x=%maxent-1,y=actual(%maxent)-.01) gaplabel
else
   grtext(alignment=right,x=%maxent-1,y=actual(%maxent)+.01) gaplabel
spgraph(done)
end

