On Mon, 30 Nov 2009, Sven Schreiber wrote:
Costia schrieb:
> 2. I haven't found a Q-Q plot test in GRETL, (like in SAS e.g.). I think
> it would be a good thing to add it.
I agree. It's not difficult to use a quick-and-dirty script to get it
done, but properly handling missing values etc. needs more care.
I haven't messed much with Q-Q plots. Can anyone confirm if the
following script is correct? If so, then I guess we could do it
as a built-in at some point.
<script>
nulldata 500
scalar n = $nobs
# artificial series to test
genr y = sort(normal())
series Qemp, Qnorm
scalar p, N, nl, nh
loop i=1..n -q
p = i/(n+1)
N = (n + 1) * p - 1;
nl = floor(N);
nh = ceil(N);
if (nh == 0 || nh == n)
Qemp[i] = NA
else
Qemp[i] = quantile(y, p)
endif
Qnorm[i] = critical(N, 1-p)
endloop
store @dotdir/gpdata.dat Qemp Qnorm --traditional
set echo off
outfile @dotdir/qq.gp --write
print "set datafile missing '-999'"
print "set nokey"
print "set xlabel 'Normal quantiles'"
print "set ylabel 'Empirical quantiles'"
print "plot '(a)dotdir/gpdata.dat', x"
outfile --close
if WIN32
launch @gnuplot @dotdir/qq.gp
else
launch @gnuplot -persist @dotdir/qq.gp
endif
</script>
Allin.