# match.vec2mat: Transform a matching vector to a binary matching matrix In hamlet: Hierarchical Optimal Matching and Machine Learning Toolbox

## Description

This function allows transforming a matching vector to a binary matching matrix. A matching vector is of length N where each element indicates the submatch to which the observation belongs to. Notice that this is not the same as the group allocation vector that is provided by the match.allocate-function. The binary matching matrix is of size N x N where 0 indicates that the observations have been part of a different submatch, and 1 indicates that the observations have been part of the same submatch. Diagonal is always 0 although an observation is always in the same submatch with its self.

## Usage

 `1` ```match.vec2mat(x) ```

## Arguments

 `x` A matching vector 'x'

## Value

N times N binary matching matrix, where 0 indicates that the observations have been part of a different submatch, and 1 indicates that the observations have been part of the same submatch.

## Author(s)

Teemu Daniel Laajala <teelaa@utu.fi>

`match.allocate` `match.mat2vec` `match.bb` `match.dummy`

## Examples

 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18``` ```data(vcapwide) # Construct an Euclidean distance example distance matrix using 15 observations from the VCaP study d <- as.matrix(dist(vcapwide[1:15,c("PSAWeek10", "BWWeek10")])) bb3 <- match.bb(d, g=3) str(bb3) solvec <- bb3\$solution # matching vector, where each element indicates to which submatch each observation belongs to solvec mat <- match.vec2mat(solvec) mat which(mat[1,] == 1) # E.g. the first, third and thirteenth observation are part of the same submatch which(solvec == solvec[1]) # Similarly ```

### Example output

```[1] "Performing initial sorting for a good initial guess"
[1] "Computing boundaries for minimum distances in possible combinations..."
[1] "Starting branch and bound"
[1] "Branches: 18"
[1] "Bounds: 357"
[1] "Ends visited: 4"
[1] "Solution cost 73.1793785290756"
[1] "Solution: 3,1,3,5,2,4,4,5,1,2,2,5,3,4,1"
List of 6
\$ branches: num 18
\$ bounds  : num 357
\$ ends    : num 4
\$ matrix  : num [1:15, 1:15] 0 0 1 0 0 0 0 0 0 0 ...
..- attr(*, "dimnames")=List of 2
.. ..\$ : chr [1:15] "ID003" "ID007" "ID008" "ID009" ...
.. ..\$ : chr [1:15] "ID003" "ID007" "ID008" "ID009" ...
\$ solution: Named num [1:15] 3 1 3 5 2 4 4 5 1 2 ...
..- attr(*, "names")= chr [1:15] "ID003" "ID007" "ID008" "ID009" ...
\$ cost    : num 73.2
ID003 ID007 ID008 ID009 ID010 ID016 ID018 ID025 ID027 ID031 ID032 ID037 ID040
3     1     3     5     2     4     4     5     1     2     2     5     3
ID045 ID047
4     1
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13]
[1,]    0    0    1    0    0    0    0    0    0     0     0     0     1
[2,]    0    0    0    0    0    0    0    0    1     0     0     0     0
[3,]    1    0    0    0    0    0    0    0    0     0     0     0     1
[4,]    0    0    0    0    0    0    0    1    0     0     0     1     0
[5,]    0    0    0    0    0    0    0    0    0     1     1     0     0
[6,]    0    0    0    0    0    0    1    0    0     0     0     0     0
[7,]    0    0    0    0    0    1    0    0    0     0     0     0     0
[8,]    0    0    0    1    0    0    0    0    0     0     0     1     0
[9,]    0    1    0    0    0    0    0    0    0     0     0     0     0
[10,]    0    0    0    0    1    0    0    0    0     0     1     0     0
[11,]    0    0    0    0    1    0    0    0    0     1     0     0     0
[12,]    0    0    0    1    0    0    0    1    0     0     0     0     0
[13,]    1    0    1    0    0    0    0    0    0     0     0     0     0
[14,]    0    0    0    0    0    1    1    0    0     0     0     0     0
[15,]    0    1    0    0    0    0    0    0    1     0     0     0     0
[,14] [,15]
[1,]     0     0
[2,]     0     1
[3,]     0     0
[4,]     0     0
[5,]     0     0
[6,]     1     0
[7,]     1     0
[8,]     0     0
[9,]     0     1
[10,]     0     0
[11,]     0     0
[12,]     0     0
[13,]     0     0
[14,]     0     0
[15,]     0     0
[1]  3 13
ID003 ID008 ID040
1     3    13
```

hamlet documentation built on May 1, 2019, 8:40 p.m.