On Wed, 2 Mar 2011, Sam Sam wrote:
I run ARIMA(1,0,1) by conditional maximum likelyhood.
the residual is :
table1:
uhat2
1980:01
1980:02 -5.421687
1980:03 -0.506024
1980:04 1.867470
1980:05 1.698795
I choose the options /Graphs/--/Risidual correlogram/
output of Residual autocorrelation function shows:
table2:
LAG ACF PACF Q-stat. [p-value]
1 0.1567 0.1567 0.1964 [0.658]
2 -0.3373 -0.3710 1.5619 [0.458]
3 -0.3194 -0.2244 4.0097 [0.260]
I caucualte Q-statistic by the formulation of Ljung-Box statistc from table1,
but the values I cauculate by myself seem not equal to the values of table2 (0.1964,
1.5619, and 4.0097)
Maybe I mistake somewhere.
Here is a script that calculates ACF and Q just as gretl does,
using the residuals you got:
<script>
function scalar acf (int k, series y, scalar ybar)
scalar num = 0
scalar den = 0
t1 = $t1
t2 = $t2
loop for (t=t1; t<=t2; t++) --quiet
z = y[t] - ybar
den += z * z
if t - k >= t1
num += z * (y[t-k] - ybar)
endif
endloop
return num / den
end function
function scalar LBQ (series y, int m)
scalar ybar = mean(y)
scalar T = $nobs
scalar LB = 0
# calculate acf up to lag m, cumulating LB
loop for (k=1; k<=m; k++) --quiet
a = acf(k, y, ybar)
LB += a * a / (T - k)
endloop
LB *= T * (T + 2.0)
return LB
end function
nulldata 5
setobs 12 1980:01 --time-series
series uhat2
smpl 1980:02 ;
uhat2 = {-5.421687, -0.506024, 1.867470, 1.698795}'
# do the calculation manually
lb = LBQ(uhat2, 1)
lb = LBQ(uhat2, 2)
lb = LBQ(uhat2, 3)
# compare gretl's built-in function
lb = ljungbox(uhat2, 1)
lb = ljungbox(uhat2, 2)
lb = ljungbox(uhat2, 3)
</script>
Allin Cottrell