Learn R Programming

mri (version 0.1.1)

mari1: Modified Adjusted Rand Index 1

Description

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

Usage

mari1(U, V, outgoing.name, k = 500)

Arguments

U

Partition U.

V

Partition V'.

outgoing.name

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

k

Number of permutations.

Value

The function returns the value of the Modified Adjusted Rand Index 1. The expected value of the index in the case of two random and independant partitions is 0. The maximum value of the index is 1. Higher value indicates more similar (stable) partitions. The splitting of clusters lowers the value of the index, but the merging of clusters does not affect the value of the index.

References

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

See Also

Other types of Modified Rand Index: mri21, mri22.

Modified Adjusted Rand Index: mari1, mari21, mari22.

Examples

Run this code
# NOT RUN {
# 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)

# example 1
cont.table <- 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(cont.table) <- c(1:4)
colnames(cont.table) <- c(1:5)
example.Model[[1]] <- cont.table

# example 2
cont.table <- 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(cont.table) <- c(1:4)
colnames(cont.table) <- c(1:5)
example.Model[[2]] <- cont.table

# example 3
cont.table <- rbind(c(0,  0, 0, 0, 0),
                c(10, 10, 0, 0, 0),
                c( 0,  0, 10, 0, 0),
                c(0, 0,  0,   5, 5))
rownames(cont.table) <- c(1:4)
colnames(cont.table) <- c(1:5)
example.Model[[3]] <- cont.table

# COMPUTE MRI1
# example 1
U <- fromTableToVectors(example.Model[[1]])[,1]
V <- fromTableToVectors(example.Model[[1]])[,2]
mari1(U = U, V = V, outgoing.name = 4, k = 500)

# example 2
U <- fromTableToVectors(example.Model[[2]])[,1]
V <- fromTableToVectors(example.Model[[2]])[,2]
mari1(U = U, V = V, outgoing.name = 4, k = 500)

# example 3
U <- fromTableToVectors(example.Model[[3]])[,1]
V <- fromTableToVectors(example.Model[[3]])[,2]
mari1(U = U, V = V, outgoing.name = 4, k = 500)
# }

Run the code above in your browser using DataLab