我想做一个MAM,但我在删除一些术语时遇到了困难:
full.model<-glm(SSB_sq~Veg_height+Bare+Common+Birds_Foot+Average_March+Average_April+
Average_May+Average_June15+Average_June20+Average_June25+Average_July15
+Average_July20+Average_July25,family="poisson")
summary(full.model)我认为我必须删除这些术语才能启动MAM,如下所示:
model1<-update(full.model,~.-Veg_height:Bare:Common:Birds_Foot:Average_March
:Average_April:Average_May:Average_June15:Average_June20:Average_June25:
Average_July15:Average_July20:Average_July25,family="poisson")
summary(model1)
anova(model1,full.model,test="Chi")但是我得到了这个输出:
anova(model1,full.model,test="Chi")
Analysis of Deviance Table
Model 1: SSB_sq ~ Veg_height + Bare + Common + Birds_Foot + Average_March +
Average_April + Average_May + Average_June15 + Average_June20 +
Average_June25 + Average_July15 + Average_July20 + Average_July25
Model 2: SSB_sq ~ Veg_height + Bare + Common + Birds_Foot + Average_March +
Average_April + Average_May + Average_June15 + Average_June20 +
Average_June25 + Average_July15 + Average_July20 + Average_July25
Resid. Df Resid. Dev Df Deviance P(>|Chi|)
1 213 237.87
2 213 237.87 0 0 为什么我的两个模型都是一样的?我试过在谷歌上搜索,但我对术语不是很在行,所以我的搜索结果不是很好。
发布于 2011-07-20 05:08:15
如果我正确理解了您的意图,您是否正在尝试拟合一个没有项的空模型?如果是这样的话,一种更简单的方法是使用SSB_sq ~ 1作为公式,这意味着只有一个截距的模型。
fit <- lm(sr ~ ., data = LifeCycleSavings)
fit0 <- lm(sr ~ 1, data = LifeCycleSavings)
## or via an update:
fit01 <- update(fit, . ~ 1)例如,它给出了:
> anova(fit)
Analysis of Variance Table
Response: sr
Df Sum Sq Mean Sq F value Pr(>F)
pop15 1 204.12 204.118 14.1157 0.0004922 ***
pop75 1 53.34 53.343 3.6889 0.0611255 .
dpi 1 12.40 12.401 0.8576 0.3593551
ddpi 1 63.05 63.054 4.3605 0.0424711 *
Residuals 45 650.71 14.460
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
> anova(fit, fit0)
Analysis of Variance Table
Model 1: sr ~ pop15 + pop75 + dpi + ddpi
Model 2: sr ~ 1
Res.Df RSS Df Sum of Sq F Pr(>F)
1 45 650.71
2 49 983.63 -4 -332.92 5.7557 0.0007904 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 对我使用的公式的解释:
.,这意味着参数data中的所有剩余变量(在我的模型中,它表示公式的RHS上的LifeCycleSavings中的所有变量,除了已经在LHS上的sr )。fit0)中,我们只在公式的RHS上包括<LifeCycleSavings>d12sr>。在R中,1表示截取,因此sr ~ 1表示适合仅截取的模型。默认情况下,假定存在截取,因此在指定要取消截取的第一个模型fit.1,请在公式中添加- 1或+ 0。对于您的数据,第一个模型将是:
full.model <- glm(SSB_sq ~ ., data = FOO, family = "poisson")其中FOO是保存变量的数据框-您正在使用数据框,不是吗?空的、仅截取的模型将使用以下方法之一指定:
null.model <- glm(SSB_sq ~ 1, data = FOO, family = "poisson")或
null.model <- update(full.model, . ~ 1)https://stackoverflow.com/questions/6753559
复制相似问题