[R] plotting percent of incidents within different 'bins'

james.holtman@convergys.com james.holtman at convergys.com
Wed Jan 5 22:04:35 CET 2005





You can use 'cut' to create the breaks..  Actually there are 8 in the 3-4
range:

   Outcome predictor
1        0         1
2        1         2
3        1         2
4        0         3
5        0         3
6        0         2
7        1         3
8        1         4
9        1         4
10       0         4
11       0         4
12       0         4
> cut(x.1$p, breaks=c(0,2,4))
 [1] (0,2] (0,2] (0,2] (2,4] (2,4] (0,2] (2,4] (2,4] (2,4] (2,4] (2,4]
(2,4]
Levels: (0,2] (2,4]
> x.c <- cut(x.1$p, breaks=c(0,2,4))
> tapply(x.1$O, x.c, function(x)sum(x==1)/length(x))
(0,2] (2,4]
0.500 0.375
>
__________________________________________________________
James Holtman        "What is the problem you are trying to solve?"
Executive Technical Consultant  --  Office of Technology, Convergys
james.holtman at convergys.com
+1 (513) 723-2929


                                                                                                                                           
                      "Stephen Choularton"                                                                                                 
                      <mail at bymouth.com>           To:       "R Help" <r-help at stat.math.ethz.ch>                                           
                      Sent by:                     cc:                                                                                     
                      r-help-bounces at stat.m        Subject:  [R] plotting percent of incidents within different 'bins'                     
                      ath.ethz.ch                                                                                                          
                                                                                                                                           
                                                                                                                                           
                      01/05/2005 14:34                                                                                                     
                                                                                                                                           
                                                                                                                                           




Hi

Say I have some data, two columns in a table being a binary outcome plus
a predictor and I want to plot a graph that shows the percentage
positives of the binary outcome within bands of the predictor, e.g.


Outcome           predictor

0                      1
1                      2
1                      2
0                      3
0                      3
0                      2
1                      3
1                      4
1                      4
0                      4
0                      4
0                      4
etc

In this case there are 4 cases in the band 1 - 2 of the predictor, 2 of
them are true so the percent is 50% and there are 7 cases in the band 3
- 4, 3 of which are true making the percentage 43% .

Is there some function in R that will sum these outcomes by bands of
predictor and produce a one by two  data set with the percentages in one
column and the ordered bands in the other, or alternately is there some
sort of special plot.???? that does it all for you?

Thanks

Stephen



             [[alternative HTML version deleted]]

______________________________________________
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