Skip to content

Specificity returns NaN #32

Description

@luca-scr

I got this behavior which looks like a bug. It appears both in the package from CRAN and in the latest version from GitHub. Here is a reproducible example:

library(ModelMetrics)
observed <- structure(c(1L, 1L, 2L, 1L, 1L, 2L, 1L, 1L, 1L, 1L), .Label = c("+", "-"), class = "factor")
yprob <- c(0.11, 0.19, 0.89, 0.3, 0.33, 0.92, 0.48, 0.03, 0.09, 0.13)
sensitivity(observed, yprob, 0.1)
sensitivity(observed, yprob, 0.2)
sensitivity(observed, yprob, 0.3)
sensitivity(observed, yprob, 0.4)
sensitivity(observed, yprob, 0.5)
specificity(observed, yprob, 0.6)
specificity(observed, yprob, 0.7)
specificity(observed, yprob, 0.8)
specificity(observed, yprob, 0.9)
specificity(observed, yprob, 1.0)

Notice that sensitivity() accepts a factor as input but the same is not valid for specificity(). Using as.numeric(observed) doesn't work, but it is ok if as.numeric(observed == "+") is used.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions