user94790
user94790

Reputation: 1

Sensitivity and Specificity in R

I want to know how i can write a functions Sensitivity() and Specificity() that help me to compute Sensitivity and Specificity by using R ? What options can help me?

Upvotes: 0

Views: 1774

Answers (1)

Tim Assal
Tim Assal

Reputation: 687

Here is a method using the caret package and it includes a reproducible example (i.e. a bit of code that someone can quickly run to help you out) from the help files of the caret package. @llottmanhill is correct that you will get more help when you tell us what you are trying to do. Right now your question is quite vague. However, give this a shot:

library(caret)
library(MASS)

fit <- lda(Species ~ ., data = iris)
model <- predict(fit)$class

irisTabs <- table(model, iris$Species)

## When passing factors, an error occurs with more
## than two levels
sensitivity(model, iris$Species)

## When passing a table, more than two levels can
## be used
sensitivity(irisTabs, "versicolor")
specificity(irisTabs, c("setosa", "virginica"))

Upvotes: 1

Related Questions