# RE: [R] glm family=binomial logistic sigmoid curve problem

From: <Bill.Venables_at_csiro.au>
Date: Mon 11 Apr 2005 - 17:17:35 EST

Couple of points:

• If you provide relative frequencies for the binomial response, you need also to give weights so that the actual counts can be reconstructed. This is what the warning message is telling you: if you reconstruct the counts using the default (unity) weights, the counts are not integers... In this case the simplest work-around is to use a quasibinomial family, which at least shuts up the warning message.
• predict with glm objects, by default, predicts *linear predictors*. You need to predict responses.

Here's how I would (minimally) correct your script:

year <- c(2003+(6/12), 2004+(2/12), 2004+(10/12), 2005+(4/12)) percent <- c(0.31, 0.43, 0.47, 0.50)
plot(year, percent, xlim = c(2003, 2007), ylim = c(0, 1)) Lm <- lm(percent ~ year)
abline(Lm)
bm <- glm(percent ~ year, family = quasibinomial) points(year, fitted(bm), pch = 3)
curve(predict(bm, data.frame(year = x), type = "resp"), add = TRUE)

Supplementary points:

• It is a good idea to work with data frames, despite the fact that you need not.
• Using "lm" as the name for a fitted linear model object can cause problems, not to say confusion.

I'm trying to plot an extrapolated logistic sigmoid curve using glm(..., family=binomial) as follows, but neither the fitted() points or the predict()ed curve are plotting correctly:

> year <- c(2003+(6/12), 2004+(2/12), 2004+(10/12), 2005+(4/12))
> percent <- c(0.31, 0.43, 0.47, 0.50)
> plot(year, percent, xlim=c(2003, 2007), ylim=c(0, 1))
> lm <- lm(percent ~ year)
> abline(lm)
> bm <- glm(percent ~ year, family=binomial)
Warning message:
non-integer #successes in a binomial glm! in: eval(expr, envir, enclos)
> points(year, fitted(bm), pch="+")
NULL

All four of the binomial-fitted points fall exactly on the simple linear regression line, and the predict() curve is nowhere near any of the data points. What am I doing wrong?

What does the warning mean? Do I need more points?

I am using R on Windows, Version 2.0.1 (2004-11-15)

Thank you for your kind help.

Sincerely,
James Salsman

R-help@stat.math.ethz.ch mailing list