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 netlet
data(icews)
netlet <- netify(
icews,
actor1 = "i", actor2 = "j", time = "year",
sum_dyads = TRUE,
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 31 0.8580645 399 0
#> 2 2003 Pakistan 29 0.9211823 374 0
#> 3 2004 Pakistan 49 0.7891156 928 0
#> 4 2005 Pakistan 45 0.8919192 883 0
#> 5 2006 Pakistan 40 0.8705128 679 0
#> 6 2007 Pakistan 39 0.9163293 679 0
#> 7 2008 Pakistan 32 0.9475806 470 0
#> 8 2009 Pakistan 28 0.9656085 365 0
#> 9 2010 Pakistan 33 0.9469697 500 0
#> 10 2011 Pakistan 30 0.9218391 401 0
#> 11 2012 Pakistan 37 0.9114114 607 0
#> 12 2013 Pakistan 29 0.9408867 382 0
#> 13 2014 Pakistan 26 0.9323077 303 0
#> mean_edge_weight sd_edge_weight median_edge_weight min_edge_weight
#> 1 447.7093 1130.1598 97.0 1
#> 2 577.3797 1389.1304 100.5 1
#> 3 252.4741 802.3923 45.0 1
#> 4 292.1699 933.7845 48.0 1
#> 5 334.5773 1064.4979 54.0 1
#> 6 397.9087 1116.5289 74.0 1
#> 7 436.7043 1143.5438 71.5 1
#> 8 517.4356 1413.9071 85.0 1
#> 9 367.4720 979.2444 67.0 1
#> 10 386.4314 987.9707 73.0 1
#> 11 284.0725 786.2262 49.0 1
#> 12 479.3089 1221.8537 78.0 1
#> 13 588.6865 1284.1628 102.0 1
#> max_edge_weight competition sd_of_actor_means transitivity
#> 1 11763 0.08302184 489.8849 0.8868895
#> 2 9768 0.08263100 639.6115 0.9336033
#> 3 9804 0.05972350 279.3920 0.8390159
#> 4 11759 0.06377164 360.3542 0.9118179
#> 5 14169 0.07270890 407.4732 0.9020027
#> 6 13823 0.06602829 463.5857 0.9310701
#> 7 9498 0.07684508 507.8457 0.9540573
#> 8 13592 0.09416877 650.9423 0.9683958
#> 9 9178 0.07743816 440.7290 0.9527853
#> 10 11084 0.07880415 423.1713 0.9321284
#> 11 8078 0.06874129 326.0892 0.9271750
#> 12 12369 0.08150719 535.9615 0.9485023
#> 13 8541 0.08163981 593.0336 0.9430204
# }