Hello 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? Thanks Peter
Have you tried the following: notmar1 <- glm(yprisx~age+harddrug+sex, subset = marcom == 0, family = quasipoisson), data=DF) predict(notmar1, newdata=DF[DF$marcom==0,]) I haven't tested this specific code, but I've gotten sensible results from constructs like this in the past. hope this helps. spencer graves Peter Flom wrote:>Hello > >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? > >Thanks > >Peter > >______________________________________________ >R-help at stat.math.ethz.ch mailing list >https://www.stat.math.ethz.ch/mailman/listinfo/r-help > >
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