The function calculates homophily matrices. If you supply a categorical variable (factor, character), the function returns attribute matches for dyads from the same group. If you supply a continuous variable (numeric, integers), the function returns absolute difference effects for each dyad in the graph.

homophily_stat(
  variable = variable,
  type = "categorical",
  nodes = nodes,
  these.categories.only = NULL,
  zero_values = NULL
)

Arguments

variable

A attribute variable. Can be categorical (attribute matches) or continuous (absolute difference effects).

type

set to categorical. Can be set to absdiff instead. If set to categorical, the homophily statistic calculates matches between dyads from the same group (analogous to dummy variables measuring attribute match between two nodes (=10) and attribute mismatch (=1)). If set to absdiff it calculates the difference in values from variable for each dyad in the graph.

nodes

optional character/factor vector. If an edgelist is provided, you have to provide a list of unique identifiers of your nodes in the graph. This is because in the edgelist, isolates are usually not recorded. If you do not specify isolates in your nodes object, they are excluded from the analysis (falsifies data).

these.categories.only

optional vector specifying the categories to be used, if only a subset of factor(variable) is needed.

zero_values

optional numeric value. Use this to substitute zero-values in your homophily change statistic matrix. Zero values in the predictors are recognized in the gHypEG regression as structural zeroes. To ensure this does not happen, please recode your zero-values in all your predictors, ideally using a dummy variable fitting an optimal value for the zeroes. Only useful with absdiff type.

Value

Homophily change statistic matrix.

Author

LB, GC

Examples

homop_stat <- homophily_stat(variable = vertexlabels, nodes = rownames(adj_karate))
nrm(w=list('homophily'= homop_stat), adj_karate, directed = FALSE, selfloops = FALSE)
#> Call:
#> nrm.default(w = list(homophily = homop_stat), adj = adj_karate, 
#>     directed = FALSE, selfloops = FALSE)
#> 
#> Coefficients:
#>           Estimate Std.Err t value    Pr(>t)    
#> homophily  2.35164 0.22414  10.492 < 2.2e-16 ***
#> ---
#> Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#> 
#> R2:
#>  McFadden R2 Cox Snell R2 
#>    0.1437786    0.5699989