[R] glm.predict?

Prof Brian Ripley ripley at stats.ox.ac.uk
Tue Jan 22 13:49:52 CET 2002


On 22 Jan 2002, Peter Dalgaard BSA wrote:

> "Patrick Connolly" <P.Connolly at hortresearch.co.nz> writes:
>
> > foo.glm <- glm(Insects ~ Dad * Mum + Location, offset = log(MM), family
> >                    = "poisson", data = model.df)
> >
> ..
> > things <- list()
> > things$fitA <- predict(foo.glm, type = "response")
> > things$fitB <- predict(foo.glm, type = "response", se.fit = TRUE)$fit
>
> > 1: longer object length
> > 	is not a multiple of shorter object length in: predictor + offset
> > 2: longer object length
> > 	is not a multiple of shorter object length in: se.fit * abs(family(object)$mu.eta(fit))
>
> I got:
>
> > predict(foo.glm,se=T)
> Error in log(MM) : Object "MM" not found
>
> which looks like it is part of the problem
>
> This works:
> > predict(foo.glm,se.fit=T,newdata=model.df)

Here's the fix, harder that it needs to be as predict.lm and predict.glm
have different defaults for newdata ...

predict.glm:

#        if (missing(newdata))
#            newdata <- model.frame(object)
        pred <- predict.lm(object, newdata, se.fit, scale = residual.scale,
            type = ifelse(type == "link", "response", type),
            terms = terms)

predict.lm:

    if (missing(newdata) || is.null(newdata)) {
        X <- model.matrix(object)
        offset <- object$offset
...

It looks like the note on prediction is out-of-date.



-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list