match.vec2mat {hamlet} | R Documentation |
Transform a matching vector to a binary matching matrix
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
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>
See Also
match.allocate
match.mat2vec
match.bb
match.dummy
Examples
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