Extract ego, alter, and alter-alter tables from an egor
object.
Source: R/conversions.R
as_tibble.egor.Rd
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 egor
as_tibble(x, ..., include.ego.vars = FALSE, include.alter.vars = FALSE)
# S3 method for 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.
#> # A tibble: 32 × 6
#> .egoID sex age age.years country income
#> <dbl> <fct> <fct> <int> <chr> <dbl>
#> 1 1 m 56 - 65 63 Australia 29930
#> 2 2 m 26 - 35 33 Germany 17885
#> 3 3 m 66 - 100 74 Germany 20805
#> 4 4 w 18 - 25 21 Poland 29565
#> 5 5 m 0 - 17 9 Germany 15330
#> 6 6 m 0 - 17 6 Australia 23360
#> 7 7 m 66 - 100 84 Australia 19345
#> 8 8 w 66 - 100 100 Poland 35040
#> 9 9 m 36 - 45 38 USA 64605
#> 10 10 m 0 - 17 14 Australia 49275
#> # ℹ 22 more rows
egor32 %>%
activate("alter") %>%
as_tibble(include.ego.vars=TRUE) # Alter table, but also with ego variables.
#> # A tibble: 384 × 12
#> .altID .egoID sex age age.years country income sex_ego age_ego
#> <int> <dbl> <fct> <fct> <int> <chr> <dbl> <fct> <fct>
#> 1 1 1 m 46 - 55 48 USA 45625 m 56 - 65
#> 2 2 1 m 0 - 17 5 Germany 52925 m 56 - 65
#> 3 3 1 w 26 - 35 35 Australia 60225 m 56 - 65
#> 4 4 1 w 0 - 17 3 Poland 25550 m 56 - 65
#> 5 5 1 m 66 - 100 97 Australia 45260 m 56 - 65
#> 6 6 1 w 26 - 35 29 Germany 8395 m 56 - 65
#> 7 7 1 m 26 - 35 32 USA 54020 m 56 - 65
#> 8 8 1 w 46 - 55 49 USA 60955 m 56 - 65
#> 9 9 1 m 56 - 65 60 Germany 39055 m 56 - 65
#> 10 10 1 w 46 - 55 52 Australia 7300 m 56 - 65
#> # ℹ 374 more rows
#> # ℹ 3 more variables: age.years_ego <int>, country_ego <chr>, income_ego <dbl>
library(srvyr)
#>
#> Attaching package: ‘srvyr’
#> The following object is masked from ‘package:stats’:
#>
#> filter
as_survey(egor32) # Ego table with survey design.
#> Independent Sampling design (with replacement)
#> Called via srvyr
#> Data variables: .egoID (dbl), sex (fct), age (fct), age.years (int), country
#> (chr), income (dbl)
# Despite alter table being active, obtain the ego table.
(egor32 <- activate(egor32, "alter"))
#> # EGO data with survey design: 32 × 6
#> .egoID sex age age.years country income
#> * <dbl> <fct> <fct> <int> <chr> <dbl>
#> 1 1 m 56 - 65 63 Australia 29930
#> 2 2 m 26 - 35 33 Germany 17885
#> 3 3 m 66 - 100 74 Germany 20805
#> # ℹ 29 more rows
#> # ALTER data (active): 384 × 7
#> .altID .egoID sex age age.years country income
#> * <int> <dbl> <fct> <fct> <int> <chr> <dbl>
#> 1 1 1 m 46 - 55 48 USA 45625
#> 2 2 1 m 0 - 17 5 Germany 52925
#> 3 3 1 w 26 - 35 35 Australia 60225
#> 4 4 1 w 0 - 17 3 Poland 25550
#> 5 5 1 m 66 - 100 97 Australia 45260
#> # ℹ 379 more rows
#> # AATIE data: 1,056 × 4
#> .egoID .srcID .tgtID weight
#> * <int> <int> <int> <dbl>
#> 1 20 1 2 0.667
#> 2 25 6 10 0.667
#> 3 9 6 8 0.667
#> # ℹ 1,053 more rows
as_egos_df(egor32)
#> # A tibble: 32 × 6
#> .egoID sex age age.years country income
#> <dbl> <fct> <fct> <int> <chr> <dbl>
#> 1 1 m 56 - 65 63 Australia 29930
#> 2 2 m 26 - 35 33 Germany 17885
#> 3 3 m 66 - 100 74 Germany 20805
#> 4 4 w 18 - 25 21 Poland 29565
#> 5 5 m 0 - 17 9 Germany 15330
#> 6 6 m 0 - 17 6 Australia 23360
#> 7 7 m 66 - 100 84 Australia 19345
#> 8 8 w 66 - 100 100 Poland 35040
#> 9 9 m 36 - 45 38 USA 64605
#> 10 10 m 0 - 17 14 Australia 49275
#> # ℹ 22 more rows
# Create global alter table
as_alters_df(egor32)
#> # A tibble: 384 × 7
#> .altID .egoID sex age age.years country income
#> <int> <dbl> <fct> <fct> <int> <chr> <dbl>
#> 1 1 1 m 46 - 55 48 USA 45625
#> 2 2 1 m 0 - 17 5 Germany 52925
#> 3 3 1 w 26 - 35 35 Australia 60225
#> 4 4 1 w 0 - 17 3 Poland 25550
#> 5 5 1 m 66 - 100 97 Australia 45260
#> 6 6 1 w 26 - 35 29 Germany 8395
#> 7 7 1 m 26 - 35 32 USA 54020
#> 8 8 1 w 46 - 55 49 USA 60955
#> 9 9 1 m 56 - 65 60 Germany 39055
#> 10 10 1 w 46 - 55 52 Australia 7300
#> # ℹ 374 more rows
# Create global alter-alter relations table
as_aaties_df(egor32)
#> # A tibble: 1,056 × 4
#> .egoID .srcID .tgtID weight
#> <int> <int> <int> <dbl>
#> 1 20 1 2 0.667
#> 2 25 6 10 0.667
#> 3 9 6 8 0.667
#> 4 31 2 10 0.667
#> 5 24 1 12 0.333
#> 6 11 9 11 0.333
#> 7 7 3 6 0.667
#> 8 8 6 7 0.667
#> 9 32 3 7 0.667
#> 10 26 2 10 1
#> # ℹ 1,046 more rows
# ... adding alter variables
as_aaties_df(egor32, include.alter.vars = TRUE)
#> # A tibble: 1,056 × 14
#> .egoID .srcID .tgtID weight sex_src age_src age.years_src country_src
#> <dbl> <int> <int> <dbl> <fct> <fct> <int> <chr>
#> 1 20 1 2 0.667 m 66 - 100 97 Australia
#> 2 25 6 10 0.667 w 26 - 35 29 Germany
#> 3 9 6 8 0.667 w 26 - 35 29 Germany
#> 4 31 2 10 0.667 w 46 - 55 52 Australia
#> 5 24 1 12 0.333 m 18 - 25 22 USA
#> 6 11 9 11 0.333 m 46 - 55 48 USA
#> 7 7 3 6 0.667 w 46 - 55 54 Poland
#> 8 8 6 7 0.667 w 66 - 100 83 Germany
#> 9 32 3 7 0.667 w 46 - 55 55 Germany
#> 10 26 2 10 1 w 66 - 100 89 Poland
#> # ℹ 1,046 more rows
#> # ℹ 6 more variables: income_src <dbl>, sex_tgt <fct>, age_tgt <fct>,
#> # age.years_tgt <int>, country_tgt <chr>, income_tgt <dbl>
as_egos_survey(egor32)
#> Independent Sampling design (with replacement)
#> Called via srvyr
#> Data variables: .egoID (dbl), sex (fct), age (fct), age.years (int), country
#> (chr), income (dbl)
as_alters_survey(egor32) # Notice the resulting cluster design.
#> 1 - level Cluster Sampling design (with replacement)
#> With (32) clusters.
#> Called via srvyr
#> Data variables: .altID (int), .egoID (dbl), sex (fct), age (fct), age.years
#> (int), country (chr), income (dbl)