egor
object.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.
# 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)
x, object, .data | An |
---|---|
... | 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. |
A tibble
for the as_tibble
and *_df
functions and a tbl_svy
for as_survey
and the *_survey
functions.
#> # A tibble: 32 x 6 #> .egoID sex age age.years country income #> <fct> <fct> <fct> <int> <fct> <dbl> #> 1 1 w 36 - 45 45 USA 36135 #> 2 2 m 36 - 45 37 Germany 35040 #> 3 3 m 26 - 35 28 Australia 63875 #> 4 4 w 0 - 17 2 USA 31755 #> 5 5 m 56 - 65 56 Germany 14600 #> 6 6 m 26 - 35 31 Poland 21900 #> 7 7 w 36 - 45 43 Poland 15695 #> 8 8 m 0 - 17 1 Australia 37960 #> 9 9 w 66 - 100 73 Poland 31390 #> 10 10 w 66 - 100 74 Germany 43435 #> # … with 22 more rowsegor32 %>% activate("alter") %>% as_tibble(include.ego.vars=TRUE) # Alter table, but also with ego variables.#> # A tibble: 478 x 12 #> .altID .egoID sex age age.years country income sex_ego age_ego #> <int> <fct> <fct> <fct> <int> <fct> <dbl> <fct> <fct> #> 1 1 1 w 66 -… 75 Austra… 42340 w 36 - 45 #> 2 2 1 m 18 -… 17 Germany 730 w 36 - 45 #> 3 3 1 w 66 -… 91 Austra… 23360 w 36 - 45 #> 4 4 1 m 0 - … 10 USA 27010 w 36 - 45 #> 5 5 1 m 66 -… 67 Poland 33215 w 36 - 45 #> 6 6 1 m 0 - … 10 USA 31755 w 36 - 45 #> 7 7 1 m 0 - … 12 Austra… 11680 w 36 - 45 #> 8 8 1 m 66 -… 97 USA 67890 w 36 - 45 #> 9 1 2 w 66 -… 75 Austra… 42340 m 36 - 45 #> 10 2 2 m 18 -… 17 Germany 730 m 36 - 45 #> # … with 468 more rows, and 3 more variables: age.years_ego <int>, #> # country_ego <fct>, income_ego <dbl>#> Warning: package ‘srvyr’ was built under R version 4.0.3#> #>#>#> #>#> Independent Sampling design (with replacement) #> Called via srvyr #> Sampling variables: #> - ids: `1` #> Data variables: .egoID (fct), sex (fct), age (fct), age.years (int), country #> (fct), income (dbl)#> # EGO data with survey design: 32 x 6 #> .egoID sex age age.years country income #> <fct> <fct> <fct> <int> <fct> <dbl> #> 1 1 w 36 - 45 45 USA 36135 #> 2 2 m 36 - 45 37 Germany 35040 #> 3 3 m 26 - 35 28 Australia 63875 #> # ALTER data (active): 478 x 7 #> .altID .egoID sex age age.years country income #> <int> <fct> <fct> <fct> <int> <fct> <dbl> #> 1 1 1 w 66 - 100 75 Australia 42340 #> 2 2 1 m 18 - 25 17 Germany 730 #> 3 3 1 w 66 - 100 91 Australia 23360 #> 4 4 1 m 0 - 17 10 USA 27010 #> 5 5 1 m 66 - 100 67 Poland 33215 #> # AATIE data: 1,858 x 4 #> .egoID .srcID .tgtID weight #> <fct> <int> <int> <dbl> #> 1 32 13 18 0.333 #> 2 18 11 22 0.667 #> 3 28 5 19 0.667as_egos_df(egor32)#> # A tibble: 32 x 6 #> .egoID sex age age.years country income #> <fct> <fct> <fct> <int> <fct> <dbl> #> 1 1 w 36 - 45 45 USA 36135 #> 2 2 m 36 - 45 37 Germany 35040 #> 3 3 m 26 - 35 28 Australia 63875 #> 4 4 w 0 - 17 2 USA 31755 #> 5 5 m 56 - 65 56 Germany 14600 #> 6 6 m 26 - 35 31 Poland 21900 #> 7 7 w 36 - 45 43 Poland 15695 #> 8 8 m 0 - 17 1 Australia 37960 #> 9 9 w 66 - 100 73 Poland 31390 #> 10 10 w 66 - 100 74 Germany 43435 #> # … with 22 more rows# Create global alter table as_alters_df(egor32)#> # A tibble: 478 x 7 #> .altID .egoID sex age age.years country income #> <int> <fct> <fct> <fct> <int> <fct> <dbl> #> 1 1 1 w 66 - 100 75 Australia 42340 #> 2 2 1 m 18 - 25 17 Germany 730 #> 3 3 1 w 66 - 100 91 Australia 23360 #> 4 4 1 m 0 - 17 10 USA 27010 #> 5 5 1 m 66 - 100 67 Poland 33215 #> 6 6 1 m 0 - 17 10 USA 31755 #> 7 7 1 m 0 - 17 12 Australia 11680 #> 8 8 1 m 66 - 100 97 USA 67890 #> 9 1 2 w 66 - 100 75 Australia 42340 #> 10 2 2 m 18 - 25 17 Germany 730 #> # … with 468 more rows# Create global alter-alter relations table as_aaties_df(egor32)#> # A tibble: 1,858 x 4 #> .egoID .srcID .tgtID weight #> <fct> <int> <int> <dbl> #> 1 32 13 18 0.333 #> 2 18 11 22 0.667 #> 3 28 5 19 0.667 #> 4 19 5 6 1 #> 5 32 2 19 0.667 #> 6 22 3 15 0.667 #> 7 14 3 7 0.333 #> 8 15 5 8 0.333 #> 9 11 10 12 0.333 #> 10 13 12 17 1 #> # … with 1,848 more rows# ... adding alter variables as_aaties_df(egor32, include.alter.vars = TRUE)#> # A tibble: 1,858 x 14 #> .egoID .srcID .tgtID weight sex_src age_src age.years_src country_src #> <fct> <int> <int> <dbl> <fct> <fct> <int> <fct> #> 1 32 13 18 0.333 m 66 - 1… 67 Poland #> 2 18 11 22 0.667 w 66 - 1… 78 USA #> 3 28 5 19 0.667 m 66 - 1… 67 Poland #> 4 19 5 6 1 m 66 - 1… 67 Poland #> 5 32 2 19 0.667 m 18 - 25 17 Germany #> 6 22 3 15 0.667 w 66 - 1… 91 Australia #> 7 14 3 7 0.333 w 66 - 1… 91 Australia #> 8 15 5 8 0.333 m 66 - 1… 67 Poland #> 9 11 10 12 0.333 w 66 - 1… 87 Germany #> 10 13 12 17 1 w 26 - 35 31 USA #> # … with 1,848 more rows, and 6 more variables: income_src <dbl>, #> # sex_tgt <fct>, age_tgt <fct>, age.years_tgt <int>, country_tgt <fct>, #> # income_tgt <dbl>as_egos_survey(egor32)#> Independent Sampling design (with replacement) #> Called via srvyr #> Sampling variables: #> - ids: `1` #> Data variables: .egoID (fct), sex (fct), age (fct), age.years (int), country #> (fct), income (dbl)as_alters_survey(egor32) # Notice the resulting cluster design.#> 1 - level Cluster Sampling design (with replacement) #> With (32) clusters. #> Called via srvyr #> Sampling variables: #> - ids: `1` #> Data variables: .altID (int), .egoID (fct), sex (fct), age (fct), age.years #> (int), country (fct), income (dbl)