[R] predict for a model with a subset

Prof Brian Ripley
Fri, 24 Oct 2003 17:18:51 -0000

example(predict.glm)
fit <- glm(SF ~ ldose, family=binomial, subset=sex=="M")
predict(fit)
[1] -2.8185550 -1.5596055 -0.3006561  0.9582933  2.2172427  3.4761922

which is just the males.

So, that example works correctly, and predict.glm as called by you should
just return the fitted values, as above.

On Fri, 24 Oct 2003, Peter Flom wrote:

> running R 1.7.1 on Windows 2000
>
> I have a model
>
> notmar1 <- glm(yprisx~age+harddrug+sex, subset = marcom == 0,
>  family = quasipoisson)
>
> and summary(notmar1) gives (as it should) 433 df for the null model
>
> but when I run
> predict(notmar1 <- glm(yprisx~age+harddrug+sex, subset = marcom == 0,
> family = quasipoisson))
>
> I get preditions for 528 people (the full data set, not the subset)
>
> How do I get predict to work on just the subset of people for whom the
> model is estimated?

Perhaps you can show us how you managed to break it?

--
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 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595