[R] creating bins for a plot

Dieter Menne dieter.menne at menne-biomed.de
Thu Oct 19 09:24:28 CEST 2006


Jeffrey Stratford <stratja <at> auburn.edu> writes:

> 
> I'm trying to plot the ratio of used versus unused bird houses
> (coded 1 or 0) versus a continuous environmental gradient (proportion of
>  urban cover [purban2]) that I would like to convert into bins (0 -
> 0.25, 0.26 - 0.5, 0.51 - 0.75, 0.76 - 1.0) and I'm not having much luck
> figuring this out.  I ran a logistic regression and purban2 ends up
> driving the probability of a box being occupied so it would be nice to
> show this relationship.  I'm also plotting the fitted values vs. purban2
> but that's done.  
 
Check the example under predict.glm. It does not use binning, though.

--- Code below added because gmane complains about too much quoted text.

## example from Venables and Ripley (2002, pp. 190-2.)
ldose <- rep(0:5, 2)
numdead <- c(1, 4, 9, 13, 18, 20, 0, 2, 6, 10, 12, 16)
sex <- factor(rep(c("M", "F"), c(6, 6)))
SF <- cbind(numdead, numalive=20-numdead)
budworm.lg <- glm(SF ~ sex*ldose, family=binomial)
summary(budworm.lg)



Dieter



More information about the R-help mailing list