[R] binomial glm???

Ben Bolker bolker at ufl.edu
Thu Nov 20 15:52:06 CET 2008


Gerard M. Keogh <GMKeogh <at> justice.ie> writes:

> 
> 
> Hi everyone,
> 
> newbee query!
> 
> I've installed R 2.8.0 and tried to run this simple glm -
>       x is no of cars in a given year, y is the number voted in an election
> that year while n is the population 18+:


  I strongly suspect that you're confused between
the definition of a generalIZED linear model (glm in
R, PROC GENMOD in Some other stAtisticS program) and
a generAL linear model (lm in R, PROC GLM in S*S).
As shown below, the actual predictions are nearly
identical in this case between the linear model
(assuming normal errors and linearity)
and the generalized linear model (assuming binomial
errors and a logistic curve), because the logistic
curve is very close to linear in the middle of
its range.

votes <- data.frame(x = c(0.62,0.77,0.71,0.74,0.77,0.86,1.13,1.44),
                    y=c(502,542,711,653,771,806,934,1123),
                    n= c(1617,1734,1680,1793,1678,1751,1807,1879))
votes$YM <- cbind(votes$y, votes$n - votes$y)
fml <- glm(YM ~ x, family = binomial, data = votes)
summary(fml)

with(votes,plot(y/n~x,ylim=c(0,1)))
xvec <- seq(0.5,1.6,length=100)
lines(xvec,predict(fml,newdata=data.frame(x=xvec,n=1),type="response"))

## or:

lm1 <- lm(y/n~x,data=votes)
abline(lm1,col=2)

  Ben Bolker



More information about the R-help mailing list