Sometimes we will need to modify existing dictionaries so we get the right combination of identities and behaviors.
Note. Better documentation coming shortly.
Merging Two Different Dictionaries
The following code merges two dictionaries:
usfullsurveyor2015
and
mostafaviestimates2022
.
It uses the anti_join()
function from the dplyr package
to keep all the rows from the mostafaviestimates2022
dictionary that don’t have a match in the
usfullsurveyor2015
dictionary.
act <- interact(dictionary = "usfullsurveyor2015")
#> ✔ equations = list(key = "us2010", group = "all")
#> ✔ dictionary = list(dataset = "usfullsurveyor2015", group = "all")
mostafavi <- interact("mostafaviestimates2022")
#> ✔ equations = list(key = "us2010", group = "all")
#> ✔ dictionary = list(dataset = "mostafaviestimates2022", group = "all")
new_rows <- dplyr::anti_join(mostafavi$dictionary, act$dictionary)
#> Joining with `by = join_by(term, component, ratings, n, sd)`
glimpse(new_rows)
#> Rows: 4,496
#> Columns: 5
#> $ term <chr> "27_year_old", "abandon", "abandoned", "abash", "abbot", "ab…
#> $ component <chr> "identity", "behavior", "modifier", "behavior", "identity", …
#> $ ratings <list> <0.49, -1.24, 0.70>, <-3.00, 0.11, -0.27>, <-2.95, -0.68, -…
#> $ n <list> <NA, NA, NA>, <NA, NA, NA>, <NA, NA, NA>, <NA, NA, NA>, <NA…
#> $ sd <list> <0.14, 0.17, 0.17>, <0.26, 0.10, 0.13>, <0.25, 0.15, 0.18>,…
act$dictionary <- dplyr::bind_rows(act$dictionary, new_rows)
#> ✔ added new dictionary
act
#>
#> ── Interact Analysis ───────────────────────────────────────────────────────────
#> ℹ Dictionary: External [!] (group: ?)
#> ℹ Equations: us2010
#> impressionabo (group: all)
Note that a message appeared signaling that the replacement was successful.
You should now be able to use the new extended dictionary.
Adding Modified Identities
Sometimes we will want to add modified identities, which we can get
with the $modify_identity()
method.
To do this we will first have to add a modifier equation with the
$add_equation()
method and then create a grid of modifiers
and identities.
act <- interact(dictionary = "usfullsurveyor2015")
#> ✔ equations = list(key = "us2010", group = "all")
#> ✔ dictionary = list(dataset = "usfullsurveyor2015", group = "all")
act$add_equation(type = "traitid", group = "all")
#> ✔ traitid = list(key = "us2010", group = "all")
modifiers <- act$dictionary |>
dplyr::filter(component == "modifier") |>
## get thirty random modifiers
dplyr::slice_sample(n = 30) |>
dplyr::pull(term)
identities <- act$dictionary |>
dplyr::filter(component == "identity") |>
## get thirty random identities
dplyr::slice_sample(n = 30) |>
dplyr::pull(term)
new_identities <- tidyr::crossing(
M = modifiers,
I = identities
)
glimpse(new_identities)
#> Rows: 900
#> Columns: 2
#> $ M <chr> "big", "big", "big", "big", "big", "big", "big", "big", "big", "big"…
#> $ I <chr> "air_force_officer", "baby", "bohemian", "boyfriend", "capitalist", …
new_rows <- act$modify_identity(new_identities)
glimpse(new_rows)
#> Rows: 900
#> Columns: 3
#> $ term <chr> "big__air_force_officer", "big__baby", "big__bohemian", "big…
#> $ component <chr> "identity", "identity", "identity", "identity", "identity", …
#> $ ratings <list> <0.345404, 2.553300, 1.026200>, <0.5281, -0.3843, 1.1042>, …
Now we just do as we did before.
act$dictionary <- dplyr::bind_rows(act$dictionary, new_rows)
#> ✔ added new dictionary
tail(act$dictionary) ## verify that new identities are present.
#> # A tibble: 6 × 5
#> term component ratings n sd
#> <chr> <chr> <list> <list> <list>
#> 1 vivacious__teenager identity <dbl [3]> <NULL> <NULL>
#> 2 vivacious__textile_worker identity <dbl [3]> <NULL> <NULL>
#> 3 vivacious__toddler identity <dbl [3]> <NULL> <NULL>
#> 4 vivacious__tv_repairman identity <dbl [3]> <NULL> <NULL>
#> 5 vivacious__umpire identity <dbl [3]> <NULL> <NULL>
#> 6 vivacious__virgin identity <dbl [3]> <NULL> <NULL>