mri21: Modified Rand Index 2.1

Description Usage Arguments Value Author(s) References See Also Examples

View source: R/mri21.R

Description

mri21 is used to compute the value of the Modified Rand Index 2.1. It considers two partitions U' and V, which are usually obtained on two sets of units S and T, where S is a subset of T. Because two vectors U and V do not have the same length, the cluster of units, which are not present in the partition U, need to be added to the partition U (denoted as U'). This can be done manually or with function merge.

Usage

1
mri21(U, V, incoming.name)

Arguments

U

Partition U'.

V

Partition V.

incoming.name

The label of added cluster (see Description). Do not specify this argument if there is no added values.

Value

The function returns the value of the Modified Rand Index 2.1. The index can take the value on the interval [0, 1], where higher value indicates more similar (stable) partitions. While the splitting of clusters lowers the value of the index, the merging of clusters does not affect the value of the index. The difference in the number of units between two sets of units S and T lower the value of the index.

Author(s)

Marjan Cugmas

References

Cugmas M. and Ferligoj A. (2015). On comparing partitions. submitted

See Also

Other types of Modified Rand Index: mri1, mri22.

Modified Adjusted Rand Index: mari1, mari21, mari22.

Examples

 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
# THIS FUNCTION CONVERT THE CONTINGENCY TABLE INTO TWO VECTORS
fromTableToVectors <- function(cont.table){
  dat <- matrix(ncol = 2)
  for (j in 1:dim(cont.table)[2]){
    for (i in 1:dim(cont.table)[1]){
      if (cont.table[i, j] >= 1){
        for (t in 1:cont.table[i,j]){
          imei <- rownames(cont.table)[i]
          imej <- colnames(cont.table)[j]
          dat <- rbind(dat, c(imei, imej))
        }
      }
    }
  }
  dat <- dat[-1,]
  return(dat)
}

# DATA
example.Model <- list(NULL)

tabela <- rbind(c(0, 10, 0, 0, 0),
                c(10, 0, 0, 0, 0),
                c(0, 0, 10, 0, 0),
                c(0, 0,  0, 5, 5))
rownames(tabela) <- c("1", "2", "3", "4")
colnames(tabela) <- c("1", "2", "3", "4", "5")
example.Model[[1]] <- t(tabela)

tabela <- rbind(c(0, 10, 0, 0, 0),
                c(0, 10, 0, 0, 0),
                c(0, 0, 10, 0, 0),
                c(0, 0,  0, 5, 5))
rownames(tabela) <- c("1", "2", "3", "4")
colnames(tabela) <- c("1", "2", "3", "4", "5")
example.Model[[2]] <- t(tabela)

tabela <- rbind(c(0,  0, 0, 0, 0),
                c(10, 10, 0, 0, 0),
                c( 0,  0, 5, 0, 5),
                c(0, 0,  0,   5, 5))
rownames(tabela) <- c("1", "2", "3", "4")
colnames(tabela) <- c("1", "2", "3", "4", "5")
example.Model[[3]] <- t(tabela)

# COMPUTE MRI22

# example 1
U <- fromTableToVectors(example.Model[[1]])[,1]
V <- fromTableToVectors(example.Model[[1]])[,2]
mri21(U = U, V = V, incoming.name = 4)

# example 2
U <- fromTableToVectors(example.Model[[2]])[,1]
V <- fromTableToVectors(example.Model[[2]])[,2]
mri21(U = U, V = V, incoming.name = 4)

# example 3
U <- fromTableToVectors(example.Model[[3]])[,1]
V <- fromTableToVectors(example.Model[[3]])[,2]
mri21(U = U, V = V, incoming.name = 5)

mri documentation built on May 30, 2017, 8:18 a.m.