-
Notifications
You must be signed in to change notification settings - Fork 0
/
errorTypes.R
106 lines (79 loc) · 2.37 KB
/
errorTypes.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# Written by Micha³ Makowski
source("auxilaryFunctions.R") # upper, isZero
require(igraph, quietly = TRUE) # edge_connectivity, graph_from_adjacency_matrix
# Measures
# H_0: x_ij == 0
# H_1: x_ij != =
# False positive
FP <- function(estimatedMatrix,
adjacentMatrix)
{
estimatedMatrix <- upper(estimatedMatrix)
adjacentMatrix <- upper(adjacentMatrix)
FP <- sum((estimatedMatrix != 0) & !adjacentMatrix)
return(FP)
}
# True positive
TP <- function(estimatedMatrix,
adjacentMatrix)
{
estimatedMatrix <- upper(estimatedMatrix)
adjacentMatrix <- upper(adjacentMatrix)
TP <- sum((estimatedMatrix != 0) & adjacentMatrix)
return(TP)
}
# False negative
FN <- function(estimatedMatrix,
adjacentMatrix)
{
estimatedMatrix <- upper(estimatedMatrix)
adjacentMatrix <- upper(adjacentMatrix)
FN <- sum((estimatedMatrix == 0) & adjacentMatrix)
return(FN)
}
# True negative
TN <- function(estimatedMatrix,
adjacentMatrix)
{
estimatedMatrix <- upper(estimatedMatrix)
adjacentMatrix <- upper(adjacentMatrix)
TN <- sum((estimatedMatrix == 0) & !adjacentMatrix)
return(TN)
}
# False dicovery proportion
FDP <- function(estimatedMatrix,
adjacentMatrix)
{
predictedPositive <- max(c(sum(upper(estimatedMatrix) != 0), 1))
return(FP(estimatedMatrix, adjacentMatrix)/predictedPositive)
}
# Local FDP
localFDP <- function(estimatedMatrix,
adjacentMatrix)
{
adjacentMatrixIG <- graph_from_adjacency_matrix(adjacentMatrix)
for (i in seq_len(NCOL(adjacentMatrix)-1)+1)
{
for (j in seq_len(i-1))
{
adjacentMatrix[j,i] <- !(edge_connectivity(adjacentMatrixIG, j, i) == 0)
}
}
predictedPositive <- max(c(sum(upper(estimatedMatrix) != 0), 1))
return(FP(estimatedMatrix, adjacentMatrix)/predictedPositive)
# return(adjacentMatrix)
}
# Sensitivity
SN <- function(estimatedMatrix,
adjacentMatrix)
{
realPositive <- max(c(sum(upper(adjacentMatrix)), 1))
return(TP(estimatedMatrix, adjacentMatrix)/realPositive)
}
# Specificity
SP <- function(estimatedMatrix,
adjacentMatrix)
{
realNegative <- max(c(sum(!upper(adjacentMatrix)), 1))
return(TN(estimatedMatrix, adjacentMatrix)/realNegative)
}