Skip to content

add1 in glm

3 messages · Murray Jorgensen, Brian Ripley

#
I'm having a bit of difficulty using the stepwise model-building tools 
in a glm context. Here, for example is one problem I have had using 
add1, where the abbreviation "." does not work as I expected it to do. I 
someone could point me towards some examples involving the interactive 
building of glm models I would be grateful.

The data set that I am using is the "Student's Goals" dataset from DASL.

 > goals.df <-read.table("C:\\Data\\DASL\\goals.txt", header = TRUE)
 > goals.df <- goals.df[,2:8]
 > goals.df[1:3,]
   Gender Grade Res Goals MOST LEAST Count
1      1     4   1     1    2     1     1
2      1     4   1     1    2     3     1
3      1     4   1     2    1     3     1
 > const <-glm(formula=Count~1,family = poisson(link = "log"), 
data=goals.df)
 > add1(const, Count ~ .)
Error in if (ncol(add) > 1) { : missing value where logical needed
 > add1(const, ~ Gender+Grade+Res+Goals+MOST+LEAST)
Single term additions

Model:
Count ~ 1
        Df Deviance    AIC
<none>      214.03 770.85
Gender  1   212.72 771.55
Grade   1   206.96 765.79
Res     1   213.25 772.08
Goals   1   208.33 767.16
MOST    1   211.30 770.13
LEAST   1   208.71 767.54
#
On Tue, 5 Nov 2002, Murray Jorgensen wrote:

            
What did you expect?  `.' means `what is already there' in updating a
formula, so you asked for nothing to be added.  The help page says

   scope: a formula giving the terms to be considered for adding or
          dropping.

and that seems precise to me.
Chapter 7 of MASS has examples using addterm, and add1 is a cut-down
version of addterm.
(That's a micro-bug)

  
    
#
ripley at stats.ox.ac.uk wrote:
Well I based it on my interpretation of the beginning of the first 
example in the V&R discussion, also the first example in the stepAIC() page:

data(quine)
quine.hi <- aov(log(Days + 2.5) ~ .^4, quine)

This seemed to suggest that "." meant "all the predictors". Now that I 
know what "." means, my error is clear.

Does anyone know of  functions for adding the best single term (or 
dropping the worst) from a specified scope? (Respecting marginality, of 
course!)

Murray









-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._