ranovaquantitative

Levene Test for Two-way ANOVA


I wanted to check the homogeneity of variance assumption for a two-way ANOVA. For that, I wanted to use the function leveneTest() in the car package. However, it gives me the error:

Error in leveneTest.formula(formula, data, center = center) :  Levene's test is not appropriate with quantitative explanatory variables.

From searching up the error I found that the order of the explanatory variables is important, the function expects the right-hand side to be factors. I tried that, but it did not work.

I also tested a Tutorial with the same task:

library(car)

my_data <- ToothGrowth

leveneTest(len ~ supp*dose, data = my_data)

And it gives me the same error, where it should give the results:

Levene's Test for Homogeneity of Variance (center = median)
'  Df F value Pr(>F)'
'group  5  1.7086 0.1484'
      ' 54'  

Does somebody get the same error and is there a solution besides converting the numerical variable into a factorial one?

Help is much appreciated!


Solution

  • You have to do it like this

    leveneTest(len ~ factor(supp)*factor(dose), data = my_data)
    

    and I think there is no way to do it without converting to factors, because Levene's test compares groups. Group names are factors, not continuous variables.