[R] glm family=binomial logistic sigmoid curve problem
Bill.Venables@csiro.au
Bill.Venables at csiro.au
Mon Apr 11 09:17:35 CEST 2005
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.
-----Original Message-----
From: r-help-bounces at stat.math.ethz.ch
[mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of James Salsman
Sent: Monday, 11 April 2005 4:51 PM
To: r-help at stat.math.ethz.ch
Subject: [R] glm family=binomial logistic sigmoid curve problem
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
> curve(predict(bm, data.frame(year=x)), add=TRUE)
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 at stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide!
http://www.R-project.org/posting-guide.html
More information about the R-help
mailing list