FAQ/fried - CBU statistics Wiki

Revision 1 as of 2007-08-16 13:53:15

Clear message
location: FAQ / fried

= How do I do pairwise comparisons using Friedman's test? =

The syntax below performs a specified pairwise comparison between a subset pair of groups representing the within subject factor.

* Compares test performance (rows)
* over time at pre, mid and post (columns)
*
* 

data list free/
t1 t2 t3.

begin data
1 3 5
21 25 27
0.2 0.1 0.1
2  1  3
end data.


* macro assumes columns called t1 to tn
* contain matched scores on the within subject
* factor e.g. time.
*
* pairf takes as inputs: the two columns to compare 
* and the total number of columns
*
* output is a t-statistic, its df, unadjusted * 2-tailed p-value and the two columns which * have been compared


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

VARSTOCASES /ID = id
 /MAKE test FROM t1 to !concat(t,!3)
 /INDEX = time(3)
 /KEEP =
 /NULL = KEEP.


RANK VARIABLES=test (A) by id
/RANK 
/PRINT=YES 
/TIES=MEAN . 
compute rtestsq=rtest*rtest. 
exe. 

aggregate outfile=*
/break = time
/rtsum rtsumsq=sum(rtest rtestsq)
/nsize = n(rtest).

matrix.
get m /variables=time rtsum rtsumsq nsize.
compute stsum=make(1,1,0).
loop i = 1 to mmax(m(:,1)).
compute stsum=stsum+((m(i,2))**2)/m(i,4).
end loop.
compute srsum=csum(m(:,3)).
compute tn=mmax(m(:,1)).
compute bn=mmax(m(:,4)).
compute #ct1=m(!1,2)-m(!2,2).
compute ct2=#ct1 / sqrt((2*bn*(srsum-stsum))/((bn-1)*(tn-1))).
compute ct3=1-fcdf(ct2*ct2,1,(bn-1)*(tn-1)).
save {ct2, (bn-1)*(tn-1), ct3, !1, !2} /outfile=*
 /variables=tstat, df, pvalue, group_1, group_2.
end matrix. 
formats tstat (f7.3) df (f4.0) pvalue (f5.3) group_1 (f2.0) group_2 (f2.0).
report format=list automatic align(center) 
/variables=tstat df pvalue group_1 group_2
/title "Unadjusted comparisons for method" 
"of Sprent and Smeeton (2001) for Friedman test" 
" " " NB: This test is only valid if the Friedman test is statistically"
 " significant overall using all the groups". 

!enddefine.

pairf 1 3 3.