The intra Hamming distance of two sets of CRPs measures the numbers of CRPs that differ. N sets of CRPs are equal if their intra Hamming distances are 0.
A response is reliable if it does not change in time, thus, its intra Hamming distance is equal to 0.
If crps
is a 2D matrix, it is assumed that each row corresponds to a sample and each column to a CRP. The ref_sample
will dictate which row is the sample taken as reference. In the case of a 3D matrix, each row corresponds to a device, each column to a CRP and the 3rd dimension represents the different samples.
Arguments
- crps
A binary vector, 2D matrix or 3D array.
- ref
Numeric index for the reference sample: If
crps
is a vector, is the index of the reference sample; Ifcrps
is a 2D matrix, the row to use as reference; Ifcrps
is a 3D array, the row for all 3rd dimension matrix.
Value
If crps
is a vector, the intra Hamming distance of the vector. If crps
is a 2D matrix, the reliability of each column as a vector of size ncol(crps) - 1
. If crps
is a 3D array, a 2D matrix where each row contains the intra Hamming distance all samples.
TODO: Maybe return the list of comparison to calculate the mean and sd
Details
The order of the samples is calculated as setdiff(seq_len(nsamples), ref_sample)
where nsamples
corresponds to nrow(crps)
in the case of a 2D matrix and dim(crps)[3]
in the case of a 3D matrix.
Examples
## Bit values
v <- c(1, 0, 0, 1, 1)
intra_hd(v, 1)
#> [1] 0 0 1 1
## Set of CRPs
mat <- rbits(c(5, 10))
intra_hd(mat, 1)
#> [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
#> [1,] 0 0 1 0 1 1 0 0 1 0
#> [2,] 1 1 1 1 1 1 1 0 0 1
#> [3,] 0 1 0 1 1 0 1 0 1 1
#> [4,] 1 0 1 1 1 1 0 0 0 0
## Set of devices with their respective samples
mat <- rbits(c(5, 10, 3))
intra_hd(mat)
#> [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
#> [1,] 0.5 0.5 0.0 0.5 1.0 0.0 0.5 0.0 0.5 0.0
#> [2,] 0.5 0.0 0.5 0.0 0.5 0.5 0.5 1.0 1.0 0.5
#> [3,] 1.0 0.5 0.0 0.0 1.0 0.5 0.5 0.5 1.0 0.5
#> [4,] 0.0 1.0 0.5 1.0 0.0 0.5 1.0 1.0 0.0 1.0
#> [5,] 1.0 1.0 0.5 1.0 1.0 0.5 0.5 0.5 0.5 0.5