binary_triangular_matrix: Get binary triangular matrices

View source: R/binary_triangular_matrix.R

binary_triangular_matrixR Documentation

Get binary triangular matrices

Description

binary_triangular_matrix creates binary triangular matrices representing categorical data in a distance matrix form

Usage

binary_triangular_matrix(group, labels = NULL)

Arguments

group

Character vector or factor containing categories to be represented as a pairwise binary matrix. Several observations per categories (at least some categories) are required.

labels

Character vector or factor containing labels to be used for rows/columns in the output matrix. Optional. Default is NULL.

Details

The function creates binary triangular matrices representing categorical data in a pairwise distance matrix form. Such matrices represent group membership by assigning 0 to pairs of observations that belong to the same category (individual, group, population) and 1 to those belonging to different categories. Binary pairwise matrices can be useful to evaluate association between a categorical and continuous variable (represented as pairwise distances) using Mantel test (as in Araya-Salas et al. 2019).

Value

A pairwise distance matrix that represents group membership. See details.

Author(s)

Marcelo Araya-Salas marcelo.araya@ucr.ac.cr)

References

Araya-Salas, M, & K. Odom. 2022, PhenotypeSpace: an R package to quantify and compare phenotypic trait spaces R package version 0.1.0.

Araya-Salas M, G Smith-vidaurre, D Mennill, P González-Gómez, J Cahill & T Wright. 2019. Social group signatures in hummingbird displays provide evidence of co-occurrence of vocal and visual learning. Proceedings of the Royal Society B. 286: 20190666.

Smouse PE, Long JC, Sokal RR. 1986 Multiple regression and correlation extensions of the Mantel test of matrix correspondence. Syst. Zool. 35, 627–632.

See Also

distance_to_rectangular, rectangular_to_triangular

Examples

{
# create 3 groups each one with 2 observations
groups <- paste0("G", rep(1:3, each = 2))
# create binary matrix
binary_triangular_matrix(group = groups)

# create binary matrix using labels
binary_triangular_matrix(group = groups, labels = paste(groups, 1:6, sep = "-"))
}

maRce10/PhenotypeSpace documentation built on July 3, 2025, 8:44 p.m.