Skip to contents

Convenience wrapper that takes an igraph or network object and returns the kind of matrix that ame / lame expect: a numeric adjacency matrix with NA on the diagonal (self-ties not modelled) and (if available) actor names preserved on the row/column dimnames.

Usage

as_lame_y(x, na_diag = TRUE)

Arguments

x

an igraph, network, matrix, or data.frame representing an adjacency / sociomatrix.

na_diag

logical: replace the diagonal with NA? Defaults to TRUE for square (unipartite) matrices and is ignored for rectangular (bipartite) matrices.

Value

A numeric matrix suitable to pass as Y to ame / lame.

Details

Plain matrices and data.frames are accepted too; data.frames are coerced to a numeric matrix and only the diagonal is rewritten to NA.

Examples

# plain matrices are returned with the diagonal set to NA
m <- matrix(rbinom(25, 1, 0.4), 5, 5,
            dimnames = list(letters[1:5], letters[1:5]))
as_lame_y(m)
#>    a  b  c  d  e
#> a NA  0  0  0  0
#> b  0 NA  0  1  0
#> c  0  1 NA  0  1
#> d  0  1  1 NA  0
#> e  0  0  1  0 NA

if (requireNamespace("igraph", quietly = TRUE)) {
  g <- igraph::sample_gnp(8, 0.3)
  Y <- as_lame_y(g)
  dim(Y)
}
#> [1] 8 8