Diff for "FAQ/kw" - CBU statistics Wiki
location: Diff for "FAQ/kw"
Differences between revisions 2 and 3
Revision 2 as of 2006-08-15 11:34:47
Size: 4066
Editor: PeterWatson
Comment:
Revision 3 as of 2006-08-15 11:35:37
Size: 4127
Editor: PeterWatson
Comment:
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
Line 6: Line 5:
As a further precaution Bonferroni/Sidak or Ryan adjustments to outputted p-values could be used. SPSS Syntax to perform these using uncorrected p-values as input is in the pipeline. As a further precaution Bonferroni, Sidak, Holm or Ryan adjustments to outputted p-values could be used. SPSS Syntax to perform these using uncorrected p-values as input is in the pipeline. For further details see the Graduate Statistics Seminar.

No procedure exists in SPSS for performing post-hoc pairwise group comparisons when the Kruskal-Wallis nonparametric test is used. Kruskal-Wallis compares three or more groups and is the nonparametric analogue of the on-way anova.

The below syntax implements one solution to this. To guards against false positive results the authors suggest only specific comparisons should be tested and only if the overall Kruskal-Wallis test is significant. (as in the LSD approach for t-tests).

As a further precaution Bonferroni, Sidak, Holm or Ryan adjustments to outputted p-values could be used. SPSS Syntax to perform these using uncorrected p-values as input is in the pipeline. For further details see the Graduate Statistics Seminar.

*
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 group means may be outputted using analyze: compare means:means in the menu or the below syntax.

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

None: FAQ/kw (last edited 2018-01-05 12:45:54 by PeterWatson)