*
* Robinson, JASA, December 1994
* Series B (Box-Jenkins IBM stock data)
*
open data "ibm-stock.txt"
data(format=free,org=var) 1 369 ibmstock
*
* Make the hypothesized difference of the data (1-L)^1 to create U-tilde
*
diff ibmstock / dseries
*
* Compute the variance of U-tilde
*
stats dseries
compute sigsq=%variance
*
compute endl=369,startl=2
*
compute n = endl-startl+1
*
freq 1 n
rtoc startl endl 1
# dseries
# 1
*
* Compute the periodogram and the psi function
*
fft 1
cmult(scale=1.0/(2*%pi*n)) 1 1
set pgram 1 n = %real(%z(t,1))
set psi 1 n = log(2 * abs(sin(-%pi*(t-1)/n)))
*
* Compute the sums of lambda to make small a-tilde and big A-tilde.
* Avoid the undefined value for psi at t=1 (zero frequency)
*
sstats 2 n 2.0*psi^2>>bigA
sstats 2 n -2.0*%pi*psi*pgram>>smallA
compute bigA=bigA/n,smallA=smallA/n
*
* This is closed form value rather than the value approximated off the sum
*
*compute bigA=%pi^2/6.0
*
* This is the chi-squared statistic
*
compute r=n*smalla^2/(bigA*sigsq^2)
*
* This is the one-tailed equivalent
*
compute onetail=sqrt(n)*smalla/(sqrt(bigA)*sigsq)
disp "Chi-Squared" r "One-tail" onetail
Users browsing this forum: No registered users and 2 guests