Comparisons at dyadic level

vertex_covariate_compare(graph, X, funname)

Arguments

graph

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

X

A numeric vector of length \(n\).

funname

Character scalar. Comparison to make (see details).

Value

A matrix dgCMatrix of size \(n\times n\) with values in the form of \(funname(x_i,x_j)\).

Details

This auxiliary function takes advantage of the sparseness of graph and applies a function in the form of \(funname(x_i,x_j)\) only to \((i,j)\) that have no empty entry. In other words, applies a compares elements of X only between vertices that have a link; making nlinks(graph) comparisons instead of looping through \(n\times n\), which is much faster.

funname can take any of the following values: "distance", "^2" or "quaddistance", ">" or "greater", "<" or "smaller", ">=" or "greaterequal", "<=" or "smallerequal", "==" or "equal".

See also

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

Examples


# Basic example ------------------------------------------------------------
set.seed(1313)
G <- rgraph_ws(10, 4, .2)
x <- rnorm(10)

vertex_covariate_compare(G, x, "distance")
#> 10 x 10 sparse Matrix of class "dgCMatrix"
#>                                                                           
#>  [1,] .         1.0641842 .         .         1.160060 .         .        
#>  [2,] 1.0641842 .         0.4867249 0.2437569 .        .         .        
#>  [3,] 0.5774593 0.4867249 .         0.2429680 1.737519 .         .        
#>  [4,] .         0.2437569 0.2429680 .         1.980487 0.3777802 .        
#>  [5,] .         .         1.7375191 1.9804871 .        2.3582672 2.7931946
#>  [6,] .         .         .         0.3777802 2.358267 .         0.4349274
#>  [7,] .         .         .         .         2.793195 0.4349274 .        
#>  [8,] .         .         .         0.5029751 1.477512 0.8807552 1.3156826
#>  [9,] 1.3807050 .         0.8032456 .         .        .         0.2524298
#> [10,] 1.2314124 0.1672282 .         0.4109851 .        .         .        
#>                                    
#>  [1,] .         1.3807050 1.2314124
#>  [2,] .         .         0.1672282
#>  [3,] .         .         .        
#>  [4,] .         .         .        
#>  [5,] .         .         .        
#>  [6,] 0.8807552 .         .        
#>  [7,] 1.3156826 0.2524298 .        
#>  [8,] .         .         .        
#>  [9,] .         .         0.1492926
#> [10,] 0.9139601 .         .        
vertex_covariate_compare(G, x, "^2")
#> 10 x 10 sparse Matrix of class "dgCMatrix"
#>                                                                               
#>  [1,] .         1.13248802 .          .          1.345739 .         .         
#>  [2,] 1.1324880 .          0.23690109 0.05941743 .        .         .         
#>  [3,] 0.3334593 0.23690109 .          0.05903343 3.018973 .         .         
#>  [4,] .         0.05941743 0.05903343 .          3.922329 0.1427178 .         
#>  [5,] .         .          3.01897268 3.92232904 .        5.5614243 7.80193599
#>  [6,] .         .          .          0.14271785 5.561424 .         0.18916181
#>  [7,] .         .          .          .          7.801936 0.1891618 .         
#>  [8,] .         .          .          0.25298393 2.183042 0.7757298 1.73102068
#>  [9,] 1.9063463 .          0.64520356 .          .        .         0.06372082
#> [10,] 1.5163764 0.02796526 .          0.16890871 .        .         .         
#>                                      
#>  [1,] .         1.90634627 1.51637640
#>  [2,] .         .          0.02796526
#>  [3,] .         .          .         
#>  [4,] .         .          .         
#>  [5,] .         .          .         
#>  [6,] 0.7757298 .          .         
#>  [7,] 1.7310207 0.06372082 .         
#>  [8,] .         .          .         
#>  [9,] .         .          0.02228829
#> [10,] 0.8353231 .          .         
vertex_covariate_compare(G, x, ">=")
#> 10 x 10 sparse Matrix of class "dgCMatrix"
#>                          
#>  [1,] . 1 . . . . . . 1 1
#>  [2,] . . . . . . . . . 1
#>  [3,] . 1 . 1 . . . . . .
#>  [4,] . 1 . . . 1 . . . .
#>  [5,] . . 1 1 . 1 1 . . .
#>  [6,] . . . . . . 1 . . .
#>  [7,] . . . . . . . . . .
#>  [8,] . . . 1 . 1 1 . . .
#>  [9,] . . . . . . 1 . . .
#> [10,] . . . . . . . . . .
vertex_covariate_compare(G, x, "<=")
#> 10 x 10 sparse Matrix of class "dgCMatrix"
#>                          
#>  [1,] . . . . 1 . . . . .
#>  [2,] 1 . 1 1 . . . . . .
#>  [3,] 1 . . . 1 . . . . .
#>  [4,] . . 1 . 1 . . . . .
#>  [5,] . . . . . . . . . .
#>  [6,] . . . 1 1 . . 1 . .
#>  [7,] . . . . 1 1 . 1 1 .
#>  [8,] . . . . 1 . . . . .
#>  [9,] 1 . 1 . . . . . . 1
#> [10,] 1 1 . 1 . . . 1 . .