Contrasts can be applied only to factor

后端 未结 3 598
一生所求
一生所求 2020-12-06 05:48

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

3条回答
  •  长情又很酷
    2020-12-06 06:25

    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)
    

提交回复
热议问题