nodematch(x) returns an n x n matrix with 1 where
x[i] == x[j] and 0 otherwise – the AME analogue of ERGM's
nodematch term, suitable for Xdyad as a single
homophily covariate. absdiff(x) returns the absolute difference
|x[i] - x[j]|, the AME analogue of ERGM's absdiff.
nodefactor(x) returns the dyadic matrix of x[i] + x[j] for
a numeric x (or, for a factor / character x, a named list
with one matrix per level giving the dyadic co-membership count
(x[i] == level) + (x[j] == level), with entries 0, 1, or 2, the
ERGM nodefactor semantics).
Value
An n x n numeric matrix (or, for a factor x passed
to nodefactor, a named list of such matrices).
Details
All helpers return a matrix or list of matrices that is ready to
wrap into an n x n x p Xdyad array via simplify2array
or array().
Examples
# \donttest{
n <- 12
grp <- sample(letters[1:3], n, replace = TRUE)
age <- rnorm(n, 40, 10)
# build a single same-group homophily covariate
Xdyad <- array(nodematch(grp), dim = c(n, n, 1),
dimnames = list(NULL, NULL, "same_group"))
# combine homophily + age difference
Xdyad <- array(c(nodematch(grp), absdiff(age)),
dim = c(n, n, 2),
dimnames = list(NULL, NULL, c("same_group", "age_diff")))
# }