Search code examples
rstatisticsdimensiondunn.test

Fixing an error in R- "Incorrect number of dimensions" in the Dunn Test


I am trying to use the Dunn test for a comparison but I am getting an error: "Error in Psort[1, i] : incorrect number of dimensions"

the data I am trying to use is this sort of idea (but sample size is bigger):

Frequency    Height
1            10
2            11
1            9
1            8
2            15
1            9
2            11
2            13

the code I used was

dunnTest(Height ~ Frequency,
     data=Data,
     method="bh") 

is my problem that my frequency is only split into two groups? cause for another factor my frequency had three groups and it worked fine. If this is the problem, is there another test I can do that will perform a similar/the same function?

Thanks!


Solution

  • The Dunn test is equivalent to the Wilcox test (wilcox.test) if you adjust values of input parameters (disable the exact calculation of p value, disable the continuity correction, more here). For your data, one obtains:

    > wilcox.test(df$Frequency, df$Height, correct = FALSE, exact = FALSE)
    
    Wilcoxon rank sum test
    
    data:  df$Frequency and df$Height
    W = 0, p-value = 0.0006346
    alternative hypothesis: true location shift is not equal to 0
    

    I think you are using the dunnTest function from the FSA package. This function fails for two groups.

    Data

    df <- read.table(text="Frequency    Height
    1            10
    2            11
    1            9
    1            8
    2            15
    1            9
    2            11
    2            13", header=TRUE)