as_tibble.egor: Extract ego, alter, and alter-alter tables from an 'egor'...

View source: R/conversions.R

as_tibble.egorR Documentation

Extract ego, alter, and alter-alter tables from an egor object.

Description

Provided an egor object, these functions create a "global" tibble or srvyr's tbl_svy object containing egos, alter attributes, or alter-alter relations. The resulting tables are useful for advanced analysis procedures, e.g. multi-level regressions.

as_tibble() method for egor extracts the currently active component (ego, alter, or aaties) table, optionally joining it with the others, dropping any survey design information.

as_survey() method for egor instead returns a srvyr tbl_svy survey, taking into account any replication due to multiple alters or alter-alter ties incident on each ego. If no design is specified for the egos, then the default design (simple random sample with replacement) is assumed as the starting point.

as_egos_df(), as_alters_df(), as_aaties_df(), as_egos_survey(), as_alters_survey(), and as_aaties_survey() are convenience functions for the as_tibble() and as_survey() methods, activating the corresponding component of the egor object.

Usage

## S3 method for class 'egor'
as_tibble(x, ..., include.ego.vars = FALSE, include.alter.vars = FALSE)

## S3 method for class 'egor'
as_survey(.data, ..., include.ego.vars = FALSE, include.alter.vars = FALSE)

as_egos_df(object)

as_alters_df(object, include.ego.vars = FALSE)

as_aaties_df(object, include.ego.vars = FALSE, include.alter.vars = FALSE)

as_egos_survey(object, include.ego.vars = FALSE)

as_alters_survey(object, include.ego.vars = FALSE)

as_aaties_survey(object, include.ego.vars = FALSE, include.alter.vars = FALSE)

Arguments

x, object, .data

An egor object.

...

Additional arguments, currently unused.

include.ego.vars

Logical, specifying if ego variables should be included in the result.

include.alter.vars

Logical, specifying if alter variables should be included in the result.

Value

A tibble for the as_tibble and ⁠*_df⁠ functions and a tbl_svy for as_survey and the ⁠*_survey⁠ functions.

Examples

# Load example data
data(egor32)

as_tibble(egor32) # Ego table.

egor32 %>%
 activate("alter") %>%
 as_tibble(include.ego.vars=TRUE) # Alter table, but also with ego variables.

library(srvyr)
as_survey(egor32) # Ego table with survey design.

# Despite alter table being active, obtain the ego table.
(egor32 <- activate(egor32, "alter"))
as_egos_df(egor32)

# Create global alter table
as_alters_df(egor32)

# Create global alter-alter relations table
as_aaties_df(egor32)

# ... adding alter variables
as_aaties_df(egor32, include.alter.vars = TRUE)
as_egos_survey(egor32)
as_alters_survey(egor32) # Notice the resulting cluster design.

egor documentation built on May 29, 2024, 12:10 p.m.