有两种方式可以解释您的第一个问题,这反映在您提出的两种方式中:“物种是否与寄主植物有关?” 并且,“考虑到雨水的影响,物种是否独立于寄主植物?”
第一种解释对应于联合独立模型,它指出物种和宿主是相互依赖的,但共同独立于是否下雨:
pshr=pshpr
其中是观测落入单元格的概率,其中索引物种、宿主类型和降雨值,是单元格,我们在雨变量上崩溃,是下雨的边际概率。pshr(s,h,r)shrpsh(s,h,⋅)pr
第二种解释对应于条件独立模型,该模型表明物种和宿主是独立的,无论是否下雨:
psh|r=ps|rph|r或pshr=psrphr/pr
其中是单元的条件概率,给定的值。psh|r(s,h,r)r
您可以在 R 中测试这些模型(loglin
也可以正常工作,但我更熟悉glm
):
count <- c(12,15,10,13,11,12,12,7)
species <- rep(c("a", "b"), 4)
host <- rep(c("c","c", "d", "d"), 2)
rain <- c(rep(0,4), rep(1,4))
my.table <- xtabs(count ~ host + species + rain)
my.data <- as.data.frame.table(my.table)
mod0 <- glm(Freq ~ species + host + rain, data=my.data, family=poisson())
mod1 <- glm(Freq ~ species * host + rain, data=my.data, family=poisson())
mod2 <- glm(Freq ~ (species + host) * rain, data=my.data, family=poisson())
anova(mod0, mod1, test="Chi") #Test of joint independence
anova(mod0, mod2, test="Chi") #Test of conditional independence
上面,mod1
对应于联合独立,mod2
对应于条件独立,而mod0
对应于相互独立模型。您可以使用 等查看参数估计值。像往常一样,您应该检查是否满足模型假设。在您提供的数据中,空模型实际上非常适合。pshr=psphprsummary(mod2)
处理第一个问题的另一种方法是对折叠的 2x2 表(第一种解释)执行 Fischer 精确检验fisher.test(xtabs(count ~ host + species))
( mantelhaen.test(xtabs(count ~ host + species + rain))
(第二种解释)。
套用你的第二个问题,物种和宿主之间的关系是否取决于是否下雨?
mod3 <- glm(Freq ~ species*host*rain - species:host:rain, data=my.data, family=poisson())
mod4 <- glm(Freq ~ species*host*rain, data=my.data, family=poisson())
anova(mod3, mod4, test=”Chi”)
pchisq(deviance(mod3), df.residual(mod3), lower=F)
完整的模型mod4
已经饱和,但是您可以通过查看mod3
我在上面所做的偏差来测试有问题的效果。