Hi guys, I will be very grateful if you guys can do me a little favor on R. I am calculating the sensitivity and specificity for a 2*2 matrix, such as t 0 1 0 1427 110 1 271 166 My codes are: sens <- function(ct) { ct[2,2] / sum(ct[,2]) } spec <- function(ct) { ct[1,1] / sum(ct[,1]) } But it doesn't show any numerical results. Would you please help me to fix it? Mnay thanks for your help.:) Best regards, Siqi [[alternative HTML version deleted]]
On Apr 25, 2014, at 10:58 AM, Si Qi L. wrote:> Hi guys, > > I will be very grateful if you guys can do me a little favor on R. I am > calculating the sensitivity and specificity for a 2*2 matrix, such as > > t > 0 1 > 0 1427 110 > 1 271 166 > > > > My codes are: sens <- function(ct) { ct[2,2] / sum(ct[,2]) } > spec <- function(ct) { ct[1,1] / sum(ct[,1]) } > > But it doesn't show any numerical results.What is the "it" that doesn't show any results? You show no code that uses these functions and you don't even include a reproducible example for `t`. (BTW using 't' as an object name may cause confusion since t() is a commonly used matrix function.> Would you please help me to fix > it? Mnay thanks for your help.:) > > Best regards, > > Siqi > > [[alternative HTML version deleted]]And please take the time to read the Posting Guide and learn to post in plain text as requested there.> > ______________________________________________ > R-help at r-project.org 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.David Winsemius Alameda, CA, USA
Try this:> sens <- function(ct) { ct[2,2] / sum(ct[,2]) } > spec <- function(ct) { ct[1,1] / sum(ct[,1]) } > > > myt <- matrix( c(1427,271,110,166), ncol=2) > > sens(myt)[1] 0.6014493> > spec(myt)[1] 0.8404005>-Don -- Don MacQueen Lawrence Livermore National Laboratory 7000 East Ave., L-627 Livermore, CA 94550 925-423-1062 On 4/25/14 10:58 AM, "Si Qi L." <liusiqi.nine at gmail.com> wrote:>Hi guys, > >I will be very grateful if you guys can do me a little favor on R. I am >calculating the sensitivity and specificity for a 2*2 matrix, such as > > t > 0 1 > 0 1427 110 > 1 271 166 > > > >My codes are: sens <- function(ct) { ct[2,2] / sum(ct[,2]) } > spec <- function(ct) { ct[1,1] / sum(ct[,1]) } > >But it doesn't show any numerical results. Would you please help me to fix >it? Mnay thanks for your help.:) > >Best regards, > >Siqi > > [[alternative HTML version deleted]] > >______________________________________________ >R-help at r-project.org 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.