0

我有以下公式: glm1 <- glm(y ~ g1 + g2, data = fish, family = binomial)

y是二项式变量: num 1 1 0 0 1 0 0 0 0 1 ... #有 (1) 或没有 (0) 鱼。 g1:因子 w/ 4 个级别“1”、“2”、“3”、“4”:1 2 1 1 4 1 2 1 1 3 ... #River 级别。 g2 : num 808 1110 754 421 568 535 570 690 668 556 ... #降水量 (mL)。

length(y)
>150
length(g1)
>150
length(g2)
>150

为了测试同方差性,我尝试了:

bartlett.test(split(y, list(g1,g2))) #Then I get this:
>Error in bartlett.test.default(split(y, list(g1,  : 
>  there must be at least 2 observations in each group. #I think it's strange, because I've 3 vectors at the formula.

但是我的公式是y~g1+g2,那么:

bartlett.test(y ~ g1+g2, data=fish) #Then I get this:
>Error in fligner.test.formula(y ~ g1 +  : 
> 'formula' should be of the form response ~ group

我还尝试了其他测试:

leveneTest(y ~ g1+g2) #Then I get this:
>Error in leveneTest.formula(y ~ g1 + g2, data = fish) : 
> Levene's test is not appropriate with quantitative explanatory variables.

最后,我尝试了这个:

fligner.test(split(y, list(g1,g2)))
>Error in fligner.test.default(split(y, list(g1,  : 
> all groups must contain data  #Again, I think it's strange, because I've 3 vectors at the formula

1. g1 和 g2 都必须是因子(分类变量)来测试同方差性吗?2. 如何用 Bartlett's、Levene's 和 Fligner's 在我的公式(y-num ~ g1-factor + g2-num)中测试同方差性?

我提前感谢您的帮助。

4

0 回答 0