can anyone help run a friedman test and post hoc analysis?

I have successfully completed a friedman test which was significant. I want to complete a post hoc test, but am having difficulty. My data is a studying weekly behavior repeated for 24 weeks, with 3 possible behavioral categories. Any coding or package suggestions??

This would be a good question for the cross validated forum (the biggest concentration of statisticians who want to help that I'm aware of).

That being said, a little bit of googling suggests that a post hoc analysis of a Friedman test may be done with a Wilcoxon signed rank test. A very detailed walk through can be found by Tal Galili here;

I am aware of different post hoc tests and have recently viewed this reference, although it was not successful for me. i am not sure if his is perhaps due to my response variables being categorical.

Does anyone have coding suggestions for running a friedman test? I have categorical behavior data (which is ordinal) but I am not sure the correct code for assigning ranking these behaviors in R and then running the friedman and post hoc thereafter

My research is a repeated measures design analyzing behavior for 25 weeks. My dependent results are categorical and may be "defensive", "stopping", or "escape" behavior. I have completed a friedman test, but cannot successfully complete a post hoc ( I have tried PMCMR, PMCMRplus, and NSM3). I have copied my coding below, for anyone to help.
thanks!

#THIS IS MY DATA SET. IT INVOLVES 0.014 PPM TREATMENTS OVER 25 WEEKS WITH RESULTING BEHAVIOR BEING DEFENSIVE, ESCAPE, OR STOPPING

controlFriedman
head(controlFriedman)
crayfishid treatment week behavior
1 22 control 9 def
2 27 control 5 escape
3 28 control 0 def
4 28 control 5 stop
5 28 control 7 def
6 266 control 0 def

str(controlFriedman)
'data.frame': 200 obs. of 5 variables:
crayfishid: int 22 27 28 28 28 266 266 266 10 10 ... treatment : Factor w/ 1 level "control": 1 1 1 1 1 1 1 1 1 1 ...
week : int 9 5 0 5 7 0 19 20 15 18 ... behavior : Factor w/ 3 levels "def","escape",..: 1 1 1 1 1 1 1 1 2 2 ...

#RUNNING FRIEDMAN TEST (behavior=dependant variable, week= independant variable, crayfishid= blocking variable)

friedman.test(behavior~week| crayfishid, data=controlFriedman)

Friedman rank sum test

data: behavior and week and crayfishid
Friedman chi-squared = 44.152, df = 24, p-value = 0.007325

library(PMCMR)

p<-posthoc.friedman.nemenyi.test(controlFriedman$behavior,controlFriedman$week,controlFriedman$crayfishid, p.adjust.methods="na")
*Error in colMeans(mat) : 'x' must be numeric

#ASSIGNING BEHAVIORS NUMBERS SIMILIAR TO A LIKERT SCALE (I didnt know if this would solve the above problem); still gives me the same Friedman results

library(dplyr)
mapping <- c("def" = 1, "stop" = 2, "escape" = 3)
orderedbehavior <- mapping[controlFriedman$behavior]
str(orderedbehavior)
Named num [1:200] 1 1 1 1 1 1 1 1 2 2 ...

  • attr(*, "names")= chr [1:200] "def" "def" "def" "def" ...

head(orderedbehavior)
def def def def def def def def stop stop stop stop stop stop stop stop
1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2

#STILL SAME VALUE FOR FRIEDMAN
> friedman.test(orderedbehavior~week| crayfishid, data=controlFriedman)

Friedman rank sum test

data: orderedbehavior and week and crayfishid
Friedman chi-squared = 44.152, df = 24, p-value = 0.007325>

#THIS BRINGS ABOUT ANOTHER PROBLEM FOR POST HOC..

p<-posthoc.friedman.nemenyi.test(controlFriedman$orderedbehavior,controlFriedman$week,controlFriedman$crayfishid, p.adjust.methods="na")
Error in posthoc.friedman.nemenyi.test.default(controlFriedman$orderedbehavior, :
y, groups and blocks must have the same length

#CHANGING BEHAVIOR CATEGORIES THEMSELVES TO NUMERIC (NOT SURE IF THIS IS RISKY )

str(controlFriedman)
'data.frame': 200 obs. of 5 variables:
crayfishid: int 22 27 28 28 28 266 266 266 10 10 ... treatment : Factor w/ 1 level "control": 1 1 1 1 1 1 1 1 1 1 ...
week : int 9 5 0 5 7 0 19 20 15 18 ... behavior : Factor w/ 3 levels "def","escape",..: 1 1 1 1 1 1 1 1 2 2 ...
$ behavior1 : Factor w/ 3 levels "def","escape",..: 1 1 1 1 1 1 1 1 2 2 ...
controlFriedman$behavior1=as.numeric(controlbehavior) str(`controlFriedman`) 'data.frame': 200 obs. of 5 variables: crayfishid: int 22 27 28 28 28 266 266 266 10 10 ...
treatment : Factor w/ 1 level "control": 1 1 1 1 1 1 1 1 1 1 ... week : int 9 5 0 5 7 0 19 20 15 18 ...
behavior : Factor w/ 3 levels "def","escape",..: 1 1 1 1 1 1 1 1 2 2 ... behavior1 : num 1 1 1 1 1 1 1 1 2 2 ...

#GET SAME FRIEDMAN VALUE

friedman.test(behavior1~week|crayfishid, data=controlFriedman)

Friedman rank sum test

data: behavior1 and week and crayfishid
Friedman chi-squared = 44.152, df = 24, p-value = 0.007325

#POST HOC FINALLY WORKS, BUT NONE OF MY PAIRWISE COMPARISONS SHOW ANY SIGNIFICANCE MAKING ME QUESTION WHETHER IT WAS COMPLETED CORRECTLY
#I ALSO TRIED PMCMRPLUS NSM3 PACKAGES

p<-posthoc.friedman.nemenyi.test(controlFriedman$behavior1,controlFriedman$week,controlFriedman$crayfishid, p.adjust.methods="na")
summary(p)

Pairwise comparisons using Nemenyi multiple comparison test	
         with q approximation for unreplicated blocked data 

data: controlFriedman$behavior1 , controlFriedman$week and controlFriedman$crayfishid

P value adjustment method: none
H0 statistic p.value
1 0 = 1 0.86469203 1.00
2 0 = 2 1.46517261 1.00
3 0 = 3 1.46517261 1.00
4 0 = 4 0.26421145 1.00
5 0 = 5 1.20096115 1.00
6 0 = 6 1.46517261 1.00
7 0 = 7 0.57646135 1.00
8 0 = 8 0.84067281 1.00
9 0 = 9 1.00880737 1.00
10 0 = 10 0.26421145 1.00
11 0 = 11 1.46517261 1.00
12 0 = 12 0.24019223 1.00
13 0 = 13 0.86469203 1.00
14 0 = 14 0.93674970 1.00
15 0 = 15 0.26421145 1.00
16 0 = 16 1.46517261 1.00
17 0 = 17 0.19215378 1.00
18 0 = 18 0.84067281 1.00
19 0 = 19 0.91273048 1.00
20 0 = 20 0.26421145 1.00
21 0 = 21 1.46517261 1.00
22 0 = 22 0.86469203 1.00
23 0 = 23 0.24019223 1.00
24 0 = 24 1.46517261 1.00
25 1 = 2 0.60048058 1.00
26 1 = 3 0.60048058 1.00
27 1 = 4 0.60048058 1.00
28 1 = 5 2.06565318 1.00
29 1 = 6 0.60048058 1.00
30 1 = 7 1.44115338 1.00
31 1 = 8 1.70536484 1.00
32 1 = 9 1.87349940 1.00
33 1 = 10 1.12890348 1.00
34 1 = 11 0.60048058 1.00
35 1 = 12 1.10488426 1.00
36 1 = 13 0.00000000 1.00
37 1 = 14 0.07205767 1.00
38 1 = 15 1.12890348 1.00
39 1 = 16 0.60048058 1.00
40 1 = 17 1.05684582 1.00
41 1 = 18 1.70536484 1.00
42 1 = 19 1.77742251 1.00
43 1 = 20 1.12890348 1.00
44 1 = 21 0.60048058 1.00
45 1 = 22 0.00000000 1.00
46 1 = 23 1.10488426 1.00
47 1 = 24 0.60048058 1.00
48 2 = 3 0.00000000 1.00
49 2 = 4 1.20096115 1.00
50 2 = 5 2.66613376 0.98
51 2 = 6 0.00000000 1.00
52 2 = 7 2.04163396 1.00
53 2 = 8 2.30584541 1.00
54 2 = 9 2.47397998 0.99
55 2 = 10 1.72938406 1.00
56 2 = 11 0.00000000 1.00
57 2 = 12 1.70536484 1.00
58 2 = 13 0.60048058 1.00
59 2 = 14 0.52842291 1.00
60 2 = 15 1.72938406 1.00
61 2 = 16 0.00000000 1.00
62 2 = 17 1.65732639 1.00
63 2 = 18 2.30584541 1.00
64 2 = 19 2.37790308 0.99
65 2 = 20 1.72938406 1.00
66 2 = 21 0.00000000 1.00
67 2 = 22 0.60048058 1.00
68 2 = 23 1.70536484 1.00
69 2 = 24 0.00000000 1.00
70 3 = 4 1.20096115 1.00
71 3 = 5 2.66613376 0.98
72 3 = 6 0.00000000 1.00
73 3 = 7 2.04163396 1.00
74 3 = 8 2.30584541 1.00
75 3 = 9 2.47397998 0.99
76 3 = 10 1.72938406 1.00
77 3 = 11 0.00000000 1.00
78 3 = 12 1.70536484 1.00
79 3 = 13 0.60048058 1.00
80 3 = 14 0.52842291 1.00
81 3 = 15 1.72938406 1.00
82 3 = 16 0.00000000 1.00
83 3 = 17 1.65732639 1.00
84 3 = 18 2.30584541 1.00
85 3 = 19 2.37790308 0.99
86 3 = 20 1.72938406 1.00
87 3 = 21 0.00000000 1.00
88 3 = 22 0.60048058 1.00
89 3 = 23 1.70536484 1.00
90 3 = 24 0.00000000 1.00
91 4 = 5 1.46517261 1.00
92 4 = 6 1.20096115 1.00
93 4 = 7 0.84067281 1.00
94 4 = 8 1.10488426 1.00
95 4 = 9 1.27301882 1.00
96 4 = 10 0.52842291 1.00
97 4 = 11 1.20096115 1.00
98 4 = 12 0.50440368 1.00
99 4 = 13 0.60048058 1.00
100 4 = 14 0.67253825 1.00
101 4 = 15 0.52842291 1.00
102 4 = 16 1.20096115 1.00
103 4 = 17 0.45636524 1.00
104 4 = 18 1.10488426 1.00
105 4 = 19 1.17694193 1.00
106 4 = 20 0.52842291 1.00
107 4 = 21 1.20096115 1.00
108 4 = 22 0.60048058 1.00
109 4 = 23 0.50440368 1.00
110 4 = 24 1.20096115 1.00
111 5 = 6 2.66613376 0.98
112 5 = 7 0.62449980 1.00
113 5 = 8 0.36028835 1.00
114 5 = 9 0.19215378 1.00
115 5 = 10 0.93674970 1.00
116 5 = 11 2.66613376 0.98
117 5 = 12 0.96076892 1.00
118 5 = 13 2.06565318 1.00
119 5 = 14 2.13771085 1.00
120 5 = 15 0.93674970 1.00
121 5 = 16 2.66613376 0.98
122 5 = 17 1.00880737 1.00
123 5 = 18 0.36028835 1.00
124 5 = 19 0.28823068 1.00
125 5 = 20 0.93674970 1.00
126 5 = 21 2.66613376 0.98
127 5 = 22 2.06565318 1.00
128 5 = 23 0.96076892 1.00
129 5 = 24 2.66613376 0.98
130 6 = 7 2.04163396 1.00
131 6 = 8 2.30584541 1.00
132 6 = 9 2.47397998 0.99
133 6 = 10 1.72938406 1.00
134 6 = 11 0.00000000 1.00
135 6 = 12 1.70536484 1.00
136 6 = 13 0.60048058 1.00
137 6 = 14 0.52842291 1.00
138 6 = 15 1.72938406 1.00
139 6 = 16 0.00000000 1.00
140 6 = 17 1.65732639 1.00
141 6 = 18 2.30584541 1.00
142 6 = 19 2.37790308 0.99
143 6 = 20 1.72938406 1.00
144 6 = 21 0.00000000 1.00
145 6 = 22 0.60048058 1.00
146 6 = 23 1.70536484 1.00
147 6 = 24 0.00000000 1.00
148 7 = 8 0.26421145 1.00
149 7 = 9 0.43234602 1.00
150 7 = 10 0.31224990 1.00
151 7 = 11 2.04163396 1.00
152 7 = 12 0.33626912 1.00
153 7 = 13 1.44115338 1.00
154 7 = 14 1.51321105 1.00
155 7 = 15 0.31224990 1.00
156 7 = 16 2.04163396 1.00
157 7 = 17 0.38430757 1.00
158 7 = 18 0.26421145 1.00
159 7 = 19 0.33626912 1.00
160 7 = 20 0.31224990 1.00
161 7 = 21 2.04163396 1.00
162 7 = 22 1.44115338 1.00
163 7 = 23 0.33626912 1.00
164 7 = 24 2.04163396 1.00
165 8 = 9 0.16813456 1.00
166 8 = 10 0.57646135 1.00
167 8 = 11 2.30584541 1.00
168 8 = 12 0.60048058 1.00
169 8 = 13 1.70536484 1.00
170 8 = 14 1.77742251 1.00
171 8 = 15 0.57646135 1.00
172 8 = 16 2.30584541 1.00
173 8 = 17 0.64851902 1.00
174 8 = 18 0.00000000 1.00
175 8 = 19 0.07205767 1.00
176 8 = 20 0.57646135 1.00
177 8 = 21 2.30584541 1.00
178 8 = 22 1.70536484 1.00
179 8 = 23 0.60048058 1.00
180 8 = 24 2.30584541 1.00
181 9 = 10 0.74459592 1.00
182 9 = 11 2.47397998 0.99
183 9 = 12 0.76861514 1.00
184 9 = 13 1.87349940 1.00
185 9 = 14 1.94555707 1.00
186 9 = 15 0.74459592 1.00
187 9 = 16 2.47397998 0.99
188 9 = 17 0.81665358 1.00
189 9 = 18 0.16813456 1.00
190 9 = 19 0.09607689 1.00
191 9 = 20 0.74459592 1.00
192 9 = 21 2.47397998 0.99
193 9 = 22 1.87349940 1.00
194 9 = 23 0.76861514 1.00
195 9 = 24 2.47397998 0.99
196 10 = 11 1.72938406 1.00
197 10 = 12 0.02401922 1.00
198 10 = 13 1.12890348 1.00
199 10 = 14 1.20096115 1.00
200 10 = 15 0.00000000 1.00
201 10 = 16 1.72938406 1.00
202 10 = 17 0.07205767 1.00
203 10 = 18 0.57646135 1.00
204 10 = 19 0.64851902 1.00
205 10 = 20 0.00000000 1.00
206 10 = 21 1.72938406 1.00
207 10 = 22 1.12890348 1.00
208 10 = 23 0.02401922 1.00
209 10 = 24 1.72938406 1.00
210 11 = 12 1.70536484 1.00
211 11 = 13 0.60048058 1.00
212 11 = 14 0.52842291 1.00
213 11 = 15 1.72938406 1.00
214 11 = 16 0.00000000 1.00
215 11 = 17 1.65732639 1.00
216 11 = 18 2.30584541 1.00
217 11 = 19 2.37790308 0.99
218 11 = 20 1.72938406 1.00
219 11 = 21 0.00000000 1.00
220 11 = 22 0.60048058 1.00
221 11 = 23 1.70536484 1.00
222 11 = 24 0.00000000 1.00
223 12 = 13 1.10488426 1.00
224 12 = 14 1.17694193 1.00
225 12 = 15 0.02401922 1.00
226 12 = 16 1.70536484 1.00
227 12 = 17 0.04803845 1.00
228 12 = 18 0.60048058 1.00
229 12 = 19 0.67253825 1.00
230 12 = 20 0.02401922 1.00
231 12 = 21 1.70536484 1.00
232 12 = 22 1.10488426 1.00
233 12 = 23 0.00000000 1.00
234 12 = 24 1.70536484 1.00
235 13 = 14 0.07205767 1.00
236 13 = 15 1.12890348 1.00
237 13 = 16 0.60048058 1.00
238 13 = 17 1.05684582 1.00
239 13 = 18 1.70536484 1.00
240 13 = 19 1.77742251 1.00
241 13 = 20 1.12890348 1.00
242 13 = 21 0.60048058 1.00
243 13 = 22 0.00000000 1.00
244 13 = 23 1.10488426 1.00
245 13 = 24 0.60048058 1.00
246 14 = 15 1.20096115 1.00
247 14 = 16 0.52842291 1.00
248 14 = 17 1.12890348 1.00
249 14 = 18 1.77742251 1.00
250 14 = 19 1.84948018 1.00
251 14 = 20 1.20096115 1.00
252 14 = 21 0.52842291 1.00
253 14 = 22 0.07205767 1.00
254 14 = 23 1.17694193 1.00
255 14 = 24 0.52842291 1.00
256 15 = 16 1.72938406 1.00
257 15 = 17 0.07205767 1.00
258 15 = 18 0.57646135 1.00
259 15 = 19 0.64851902 1.00
260 15 = 20 0.00000000 1.00
261 15 = 21 1.72938406 1.00
262 15 = 22 1.12890348 1.00
263 15 = 23 0.02401922 1.00
264 15 = 24 1.72938406 1.00
265 16 = 17 1.65732639 1.00
266 16 = 18 2.30584541 1.00
267 16 = 19 2.37790308 0.99
268 16 = 20 1.72938406 1.00
269 16 = 21 0.00000000 1.00
270 16 = 22 0.60048058 1.00
271 16 = 23 1.70536484 1.00
272 16 = 24 0.00000000 1.00
273 17 = 18 0.64851902 1.00
274 17 = 19 0.72057669 1.00
275 17 = 20 0.07205767 1.00
276 17 = 21 1.65732639 1.00
277 17 = 22 1.05684582 1.00
278 17 = 23 0.04803845 1.00
279 17 = 24 1.65732639 1.00
280 18 = 19 0.07205767 1.00
281 18 = 20 0.57646135 1.00
282 18 = 21 2.30584541 1.00
283 18 = 22 1.70536484 1.00
284 18 = 23 0.60048058 1.00
285 18 = 24 2.30584541 1.00
286 19 = 20 0.64851902 1.00
287 19 = 21 2.37790308 0.99
288 19 = 22 1.77742251 1.00
289 19 = 23 0.67253825 1.00
290 19 = 24 2.37790308 0.99
291 20 = 21 1.72938406 1.00
292 20 = 22 1.12890348 1.00
293 20 = 23 0.02401922 1.00
294 20 = 24 1.72938406 1.00
295 21 = 22 0.60048058 1.00
296 21 = 23 1.70536484 1.00
297 21 = 24 0.00000000 1.00
298 22 = 23 1.10488426 1.00
299 22 = 24 0.60048058 1.00
300 23 = 24 1.70536484 1.00

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.