ego_netify extracts an ego network from a
netify object. an ego network consists of a focal node (ego) and its immediate
neighbors (alters). for weighted networks, users can define neighborhoods using
edge weight thresholds. the function returns a netify object representing the
ego network.
Arguments
- netlet
a netify object (class "netify") from which to extract the ego network.
- ego
character string specifying the name of the ego for whom to create the ego network. must match an actor name in the netify object.
- threshold
numeric value or vector specifying the threshold for including alters in the ego network based on edge weights. for longitudinal networks, can be a vector with length equal to the number of time periods to apply different thresholds over time. if NULL (default), uses 0 for unweighted networks and the mean edge weight for weighted networks.
- ngbd_direction
character string specifying which neighbors to include for directed networks. options are:
"out": include alters that ego has outgoing ties to"in": include alters that ego has incoming ties from"any": include alters with any tie to/from ego (default)
- include_ego
logical. if TRUE (default), the ego node is included in the ego network. if FALSE, only alters are included.
Value
a netify object representing the ego network. for longitudinal networks, returns a list of netify objects with one ego network per time period.
each returned netify object includes additional attributes:
ego_netify: TRUE (indicator that this is an ego network)ego_id: identifier of the egothreshold: threshold value(s) usedngbd_direction: direction specification usedinclude_ego: whether ego was included
Details
the function extracts an ego network by identifying all nodes connected to the specified ego based on the given criteria:
neighborhood definition:
for unweighted networks: all nodes with edges to/from ego (threshold = 0)
for weighted networks: all nodes with edge weights exceeding the threshold
direction matters only for directed networks (controlled by ngbd_direction)
threshold behavior:
if not specified, defaults to 0 for unweighted networks
if not specified for weighted networks, uses the mean edge weight
for longitudinal networks, can vary by time period if a vector is provided
edges with weights > threshold are included (not >=)
output structure:
the function preserves all attributes from the original netify object, including nodal and dyadic variables, but subsets them to include only ego and its neighbors. for longitudinal networks, ego networks may vary in composition across time periods as relationships change.
limitations:
currently does not support multilayer networks
currently does not support bipartite networks
Note
to create ego networks for multiple egos, use lapply or a loop to call
this function for each ego separately.
Examples
# cross-sectional ego network from the bundled classroom data
data(classroom_edges)
data(classroom_nodes)
net <- netify(
classroom_edges,
actor1 = "from", actor2 = "to",
symmetric = TRUE,
nodal_data = classroom_nodes
)
s07_ego <- ego_netify(net, ego = "s07")
print(s07_ego)
#> ✔ Neighborhood network created for ego(s) (s07).
#> • Type: Ego Network
#> • Ego: s07
#> • Direction: Any ties (in or out)
#> • Ego included: Yes
#> • Unipartite
#> • Symmetric
#> • Binary Weights
#> • Cross-Sectional
#> • # Unique Egos: 1 | # Unique Alters: 5
#> Neighborhood Network Summary Statistics:
#> dens miss trans
#> s07 0.333 0 0
#> • Nodal Features: gender, grade, gpa
#> • Dyad Features: None
# \donttest{
# longitudinal ego network with a weighted, directed netlet
data(icews)
netlet <- netify(
icews,
actor1 = "i", actor2 = "j", time = "year",
weight = "verbCoop"
)
pakistan_ego <- ego_netify(netlet, ego = "Pakistan")
summary(pakistan_ego)
#> net layer num_actors density num_edges prop_edges_missing
#> 1 2002 Pakistan 33 0.8049242 425 0
#> 2 2003 Pakistan 28 0.9312169 352 0
#> 3 2004 Pakistan 49 0.7891156 928 0
#> 4 2005 Pakistan 44 0.8985201 850 0
#> 5 2006 Pakistan 40 0.8846154 690 0
#> 6 2007 Pakistan 39 0.9082321 673 0
#> 7 2008 Pakistan 29 0.9334975 379 0
#> 8 2009 Pakistan 28 0.9656085 365 0
#> 9 2010 Pakistan 37 0.9249249 616 0
#> 10 2011 Pakistan 33 0.9053030 478 0
#> 11 2012 Pakistan 40 0.9012821 703 0
#> 12 2013 Pakistan 27 0.9686610 340 0
#> 13 2014 Pakistan 24 0.9420290 260 0
#> mean_edge_weight sd_edge_weight median_edge_weight min_edge_weight
#> 1 227.2941 595.2732 35 1
#> 2 306.7926 740.5199 51 1
#> 3 128.4300 412.2462 22 1
#> 4 154.1388 499.4925 25 1
#> 5 169.6478 561.8834 25 1
#> 6 201.4740 578.2115 35 1
#> 7 245.0343 614.2971 40 1
#> 8 263.0849 732.7934 42 1
#> 9 171.2110 500.5081 29 1
#> 10 183.7594 486.9519 26 1
#> 11 133.3371 379.9686 24 1
#> 12 253.6588 631.8493 40 1
#> 13 339.2654 701.8777 65 1
#> max_edge_weight competition sd_of_actor_means transitivity
#> 1 5760 0.08270328 244.3143 0.8513921
#> 2 5937 0.08521930 342.5283 0.9417385
#> 3 5141 0.06014910 142.8899 0.8390159
#> 4 6561 0.06605279 193.4328 0.9174501
#> 5 7579 0.07536095 215.7135 0.9116163
#> 6 6698 0.06860271 239.9547 0.9247124
#> 7 4590 0.08288226 275.7906 0.9418932
#> 8 6863 0.09577883 335.4921 0.9683958
#> 9 4937 0.07634283 216.8612 0.9366962
#> 10 5581 0.07512401 205.4581 0.9194264
#> 11 4225 0.06522529 154.3793 0.9187122
#> 12 6049 0.08525561 285.6972 0.9706418
#> 13 4374 0.08494759 332.7357 0.9510980
# }