FAQ/kw - CBU statistics Wiki

Revision 1 as of 2006-08-15 11:28:06

Clear message
location: FAQ / kw

Describe FAQ/kw here.

*
Example data set below
{{{
data list free/
 y group.

begin data
9 1
9 1
1 1
2 1
4 2
5 2
7  2
12 2
6 3
7 3
9 3
8 3
6 3
2 3
5 3
end data.

After opening a spreadsheet containing y (response) and group columns you can run the SPSS Macro syntax below: [ CUT AND PASTE INTO A SPSS SYNTAX WINDOW, SELECT ALL AND RUN; SPECIFY TWO GROUPS TO BE COMPARED IN LAST LINE]

 performs Sprent & Smeeton (2001) method of pairwise comparisons for kruskal-wallis test
*
* Data file containing just the two columns called y and group
* inputs are specified groups to being compared 
* This test is only valid if the overall Kruskal-Wallis test is statistically significant
*
* results are saved to output.sav which appears in My Documents folder and are outputted
* in SPSS output window
*
* reference Sprent, P. and Smeeton, NC (2001) Applied Nonparametric Statistical Methods.
* Chapman and Hall:London.


* inputs groups to be compared 

set errors=none.
set mprint=off.

define !kwpairs ( !pos !tokens(1)
                       / !pos !tokens(1)).

RANK
  VARIABLES=y  (A)   /RANK /PRINT=YES
  /TIES=MEAN .
compute rysq=ry*ry.
exe.

aggregate outfile=* 
 /break=group
 /sumy sumysq= sum(ry rysq)
 /nsize=n(ry).

compute mrk = sumy/nsize.
compute suma = sumy*sumy/nsize.
compute con=1.
exe.

* input which two groups to be compared

if (group=!1) m1=sumy/nsize.
if (group=!2) m2=sumy/nsize.
if (group=!1) nx=nsize.
if (group=!2) ny=nsize.
exe.

aggregate outfile=* 
 /break=con 
 /con2 ssq= sum(suma sumysq)
 /ng=max(group)
 /mn1 mn2 = first(m1 m2)
 /n1 n2 = first(nx ny)
 /ntot=sum(nsize).

compute #con1=ntot*(ntot+1)*(ntot+1)/4.
compute #con3= (ntot-1)*(con2-#con1).
compute #con4= #con3/(ssq-#con1).
compute #con5=(ntot-1-#con4)*(n1+n2).
compute con6=(ssq-#con1)*(#con5).
compute con7=(n1*n2)*(ntot-ng)*(ntot-1).

* Just use two-tailed uncorrected t
* Given overall K-Wallis is statistically significant ie LSD equivalent

compute twot=2.

compute cd025= mn1-mn2 + idf.t(0.05/twot,ntot-ng)*sqrt(con6/con7).
compute cd975= mn1-mn2 - idf.t(0.05/twot,ntot-ng)*sqrt(con6/con7).
compute pv = cdf.t(-abs(mn1-mn2) / sqrt(con6/con7),ntot-ng).

save outfile=output.sav /keep = mn1 mn2 cd025 cd975 pv.
exe.

get file=output.sav.
compute odiff=abs(mn1 - mn2).
exe.

formats all (f11.8).
variable labels mn1 'Mean Rank Group 1' /mn2 'Mean Rank Group 2' / odiff 'Observed difference' /pv ' Uncorrected Two-tailed P-Value'
         / cd025 '95% CI L ' / cd975 '95% CI U'.

report format=list automatic align(center)
  /variables=mn1 mn2 odiff pv cd025 cd975
  /title "Pairwise comparisons using Bonferroni adjustments for method"
         "of Sprent and Smeeton (2001) for Kruskal-Wallis test"
         " 95% Confidence Interval for difference in means ranks in (L,U)"
         "                                                                                          "
         " NB: This test is only valid if the Kruskal-Wallis test is statistically"
         " significant overall using all the groups".

!enddefine.

* specify (numeric) pair of groups to be compared

!kwpairs 2 3.

* raw means may be outputted using

MEANS

  • TABLES=y BY group /CELLS MEAN COUNT STDDEV .