2

Trying to use friedman_test (coin), but I get the error:

Error in .local(.Object, ...) : ‘x’ is not a balanced factor.

I want to compare two "Treatment" from a bigger dataframe, and use the "Subject" as block. After extracting relevant data this is the df:

   Subject      Treatment Itching.Duration
1       BG  Pentobarbital              108
2       BG Tripelennamine              141
3       JF  Pentobarbital              341
4       JF Tripelennamine              184
5       BS  Pentobarbital              159
6       BS Tripelennamine              125
7       SI  Pentobarbital              135
8       SI Tripelennamine              227
9       BW  Pentobarbital              239
10      BW Tripelennamine              194
11      TS  Pentobarbital              136
12      TS Tripelennamine              155
13      GM  Pentobarbital              140
14      GM Tripelennamine              121
15      SS  Pentobarbital              134
16      SS Tripelennamine              129
17      MU  Pentobarbital              185
18      MU Tripelennamine               79
19      OS  Pentobarbital              188
20      OS Tripelennamine              317

And the error I get is:

> friedman_test(Itching.Duration~Treatment|as.factor(Subject), data = df1)
Error in .local(.Object, ...) : ‘x’ is not a balanced factor

I understand that my data is not balanced, but I don't get how to do it. If I do the same command on all the dataframe before I extract the data then it works.

1 Answers1

0

I think you need to drop the unused factors as in : Drop unused factor levels in a subsetted data frame

After defining your subset (df1) you should you use the following lines :

library(gdata)
df1 = drop.levels(df1)