R 从带有偏移的模型中理解系数值
我正在使用R进行一些统计分析,在解释模型时遇到了一些问题。 考虑以下数据:R 从带有偏移的模型中理解系数值,r,offset,glm,coefficients,R,Offset,Glm,Coefficients,我正在使用R进行一些统计分析,在解释模型时遇到了一些问题。 考虑以下数据: df <- data.frame( richness=c(9,13,10,12,11,5,6,8,9,10,10,8, 5,7,6,9,5,6,7,8,4,10,5,8, 4,5,7,5,6,7,4,5,5,6,6,6, 1,0,2,1,4,5,3,2,0,1,4,4), condition=
df <- data.frame( richness=c(9,13,10,12,11,5,6,8,9,10,10,8,
5,7,6,9,5,6,7,8,4,10,5,8,
4,5,7,5,6,7,4,5,5,6,6,6,
1,0,2,1,4,5,3,2,0,1,4,4),
condition=c(rep("A",24), rep("B",24)),
area = c(12.62, 11.07, 15.72, 15.41, 6.42, 19.13, 17.58, 19.44, 13.55, 18.20, 6.73, 14.79, 5.80, 14.48, 17.89, 7.66, 10.76, 8.90, 8.59, 12.00, 12.93, 7.04, 17.27, 16.34, 9.83, 9.52, 19.75, 10.14, 13.86, 12.31, 16.03, 11.38, 14.17, 15.10, 18.51, 9.21, 20.06, 20.37, 7.97, 7.35, 8.28, 16.65, 6.11, 18.82, 10.45, 16.96, 11.69, 13.24),
treatment=rep(c(rep("absent",12), rep("present",12)), 2))
library(MASS)
nb.fit <- glm.nb( richness ~ condition * treatment, data=df)
exp(coef(nb.fit))
现在,考虑我们有不同的采样大小,这意味着我们有不同的努力。我们应该(可能必须)解释这个问题。
那么,让我们把它作为模型中的偏移量
nb.fit2 <- glm.nb(richness ~ condition * treatment + offset(log(area)),data=df)
问题1:对于A:缺失,平均丰富度/面积为0.69种的解释是否正确?(在这种情况下,每平方米0.69种)
问题2:如何计算偏移量?例如,我无法手动获取平均值,就像我在第一个使用
平均值(子集(df,条件==“A”和治疗==“缺失”)$richness)
即使是在试图消除该区域的影响时
df$richness.area <- df$richness/df$area
mean(subset(df, condition=="A" & treatment=="absent")$richness.area)
df$richness.area我认为这属于CrossValidated。有关相关问题和答案,请参见。。。
exp(coef(nb.fit2))
df$richness.area <- df$richness/df$area
mean(subset(df, condition=="A" & treatment=="absent")$richness.area)