ego_netwrite: Ego Network Cleaning and Measure Calculation ('ego_netwrite')

View source: R/netwrite_ego.R

ego_netwriteR Documentation

Ego Network Cleaning and Measure Calculation (ego_netwrite)

Description

The ego_netwrite function reads in data pertaining to ego networks and processes them into a set of standardized outputs, including measures commonly calculated for ego networks.

Usage

ego_netwrite(
  egos,
  ego_id,
  alters = NULL,
  alter_id = NULL,
  alter_ego = NULL,
  alter_types = NULL,
  max_alters = Inf,
  alter_alter = NULL,
  aa_ego = NULL,
  i_elements = NULL,
  j_elements = NULL,
  directed = FALSE,
  aa_type = NULL,
  missing_code = 99999,
  na.rm = FALSE,
  egor = FALSE,
  egor_design = NULL
)

Arguments

egos

A data frame containing measures of ego attributes.

ego_id

A vector of unique identifiers corresponding to each ego, or a single character value indicating the name of the column in egos containing ego identifiers.

alters

A data frame containing measures of alter attributes.

alter_id

A vector of identifiers indicating which alter is associated with a given row in alters, or a single character value indicating the name of the column in alters containing alter identifiers.

alter_ego

A vector of identifiers indicating which ego is associated with a given alter, or a single character value indicating the name of the column in alters containing ego identifiers.

alter_types

A character vector indicating the columns in alters that indicate whether a given alter has certain types of relations with ego. These columns should all contain binary measures indicating whether alter has a particular type of relation with ego.

max_alters

A numeric value indicating the maximum number of alters an ego in the dataset could have nominated

alter_alter

A data frame containing an edgelist indicating ties between alters in each ego's network. This edgelist is optional, but ego_netwrite will not provide certain measures without it.

aa_ego

A vector of identifiers indicating which ego is associated with a given tie between alters, or a single character indicating the name of the column in alter_alter containing ego identifiers.

i_elements

A vector of identifiers indicating which alter is on one end of an alter-alter tie, or a single character indicating the name of the column in alter_alter containing these identifiers.

j_elements

A vector of identifiers indicating which alter is on the other end of an alter-alter tie, or a single character indicating the name of the column in alter_alter containing these identifiers.

directed

A logical value indicating whether network ties are directed or undirected.

aa_type

A numeric or character vector indicating the types of relationships represented in the alter edgelist, or a single character value indicating the name of the column in alter_alter containing relationship type. If alter_type is specified, ego_netwrite will treat the data as a set of multi-relational networks and produce additional outputs reflecting the different types of ties occurring in each ego network.

missing_code

A numeric value indicating "missing" values in the alter-alter edgelist.

na.rm

A logical value indicating whether NA values should be excluded when calculating continuous measures.

egor

A logical value indicating whether output should include an egor object, which is often useful for visualizaton and for simulation larger networks from egocentric data.

egor_design

If creating an egor object, a list of arguments to srvyr::as_survey_design specifying the sampling design for egos. This argument corresponds to ego_design in egor::egor.

Value

ego_netwrite returns a list containing several output objects. Users may find it easier to access and work with outputs by applying list2env to this list, which will separate outputs and store them in the R Global Environment. Note, however, that this risks overwriting existing objects in the Global Environment should those objects share names with objects in netwrite's output. Outputs include a data frame containing measures of ego attributes, another data frame containing measures of alter attributes and network position, a third containing the alter-alter edgelist (when applicable), a fourth containing summary measures for each individual ego network, and a fifth providing summary measures for the overall dataset. Additionally, ego_netwrite returns a list of igraph objects constructed for each individual ego network, as well as an egor object for the overall dataset if desired.

Examples


# Simple Processing, Ignoring Ego-Alter or Alter-Alter Relation Types
ngq_nw <- ego_netwrite(egos = ngq_egos,
                       ego_id = ngq_egos$ego_id,

                       alters = ngq_alters,
                       alter_id = ngq_alters$alter_id,
                       alter_ego = ngq_alters$ego_id,

                       max_alters = 10,
                       alter_alter = ngq_aa,
                       aa_ego = ngq_aa$ego_id,
                       i_elements = ngq_aa$alter1,
                       j_elements = ngq_aa$alter2,
                       directed = FALSE)


# View summaries of individual ego networks
head(ngq_nw$summaries)

# View summary of overall dataset
head(ngq_nw$overall_summary)

# View sociogram of fourth ego network
plot(ngq_nw$igraph_objects[[4]]$igraph_ego)


# For advanced applications involving multiple relationship types
# and `egor` object creation, please consult the `ego_netwrite` vignette
vignette("ego_netwrite", package = "ideanet")

ideanet documentation built on June 8, 2025, 1:07 p.m.