Re: [R] creating bins for a plot

2006-10-19 Thread Dieter Menne
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@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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] creating bins for a plot

2006-10-19 Thread Ingmar Visser
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 [EMAIL PROTECTED] 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
 
 
 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
 15 1 0.07046477 0.03355705
 .
 .
 .
 
 
 
 Jeffrey A. Stratford, Ph.D.
 Postdoctoral Associate
 331 Funchess Hall
 Department of Biological Sciences
 Auburn University
 Auburn, AL 36849
 334-329-9198
 FAX 334-844-9234
 http://www.auburn.edu/~stratja
 
 __
 R-help@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
 and provide commented, minimal, self-contained, reproducible code.

-- 
Ingmar Visser
Department of Psychology, University of Amsterdam
Roetersstraat 15, 1018 WB Amsterdam
The Netherlands
http://users.fmg.uva.nl/ivisser/
tel: +31-20-5256735

__
R-help@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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] creating bins for a plot

2006-10-19 Thread Alex Brown
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,

 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
 100   0.3476093   0.1409396
 110   0.3719566   0.3020134
 121   0.09238011  0.1342282
 130   0.08616111  0.1073826
 140   0.07388724  0.04026845
 151   0.07046477  0.03355705
 .
 .
 .


 
 Jeffrey A. Stratford, Ph.D.
 Postdoctoral Associate
 331 Funchess Hall
 Department of Biological Sciences
 Auburn University
 Auburn, AL 36849
 334-329-9198
 FAX 334-844-9234
 http://www.auburn.edu/~stratja

 __
 R-help@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
 and provide commented, minimal, self-contained, reproducible code.

__
R-help@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
and provide commented, minimal, self-contained, reproducible code.


[R] creating bins for a plot

2006-10-18 Thread Jeffrey Stratford
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
15  1   0.07046477  0.03355705
.
.
.



Jeffrey A. Stratford, Ph.D.
Postdoctoral Associate
331 Funchess Hall
Department of Biological Sciences
Auburn University
Auburn, AL 36849
334-329-9198
FAX 334-844-9234
http://www.auburn.edu/~stratja

__
R-help@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
and provide commented, minimal, self-contained, reproducible code.