I have a question about R.
I am using a test called levene.test to test a homogeneity of variance.
I know that you need a factor variable with at least two l
You need to actually convert your variable to a factor
. Just having three (or a finite) number of values does not necessarily make it a factor.
use x <- factor(x)
to convert
When you look at the output of str()
, it shows you the type of each variable:
<..cropped..>
$ SIF1 : num 19.6 17 NA 23.8 24.1 ...
$ sex : Factor w/ 2 levels "0","1": 1 1 2 2 2 2 1 1 1 1 ...
$ k : Factor w/ 3 levels "0","1","2": 1 1 2 3 1 3 3 3 1 2 ...
notice that $k
is a factor
but SIF1
is not
Thus, use
geno1rs11809462$SIF1 <- factor(geno1rs11809462$SIF1)
If your factor has only one level, you will get this error. To check to see the levels of your factor variables, use lapply(df, levels)
. It will return nothing for non-factor variables, but will easily let you identify which variable is the offender. This is especially helpful if, like me, you have hundreds of variables.
I think I may have solved the problem. I believe it is due to NA value in the data. Because after I removed the na using say
x<-na.omit(original_data)
then apply the levene test on x, the warning message disappears.
Hopefully this is the cause of the problem.