How to use Levene test function in R?

I’m a newbie to statistics and R and I have a trouble with using Levene function (I would like to check the equality of variance of two samples).
The documentation says that I should run:

levene.test(y, group)

But I have no idea what I should put as y and group? I have two different samples which of I would like to check the equality of variance. Should I put one of the sample’s values as y and the second as group parameter?

Any hints?

Answer

Let’s say that, in R, your 1st sample is stored in a vector named sample1 and your 2nd sample is stored in a vector named sample2.

You first have to combine your two samples in a single vector and to create another vector defining the two groups:

y <- c(sample1, sample2)

and

group <- as.factor(c(rep(1, length(sample1)), rep(2, length(sample2))))

Now, you can call

library(car)
levene.test(y, group)

EDIT

When trying this in R, I got the following warning:

'levene.test' has now been removed. Use 'leveneTest' instead...

According to this, you should have a look at leveneTest instead…

Attribution
Source : Link , Question Author : Jakub , Answer Author : Karolis Koncevičius

Leave a Comment