# 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]
mri1(U = U, V = V, outgoing.name = 4)
# example 2
U <- fromTableToVectors(example.Model[[2]])[,1]
V <- fromTableToVectors(example.Model[[2]])[,2]
mri1(U = U, V = V, outgoing.name = 4)
# example 3
U <- fromTableToVectors(example.Model[[3]])[,1]
V <- fromTableToVectors(example.Model[[3]])[,2]
mri1(U = U, V = V, outgoing.name = 4)
# }
Run the code above in your browser using DataLab