Jeffrey Stratford | 19 Oct 00:21
Favicon

creating bins for a plot

Hi.  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.  Any suggestions would be appreciated.

Many thanks,

Jeff

Data sample:

box	use	purbank	purban2
1	1	0.003813435	0.02684564
2	1	0.04429451	0.1610738
3	1	0.04458785	0.06040268
4	1	0.06072162	0.2080537
5	0	0.6080962	0.6979866
6	1	0.6060428	0.6107383
7	1	0.3807568	0.4362416
8	0	0.3649164	0.3154362
9	0	0.3505427	0.2483221
10	0	0.3476093	0.1409396
11	0	0.3719566	0.3020134
12	1	0.09238011	0.1342282
13	0	0.08616111	0.1073826
14	0	0.07388724	0.04026845
(Continue reading)

Dieter Menne | 19 Oct 09:24
Favicon

Re: creating bins for a plot

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

______________________________________________
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
(Continue reading)

Ingmar Visser | 19 Oct 09:45
Favicon

Re: creating bins for a plot

Jeffrey,
not sure what you mean by showing the relationship between the prob and
purban2, but something like this could work:

library(gtools)
#inverse logit
fl <- function(x,beta){inv.logit(beta[1]+beta[2]*x)}
# for beta fill in your intercept and the coefficient of purban2
flb<-function(x,beta=c(-0.09,3.65)){fl(x,beta)}
# plot over the range of purban2 by:
plot(flb,0,1)

hth, Ingmar

On 10/19/06 12:24 AM, "Jeffrey Stratford" <stratja <at> auburn.edu> wrote:

> Hi.  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.  Any suggestions would be appreciated.
> 
> Many thanks,
> 
> Jeff
> 
> 
(Continue reading)

Alex Brown | 19 Oct 12:53

Re: creating bins for a plot

I suggest you look at the functions cut and tapply.

for instance:

breaks = 0:40 / 40
bucket <- cut(purban2, breaks)
used.c = tapply(used, bucket, sum)
unused.c = tapply(1 - used, bucket, sum)
used.c[is.na(used.c)] = 0
unused.c[is.na(unused.c)] = 0
plot(breaks[-length(breaks)], used.c / unused.c)

-Alex Brown

On 18 Oct 2006, at 23:24, Jeffrey Stratford wrote:

> Hi.  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.  Any suggestions would be appreciated.
>
> Many thanks,
>
(Continue reading)


Gmane