[R] misclassification matrix

Gregory Ryslik rsaber at comcast.net
Wed Oct 6 17:19:23 CEST 2010


HI Everyone,

I am working with the following situation. I have n observations and j possible outcomes and each one of the n observations is assigned a class from 1 to j.  Furthermore, this process is done m times (for some large m > 1000). 

What I want to do is create a misclassification matrix which tells me for each one of the possible classes, how many observations were classified correctly, and then how many were incorrectly at each level. Here is an example of what I mean

	0 	1	 2	Misclassification 
0     100 250  50   .75
1	25	100	25	.333333
2	10	5	40   .2727273


For each one of the 1 to j elements, I can use a nested for loop to count how many were classified as 0, are in 1, etc and then construct such matrix. Thus for each element I have j comparisons and then I have j total rows leading to an O(j^2) running time.

 Any way I can avoid such a for loop and perhaps make it run a bit quicker? If not, any ideas then at least how to avoid the double for loop and make the code more aesthetically pleasing?

As always, thank you for your help!

Kind regards,
Greg


More information about the R-help mailing list