Levene's Test Equality of Error Variances

Hello again everybody,

I am trying to run an ANCOVA test on R Shiny and one of the assumptions that need to be fulfilled in this test is that the residual variances should be similar for all groups (Homogeneity of variance). I have tried to use the function leveneTest() from the library(car). But I am not quite sure about it since it doesn't use the residual instead it uses the absolute value. This is how the app looks like:

and this is the code in R Studio:

# Output for Homogeneity of Variance ANCOVA
  output$levTable <- renderPrint({
      need(input$varAncovTest != "" && input$groupAncovTest != "" , "Undefined columns selected")
    Data <- df()
    if (is.null(Data)){return(NULL)}
    DepVar <- Data[,input$varAncovTest]
    IndVar <- Data[,input$groupAncovTest]
    leveneTest(DepVar ~ IndVar,data=Data,center=mean)

The results should show a significant p-value and assumptions of equal error variances should be made. Is there any possibilities to measure the residuals instead of the absolute one? Thank you in advance!


Levene's test is working correctly here. Typically you want three arguments, your DV in first argument followed by your grouping variable for the groups and then selecting an appropriate center. The original test uses the mean.

leveneTest(outcome variable, group, center = median/mean)

A significant p-value will not indicate equal error variance. It shows the violation of the condition. You want the original data added into the test and not change it. Does this help?

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

If you have a query related to it or one of the replies, start a new topic and refer back with a link.

Sorry, but the data that I used is based on the actual values and not the residuals, so I am not quite sure if this is the correct result since the assumption requires the homogenity of error variance(residual's variance). Is there any solution for this one? or maybe convert the data first into residuals just like in SAS below, but I am not quite sure how to apply it in R:

PROC MIXED data=bref.ancova_dat;
CLASS Product;
Model dWeight_V3_V1=Product Weight_V1/residual outp=res;
lsmeans Product;

and create this output=res (for residuals) with column RESID:

The easiest way is to take the dummy example in the help document of leveneTest and run it with that data and see if you'd have treated the data in the same way or not. I am pretty sure that is done in the background for you with the function itself but run it with the example data

Ok! I will try. Thank you !

1 Like