*********************************************************************** * FRIEDMAN-TEST APPLIED TO DATA OF CONOVER * * WITH MCP OF HOLM (1979) (F-APPR) * ***********************************************************************; *------------------------------------------------------------------* | QUESTIONS ? | | | | ---> Dr. Ralf BENDER Phone: +49 221 35685-451 | | Fax: +49 221 35685-891 | | E-Mail: Ralf@rbsd.de | *------------------------------------------------------------------*; options linesize=90; *---------------------------------------------------------------------* | Data of CONOVER (1980, p. 301) | *---------------------------------------------------------------------*; data DATA; input g1-g4; cards; 4 3 2 1 4 2 3 1 3 1.5 1.5 4 3 1 2 4 4 2 1 3 2 2 2 4 1 3 2 4 2 4 1 3 3.5 1 2 3.5 4 1 3 2 4 2 3 1 3.5 1 2 3.5 ; run; *********************************************************************** * COMPUTING OF THE FRIEDMAN TEST * * WITH ADJUSTMENT FOR TIES * * AND MULTIPLE COMPARISONS USING THE HOLM PROCEDURE * ***********************************************************************; *---------------------------------------------------------------------* | READING DATA | | | | Be sure that your data set "DATA" has a block*treatment structure, | | i.e. the rows are the blocks and the colomns are the treatments | | and that there are no missing values ! | *---------------------------------------------------------------------*; PROC IML; use DATA; read all into X; reset center linesize=80 nolog spaces=0; n=nrow(X); k=ncol(X); if n<10 then print 'WARNING: The following results are based on approximations', ' and should be interpreted carefully, because the ', ' sample size is small !!! ',,,,; *---------------------------------------------------------------------* | FRIEDMAN TEST | *---------------------------------------------------------------------*; START FRIEDMAN; *-----------------------*computing of mean ranks*--------------------*; do i=1 to n; Y = Y // ranktie(X[i,]); end; do j=1 to k; RS = RS || sum(Y[,j]); end; SSQX = ssq(Y); SSRS = ssq(RS); *-----------------------*some different statistics*------------------*; F_cla = 12/(n*k*(k+1))*SSRS - 3*n*(k+1); F_tie = (k-1)* (SSRS-(n**2*k*(k+1)**2)/4) / (SSQX-(n*k*(k+1)**2)/4); F_Con = (n-1)*F_tie / (n*(k-1)-F_tie); *-----------------------------*p values*-----------------------------*; p_cla = 1-probchi(F_cla,k-1); p_tie = 1-probchi(F_tie,k-1); if n*(k-1)=F_tie then p_Con=(1/gamma(k+1))**(n-1); else p_Con = 1-probf(F_Con,(k-1),(n-1)*(k-1)); *--------------------------*printing of results*---------------------*; print 'RESULTS OF THE FRIEDMAN TEST',; print 'Number of Blocks and Treatments: ' N K,; print 'Classical Friedman Test: ' F_cla [format=8.3] ' ' p_cla [format=8.6],; print 'Friedman Test with Adjustment for Ties: ' F_tie [format=8.3] ' ' p_tie [format=8.6]; print 'F Approximation of CONOVER (1980, p. 300): ' F_Con [format=8.3] ' ' p_Con [format=8.6],,,; if F_Con=. then print 'Note: The F approximation cannot be computed. ', ' The p-value is computed as p=(1/k!)**(n-1)', ' [see CONOVER (1980, p. 300)]. ',,,; FINISH; *---------------------------------------------------------------------* | Multiple Comparisons (HOLM, 1979) | *---------------------------------------------------------------------*; START HOLM; create mc var{v w p}; *------------------*Friedman test of all possible pairs*--------------*; M = k*(k-1)*0.5; * M is the Number of pairwise comparisons; do v=1 to k-1; do w=v+1 to k; XP = X[,v] || X[,w]; free YP; do i=1 to n; YI = ranktie(XP[i,]); YP = YP // YI; end; free RS; do j=1 to 2; RJ = sum(YP[,j]); RS = RS || RJ; end; SSQX = ssq(YP); SSRS = ssq(RS); F_tie = (SSRS-(n**2*2*9)/4) / (SSQX-(n*2*9)/4); F_Con = (n-1)*F_tie / (n-F_tie); if n=F_tie then p_Con=0.5**(n-1); else p_Con = 1-probf(F_Con,1,n-1); MC = v || w || p_Con; pairv = v || w; append from MC; end; end; close MC; *--------------------------*sorting of p values*---------------------*; sort MC by p; use MC; read all into HOLM; *-------------------------------*decisions*-------------------------*; D10I: do i=1 to M; if HOLM[i,3] <= 0.10/(M-i+1) then do; d10i=1; d10=d10//d10i; end; else goto D10R; end; if i>M then goto D05I; D10R: d10r=J(M-i+1,1,0); D10=d10//d10r; D05I: do i=1 to M; if HOLM[i,3] <= 0.05/(M-i+1) then do; d05i=1; d05=d05//d05i; end; else goto D05R; end; if i>M then goto NEXT; D05R: d05r=J(M-i+1,1,0); D05=d05//d05r; NEXT: PAIR = HOLM[,1:2]; P = HOLM[,3]; *--------------------------*printing of results*---------------------*; print 'RESULTS OF THE HOLM PROCEDURE'; print 'Elementwise p-Values and Simultaneous Decisions for Alpha=0.05,0.10',; print PAIR[format=3.0] ' ' P[format=8.6] D05 D10; FINISH; run friedman; run holm; quit; run; *********** All Rights by R. BENDER, Duesseldorf, 1995 *****************;