开发者

R not removing terms when doing MAM

I want to do a MAM, but I'm having difficulty in removing some terms:

 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)

I believe I have to remove these terms to start the MAM like so:

  model1<-update(full.model,~.-Veg_height:Bare:Common:Birds_Foot:Average_March
:Average_Apri开发者_StackOverflow社区l:Average_May:Average_June15:Average_June20:Average_June25:
Average_July15:Average_July20:Average_July25,family="poisson")
summary(model1)
anova(model1,full.model,test="Chi")

But I get this output:

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 

I've tried putting plus signs in model1 instead of colons, as I was clutching at straws when reading my notes but the same thing happens.

Why are both my models the same? I've tried searching on Google but I'm not very good at the terminology so my searches aren't bringing up much.


If I read your intention correctly, are you trying to fit a null model with no terms in it? If so, a simpler way is just to use the SSB_sq ~ 1 as the formula, meaning a model with only an intercept.

fit <- lm(sr ~ ., data = LifeCycleSavings)
fit0 <- lm(sr ~ 1, data = LifeCycleSavings)
## or via an update:
fit01 <- update(fit, . ~ 1)

Which gives, for example:

> 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 

An explanation of the formulae I use:

  • The first model used the shortcut ., which means all remaining variables in argument data (in my model it meant all variables in LifeCycleSavings on the RHS of the formula, except for sr which is already on the LHS).
  • In the second model (fit0), we only include 1 on the RHS of the formula. In R, 1 means an intercept, so sr ~ 1 means fit an intercept-only model. By default, an intercept is assumed, hence we did not need 1 when specifying the first model fit.
  • If you want to suppress an intercept, add - 1 or + 0 to your formula.

For your data, the first model would be:

full.model <- glm(SSB_sq ~ ., data = FOO, family = "poisson")

where FOO is the data frame holding your variables - you are using a data frame, aren't you? The null, intercept-only model would be specified using one of:

null.model <- glm(SSB_sq ~ 1, data = FOO, family = "poisson")

or

null.model <- update(full.model, . ~ 1)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜