[R] misclassification rate
Patrick Breheny
patrick.breheny at uky.edu
Sat Sep 3 12:03:13 CEST 2011
On 09/02/2011 05:29 PM, Doussa wrote:
> I have a matrix in wich there are two colmns( yp, yt)
> Yp: predicted values from my model.
> yt: true values ( my dependante variable y is a categorical;3 modalities
> (0,1,2)
> I don't know how to procede to calculate the misclassification rate and the
> error Types.
Suppose your data looks like this:
> yp <- sample(0:2,50,replace=TRUE)
> yt <- sample(0:2,50,replace=TRUE)
You can create a cross-classification table with:
> tab <- table(yp,yt)
> tab
yt
yp 0 1 2
0 5 8 5
1 2 11 9
2 1 2 7
And the misclassification rate is
> 1-sum(diag(tab))/sum(tab)
[1] 0.54
--
Patrick Breheny
Assistant Professor
Department of Biostatistics
Department of Statistics
University of Kentucky
More information about the R-help
mailing list