Learn R Programming

ebdbNet (version 1.1)

sensitivity: Calculate Sensitivity and Specificity of a Network

Description

Function to calculate the true positives (TP), true negatives (TN), false positives (FP), and false negatives (FN) of an estimated network, given the structure of the true network.

Usage

sensitivity(trueMatrix, estMatrix)

Arguments

trueMatrix
Posterior mean or adjacency matrix of the true network
estMatrix
Posterior mean or adjacency matrix of the estimated network

Value

  • TPNumber of true positives
  • FPNumber of false positives
  • FNNumber of false negatives
  • TNNumber of true negatives

Details

The matrices trueMatrix and estMatrix must be of the same dimension.

See Also

calcAUC

Examples

Run this code
library(ebdbNet)
tmp <- runif(1) ## Initialize random number generator
set.seed(16933) ## Set seed
P <- 10 ## 10 genes

## Create artificial true D matrix
Dtrue <- matrix(0, nrow = P, ncol = P)
index <- expand.grid(seq(1:P),seq(1:P))
selected.index <- sample(seq(1:(P*P)), ceiling(0.25 * P * P))
selected.edges <- index[selected.index,]
for(edge in 1:ceiling(0.25 * P * P)) {
	tmp <- runif(1)
	if(tmp > 0.5) {
		Dtrue[selected.edges[edge,1], selected.edges[edge,2]] <-
			runif(1, min = 0.2, max = 1)
	}
	else {
		Dtrue[selected.edges[edge,1], selected.edges[edge,2]] <-
			runif(1, min = -1, max = -0.2)
	}
}

## Create artificial estimated D matrix
Dest <- matrix(0, nrow = P, ncol = P)
index <- expand.grid(seq(1:P),seq(1:P))
selected.index <- sample(seq(1:(P*P)), ceiling(0.25 * P * P))
selected.edges <- index[selected.index,]
for(edge in 1:ceiling(0.25 * P * P)) {
	tmp <- runif(1)
	if(tmp > 0.5) {
		Dest[selected.edges[edge,1], selected.edges[edge,2]] <-
			runif(1, min = 0.2, max = 1)
	}
	else {
		Dest[selected.edges[edge,1], selected.edges[edge,2]] <-
			runif(1, min = -1, max = -0.2)
	}
}

check <- sensitivity(Dtrue, Dest)
check$TP ## 5 True Positives
check$FP ## 20 False Positives
check$TN ## 55 True Negatives
check$FN ## 20 False Negatives

Run the code above in your browser using DataLab