library(inteRact)
#> Loading required package: actdata
library(actdata)
library(tidyverse)
#> ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.1 ──
#>  ggplot2 3.4.0       purrr   0.3.5 
#>  tibble  3.1.8       dplyr   1.0.10
#>  tidyr   1.2.1       stringr 1.5.0 
#>  readr   2.1.3       forcats 0.5.2
#> ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
#>  dplyr::filter() masks stats::filter()
#>  dplyr::lag()    masks stats::lag()
library(here)
#> here() starts at /Users/emilymaloney/Dropbox/Grad_School/Quant_qual/inteRact

Step 1: Load data, select events


#get US 2015 dictionary
us_2015 <- epa_subset(dataset = "usfullsurveyor2015")

#make a dataframe of events 
set.seed(129)
events <- tibble(actor_modifier = sample(us_2015$term[us_2015$component == "modifier"], 50),
                 actor = sample(us_2015$term[us_2015$component == "identity"], 50),
                 behavior = sample(us_2015$term[us_2015$component == "behavior"], 50),
                 object = sample(us_2015$term[us_2015$component == "identity"], 50))

Step 2: Reshape the dataframe to have EPA values

analysis_df <- reshape_events_df(events, df_format = "wide",
                                 dictionary_key = "usfullsurveyor2015", 
                                 dictionary_gender = "average")
#> Joining, by = c("term", "component")

Step 3: Nest your dataframe by event id and indicate the equation you will be using for your calculations - must be in the format “{equation_key}_{gender}” with the equation key coming from the actdata package.


nested_analysis <- analysis_df %>% ungroup() %>% 
                   nest_by(event_id) %>% 
                   mutate(equation_key = "us2010",
                          equation_gender = "average")

Step 4: Run some calculations

deflection <- nested_analysis %>% 
              mutate(d = get_deflection(d = data, 
                                        equation_key = equation_key,
                                        equation_gender = equation_gender))
start_time <- Sys.time()
multiple_functions <- nested_analysis %>% 
                      mutate(d = get_deflection(d = data, 
                                        equation_key = equation_key,
                                        equation_gender = equation_gender),
                            ti = list(transient_impression(d = data, 
                                        equation_key = equation_key,
                                        equation_gender = equation_gender)),
                            actor_reidentified = list(reidentify_actor(d = data, 
                                        equation_key = equation_key,
                                        equation_gender = equation_gender)))
end_time <- Sys.time()