vertex_covariate_dist(graph, X, p = 2)
vertex_mahalanobis_dist(graph, X, S)
ncol(x)
. Usually the var-covar matrix.dgCMatrix
. Will
be symmetric only if graph
is symmetric.
dist
, these functions compute distance metrics
between pairs of vertices that are connected (otherwise skip).The function vertex_covariate_dist
is the simil of dist
and returns p-norms. It is implemented as follows (for each pair of vertices):
In the case of mahalanobis distance, for each pair of vertex $(i,j)$, the distance is computed as follows:
mahalanobis
in the stats package.Other statistics: classify_adopters
,
cumulative_adopt_count
, dgr
,
ego_variance
, exposure
,
hazard_rate
, infection
,
moran
, struct_equiv
,
threshold
# Distance (aka p norm) -----------------------------------------------------
set.seed(123)
G <- rgraph_ws(20, 4, .1)
X <- matrix(runif(40), ncol=2)
vertex_covariate_dist(G, X)
# Mahalanobis distance ------------------------------------------------------
S <- var(X)
M <- vertex_mahalanobis_dist(G, X, S)
# Example with diffnet objects ----------------------------------------------
data(medInnovationsDiffNet)
X <- cbind(
medInnovationsDiffNet[["proage"]],
medInnovationsDiffNet[["attend"]]
)
S <- var(X, na.rm=TRUE)
ans <- vertex_mahalanobis_dist(medInnovationsDiffNet, X, S)
Run the code above in your browser using DataLab