7

I'm having trouble running a Friedman test over my data. I'm trying to run a Friedman test using this command:

friedman.test(mean ~ isi | expId, data=monoSum)

On the following database (https://www.dropbox.com/s/2ox0y1b4gwld0ai/monoSum.csv):

> monoSum
   expId isi  N       mean
1  m80B1   1 10 100.000000
2  m80B1   2 10  73.999819
3  m80B1   3 10  45.219362
4  m80B1   4 10 116.566174        
.   .     .   .          .
18 m80L2   2 10  82.945491
19 m80L2   3 10  57.675480
20 m80L2   4 10 207.169277
.    .     .  .   .      .
25 m80M2   1 10 100.000000
26 m80M2   2 10  49.752687
27 m80M2   3 10  19.042592
28 m80M2   4 10 150.411035

It gives me back the error:

Error in friedman.test.default(c(100, 73.9998193095267, 45.2193621626293,  : 
not an unreplicated complete block design

I figure it gives the error because, when monoSum$isi==1 the value of mean is always 100. Is this correct?

However, monoSum$isi==1 is alway 100 because it is the control group on which all the other monoSum$isi groups are normalized. I can not assume a normal distribution, so I cannot run a rmANOVA… Is there a way to run a friedman test on this data or am I missing a very essential point here?

Many thanks in advance!

RmyjuloR
  • 369
  • 1
  • 4
  • 13

9 Answers9

7

I don't get an error if I run your dataset:

   Friedman rank sum test

   data:  mean and isi and expId
   Friedman chi-squared = 17.9143, df = 3, p-value = 0.0004581

However, you have to make sure that expId and isi are coded as factors. Run these commands:

    monoSum$expID$<-factor(monoSum$expID)
    monoSum$isi$<-factor(monoSum$isi)

Then run the test again. This has worked for me with a similar problem.

TJK
  • 106
  • 3
  • I restarted R and it now runs smoothly here too… Even without coding as factors… Unbelievable this had me going for almost over a week :') Thank you for your effort – RmyjuloR Feb 03 '14 at 20:56
6

I know this is pretty old but for future generations (see also: me when I forget and google this again):

You can determine what the missing values are in your dataframe by running table(groups, blocks) or in the case of this question table(monoSum$isi, monoSum$expID). This will return a table of 0s and 1s. This missing records are in the the cells with 0s.

I ran into this problem after trying to remove the blocks that had incomplete results; taking a subset of the data did not remove the blocks for some reason.

SPLASHT0N
  • 85
  • 1
  • 8
2

Just thought I would mention I found this post because I was getting a similar error message. The above suggestions did not solve it. Strangely, I had to sort my dataframe so that block by block the groups appeared in order (i.e. I could not have the following: Block 1 A Block 1 B Block 2 B Block 2 A

It has to appear as A, B, A, B)

1

I ran into the same cryptic error message in R, though in my case it was resolved when I applied the 'as.matrix' function to what was originally a dataframe for the CSV file I imported in using the read.csv() function.

I also had a missing data point in my original data set, and I found that when my data was transformed into a matrix for the friedman.test() call, the entire row containing the missing data point was omitted automatically.

Paul Sochacki
  • 433
  • 6
  • 8
1

Using the function as.matrix() to transform my dataframe is the magic that got the function to run for me.

Rachael
  • 33
  • 7
0

I had this exact error too with my dataset. It turns out that the function friedman.test() accepts data frames (fx those created by data.frame() ) but not tibbles (those created by dplyr and other modern tools). The solution for me was to convert my dataset to a dataframe first.

D_fri <- D_all %>% dplyr::select(FrustrationEpisode, Condition, Participant)
D_fri <- as.data.frame(D_fri)
str(D_fri) # confirm the object should now be a 'data.frame'
friedman.test(FrustrationEpisode ~ Condition | Participant, D_fri)
Bastian
  • 620
  • 5
  • 14
0

I ran into this problem too. Fixed mine by removing the NAs.

# My data (called layers) looks like:
| resp.no | av.l.all | av.baseem | av.base |
| 1       | 1.5      | 1.3       | 2.3     |
| 2       | 1.4      | 3.2       | 1.4     |
| 3       | 2.5      | 2.8       | 2.9     |
...
| 1088    | 3.6      | 1.1       | 3.3     |

# Remove NAs
layers1 <- na.omit(layers)

# Re-organise data so the scores are stacked, and a column added with the original column name as a factor
layers2 <- layers1 %>%
  gather(key = "layertype", value = "score", av.l.all, av.baseem, av.base) %>%
  convert_as_factor(resp.no, layertype)

# Data now looks like this
| resp.no | layertype | score  | 
| 1       | av.l.all  | 1.5    | 
| 1       | av.baseem | 1.3    | 
| 1       | av.base   | 2.3    | 
| 2       | av.l.all  | 1.4    | 
...
| 1088    | av.base   | 3.3    | 

# Then do Friedman test
friedman.test(score ~ layertype | resp.no, data = layers2)
0

Just want to share what my problem was. My ID factor did not have correct levels after doing pivot_longer(). Because of this, the same error was given. I made sure the correct level and it worked by the following:as.factor(as.character(df$ID))

Jan
  • 1
  • This does not really answer the question. If you have a different question, you can ask it by clicking [Ask Question](https://stackoverflow.com/questions/ask). To get notified when this question gets new answers, you can [follow this question](https://meta.stackexchange.com/q/345661). Once you have enough [reputation](https://stackoverflow.com/help/whats-reputation), you can also [add a bounty](https://stackoverflow.com/help/privileges/set-bounties) to draw more attention to this question. - [From Review](/review/late-answers/33290240) – Chris Nov 28 '22 at 21:43
0

Reviving an old thread with new information. I ran into a similar problem after removing NAs. My group and block were factors before the NA removal. However, after removing NAs, the factors retained the levels before the removal even though some levels were no longer in the data!

Running the friedman.test() with the as.matrix() trick (e.g., friedman.test(a ~ b | c, as.matrix(df))) was fine but running frdAllPairsExactTest() or friedman_effsize() would throw the not an unreplicated complete block design error. I ended up re-factoring the group and block (i.e., dropping the levels that were no longer in the data, df$block <- factor(df$block)) to make things work. After the re-factor, I did not need the as.matrix() trick, either.

xikeck
  • 7
  • 2