# [R] Counting things

William Dunlap wdunlap at tibco.com
Wed Aug 5 19:11:43 CEST 2009

```> -----Original Message-----
> From: r-help-bounces at r-project.org
> [mailto:r-help-bounces at r-project.org] On Behalf Of Noah Silverman
> Sent: Tuesday, August 04, 2009 8:40 PM
> To: r help
> Subject: [R] Counting things
>
> I've completed an experiment and want to summarize the results.
>
> There are two things I like to create.
>
> 1) A simple count of things from the data.frame with predictions
>      1a) Number of predictions with probability greater than x

sum(logicalVector) returns the number of TRUEs in logicalVector,
because it converts TRUE to 1 and FALSE to 0 before doing the sum.
You will have to use na.rm=TRUE if there are NA's (missing values)
in logical vector.  Hence you get compute 1a with
sum(probabilities>x)
mean(probabilities>x) will give the proportion of times probabilities>x
is
TRUE. table(probabilities>x) will give a count of both the FALSEs and
TRUEs.

>      1b) Number of predictions with probability greater than
>           x that are  really true

sum(probabilities>x & label=="T")
(I'm guessing that label is a character or factor vector with values
"T" and "F".)

Bill Dunlap
TIBCO Software Inc - Spotfire Division
wdunlap tibco.com

>
>      In SQL, this would be,
>          "Select count(predictions) from data.frame where
> probability > x"
> "Select count(predictions) from data.frame where probability > x and
> label ='T' "
>
> How can I do this one in R?
>
>
> 2) I'd like to create what we call "binning".  It is a simple list of
> probability ranges and how accurate our model is.  The idea is to see
> how "true" our probabilities are.
> for example
>
> range        number of items        mean(probability)   true_accuracy
> 100-90%        20                            .924
>        .90
> 90-80%          50                            .825
>         .84
> 80-70%          214                          .75
>         .71
> etc...
>
> It would be really great if I could also graph this!
>
> Is there any kind of package or way to do this in R
>
> Thanks!
>
> -N
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help