Friedman’s test is a nonparametric test for treatment differences in a randomized complete block design. Each block of the design might be a subject or a homogeneous group of subjects. If blocks are groups of subjects, the number of subjects in each block must equal the number of treatments. Treatments are randomly assigned to subjects within each block. If there is one subject per block, the subjects are repeatedly measured once under each treatment. The order of treatments is randomized for each subject.

In this setting, Friedman’s test is identical to the ANOVA (row means scores) CMH statistic when the analysis uses rank scores (SCORES=RANK). The three-way table uses subject (or subject group) as the stratifying variable, treatment as the row variable, and response as the column variable. PROC FREQ handles ties by assigning midranks to tied response values. If there are multiple subjects per treatment in each block, the ANOVA CMH statistic is a generalization of Friedman’s test.

The data set `Hypnosis`

contains data from a study investigating whether hypnosis has the same effect on skin potential (measured in millivolts)
for four emotions (Lehmann and D’Abrera 2006, p. 264). Eight subjects are asked to display fear, joy, sadness, and calmness under hypnosis. The data are recorded as one
observation per subject for each emotion.

data Hypnosis; length Emotion $ 10; input Subject Emotion $ SkinResponse @@; datalines; 1 fear 23.1 1 joy 22.7 1 sadness 22.5 1 calmness 22.6 2 fear 57.6 2 joy 53.2 2 sadness 53.7 2 calmness 53.1 3 fear 10.5 3 joy 9.7 3 sadness 10.8 3 calmness 8.3 4 fear 23.6 4 joy 19.6 4 sadness 21.1 4 calmness 21.6 5 fear 11.9 5 joy 13.8 5 sadness 13.7 5 calmness 13.3 6 fear 54.6 6 joy 47.1 6 sadness 39.2 6 calmness 37.0 7 fear 21.0 7 joy 13.6 7 sadness 13.7 7 calmness 14.8 8 fear 20.3 8 joy 23.6 8 sadness 16.3 8 calmness 14.8 ;

In the following PROC FREQ statements, the TABLES statement creates a three-way table stratified by `Subject`

and a two-way table; the variables `Emotion`

and `SkinResponse`

form the rows and columns of each table. The CMH2 option produces the first two Cochran-Mantel-Haenszel statistics, the option
SCORES=RANK specifies that rank scores are used to compute these statistics, and the NOPRINT option suppresses the contingency
tables. These statements produce Output 3.9.1 and Output 3.9.2.

proc freq data=Hypnosis; tables Subject*Emotion*SkinResponse / cmh2 scores=rank noprint; run;

proc freq data=Hypnosis; tables Emotion*SkinResponse / cmh2 scores=rank noprint; run;

Because the CMH statistics in Output 3.9.1 are based on rank scores, the Row Mean Scores Differ statistic is identical to Friedman’s chi-square (Q = 6.45). The p-value of 0.0917 indicates that differences in skin potential response for different emotions are significant at the 10% level but not at the 5% level.

When you do not stratify by subject, the Row Mean Scores Differ CMH statistic is identical to a Kruskal-Wallis test and is not significant (p = 0.9038 in Output 3.9.2). Thus, adjusting for subject is critical to reducing the background variation due to subject differences.

Output 3.9.1: CMH Statistics: Stratifying by Subject

Output 3.9.2: CMH Statistics: No Stratification