Computes covariate distance between connected vertices

vertex_covariate_dist(graph, X, p = 2)

vertex_mahalanobis_dist(graph, X, S)

Arguments

graph

A square matrix of size \(n\) of class dgCMatrix.

X

A numeric matrix of size \(n \times K\). Vertices attributes

p

Numeric scalar. Norm to compute

S

Square matrix of size ncol(x). Usually the var-covar matrix.

Value

A matrix of size \(n\times n\) of class dgCMatrix. Will be symmetric only if graph is symmetric.

Details

Faster than 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 (Minkowski distance). It is implemented as follows (for each pair of vertices):

$$% D_{ij} = \left(\sum_{k=1}^K \left|X_{ik} - X_{jk}\right|^{p} \right)^{1/p}\mbox{ if }graph_{i,j}\neq 0 $$

In the case of mahalanobis distance, for each pair of vertex \((i,j)\), the distance is computed as follows:

$$% D_{ij} = \left( (X_i - X_j)\times S \times (X_i - X_j)' \right)^{1/2}\mbox{ if }graph_{i,j}\neq 0 $$

References

Mahalanobis distance. (2016, September 27). In Wikipedia, The Free Encyclopedia. Retrieved 20:31, September 27, 2016, from https://en.wikipedia.org/w/index.php?title=Mahalanobis_distance&oldid=741488252

See also

mahalanobis in the stats package.

Other statistics: bass, classify_adopters(), cumulative_adopt_count(), dgr(), ego_variance(), exposure(), hazard_rate(), infection(), moran(), struct_equiv(), threshold()

Other dyadic-level comparison functions: matrix_compare(), vertex_covariate_compare()

Author

George G. Vega Yon

Examples

# Distance (aka p norm) -----------------------------------------------------
set.seed(123)
G <- rgraph_ws(20, 4, .1)
X <- matrix(runif(40), ncol=2)

vertex_covariate_dist(G, X)[1:5, 1:5]
#> 5 x 5 sparse Matrix of class "dgCMatrix"
#>                                                       
#> [1,] .         0.1981546 0.8536003 .         .        
#> [2,] 0.1981546 .         0.7586802 0.9200049 .        
#> [3,] 0.8536003 0.7586802 .         0.7894522 0.5022833
#> [4,] .         0.9200049 0.7894522 .         0.8215560
#> [5,] .         .         0.5022833 0.8215560 .        

# 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)