Re: [R] Is there a function for this?

2007-01-03 Thread Andreas Hary
Try the following:

act <- c('good','good','bad','bad','good','good','bad','bad')
pred <- c('good','bad','bad','bad','good','good','good','bad')
table(pred,act)
table(pred,act)/apply(table(pred,act),1,sum)

Cheers,

Andreas


On 1/3/07, Feng Qiu <[EMAIL PROTECTED]> wrote:
> Hi everybody, I'm trying to do a statistic on the error rate of a prediction
> algorithm.
>
> suppose this is the real category
> [good, good, bad, bad, good, good, bad, bad]
> this is the predicted category
> [good, bad, bad, bad, good, good, good, bad]
>
> I'm trying to do a statistic on the error rate for each group("good","bad"):
> what percentage of instances are predicted incorrectly for each group ?
> Of course I can write a loop to do that, but is there a easy way to do that?
>
> Thank you!
>
> Best,
>
> Feng
>
> __
> 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.


Re: [R] Is there a function for this?

2007-01-03 Thread Gabor Grothendieck
Try this:

> actual <- factor(c("good", "good", "bad", "bad", "good", "good", "bad", 
> "bad"))
> pred <- factor(c("good", "bad", "bad", "bad", "good", "good", "good", "bad"))

> table(actual, pred)
  pred
actual bad good
  bad31
  good   13

> prop.table(table(actual, pred), 1)
  pred
actual  bad good
  bad  0.75 0.25
  good 0.25 0.75

> prop.table(table(actual, pred), 2)
  pred
actual  bad good
  bad  0.75 0.25
  good 0.25 0.75

> library(gmodels)
> CrossTable(actual, pred)


   Cell Contents
|-|
|   N |
| Chi-square contribution |
|   N / Row Total |
|   N / Col Total |
| N / Table Total |
|-|


Total Observations in Table:  8


 | pred
  actual |   bad |  good | Row Total |
-|---|---|---|
 bad | 3 | 1 | 4 |
 | 0.500 | 0.500 |   |
 | 0.750 | 0.250 | 0.500 |
 | 0.750 | 0.250 |   |
 | 0.375 | 0.125 |   |
-|---|---|---|
good | 1 | 3 | 4 |
 | 0.500 | 0.500 |   |
 | 0.250 | 0.750 | 0.500 |
 | 0.250 | 0.750 |   |
 | 0.125 | 0.375 |   |
-|---|---|---|
Column Total | 4 | 4 | 8 |
 | 0.500 | 0.500 |   |
-|---|---|---|





On 1/3/07, Feng Qiu <[EMAIL PROTECTED]> wrote:
> Hi everybody, I'm trying to do a statistic on the error rate of a prediction
> algorithm.
>
> suppose this is the real category
> [good, good, bad, bad, good, good, bad, bad]
> this is the predicted category
> [good, bad, bad, bad, good, good, good, bad]
>
> I'm trying to do a statistic on the error rate for each group("good","bad"):
> what percentage of instances are predicted incorrectly for each group ?
> Of course I can write a loop to do that, but is there a easy way to do that?
>
> Thank you!
>
> Best,
>
> Feng
>

__
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] Is there a function for this?

2007-01-03 Thread Feng Qiu
Hi everybody, I'm trying to do a statistic on the error rate of a prediction 
algorithm.

suppose this is the real category
[good, good, bad, bad, good, good, bad, bad]
this is the predicted category
[good, bad, bad, bad, good, good, good, bad]

I'm trying to do a statistic on the error rate for each group("good","bad"): 
what percentage of instances are predicted incorrectly for each group ?
Of course I can write a loop to do that, but is there a easy way to do that?

Thank you!

Best,

Feng

__
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.