addterm.Rd
Try fitting all models that differ from the current model by adding a single term from those supplied, maintaining marginality.
This function is generic; there exist methods for classes lm
and
glm
and the default method will work for many other classes.
addterm(object, ...) # S3 method for default addterm(object, scope, scale = 0, test = c("none", "Chisq"), k = 2, sorted = FALSE, trace = FALSE, ...) # S3 method for lm addterm(object, scope, scale = 0, test = c("none", "Chisq", "F"), k = 2, sorted = FALSE, ...) # S3 method for glm addterm(object, scope, scale = 0, test = c("none", "Chisq", "F"), k = 2, sorted = FALSE, trace = FALSE, ...)
object | An object fitted by some model-fitting function. |
---|---|
scope | a formula specifying a maximal model which should include the current one. All additional terms in the maximal model with all marginal terms in the original model are tried. |
scale | used in the definition of the AIC statistic for selecting the models,
currently only for |
test | should the results include a test statistic relative to the original
model? The F test is only appropriate for |
k | the multiple of the number of degrees of freedom used for the penalty.
Only |
sorted | should the results be sorted on the value of AIC? |
trace | if |
... | arguments passed to or from other methods. |
A table of class "anova"
containing at least columns for the change
in degrees of freedom and AIC (or Cp) for the models. Some methods
will give further information, for example sums of squares, deviances,
log-likelihoods and test statistics.
The definition of AIC is only up to an additive constant: when
appropriate (lm
models with specified scale) the constant is taken
to be that used in Mallows' Cp statistic and the results are labelled
accordingly.
Venables, W. N. and Ripley, B. D. (2002) Modern Applied Statistics with S. Fourth edition. Springer.
quine.hi <- aov(log(Days + 2.5) ~ .^4, quine) quine.lo <- aov(log(Days+2.5) ~ 1, quine) addterm(quine.lo, quine.hi, test="F")#> Single term additions #> #> Model: #> log(Days + 2.5) ~ 1 #> Df Sum of Sq RSS AIC F Value Pr(F) #> <none> 106.787 -43.664 #> Eth 1 10.6820 96.105 -57.052 16.0055 0.0001006 *** #> Sex 1 0.5969 106.190 -42.483 0.8094 0.3698057 #> Age 3 4.7469 102.040 -44.303 2.2019 0.0904804 . #> Lrn 1 0.0043 106.783 -41.670 0.0058 0.9392083 #> --- #> Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1house.glm0 <- glm(Freq ~ Infl*Type*Cont + Sat, family=poisson, data=housing) addterm(house.glm0, ~. + Sat:(Infl+Type+Cont), test="Chisq")#> Single term additions #> #> Model: #> Freq ~ Infl * Type * Cont + Sat #> Df Deviance AIC LRT Pr(Chi) #> <none> 217.46 610.43 #> Infl:Sat 4 111.08 512.05 106.371 < 2.2e-16 *** #> Type:Sat 6 156.79 561.76 60.669 3.292e-11 *** #> Cont:Sat 2 212.33 609.30 5.126 0.07708 . #> --- #> Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1house.glm1 <- update(house.glm0, . ~ . + Sat*(Infl+Type+Cont)) addterm(house.glm1, ~. + Sat:(Infl+Type+Cont)^2, test = "Chisq")#> Single term additions #> #> Model: #> Freq ~ Infl + Type + Cont + Sat + Infl:Type + Infl:Cont + Type:Cont + #> Infl:Sat + Type:Sat + Cont:Sat + Infl:Type:Cont #> Df Deviance AIC LRT Pr(Chi) #> <none> 38.662 455.63 #> Infl:Type:Sat 12 16.107 457.08 22.5550 0.03175 * #> Infl:Cont:Sat 4 37.472 462.44 1.1901 0.87973 #> Type:Cont:Sat 6 28.256 457.23 10.4064 0.10855 #> --- #> Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1