You can also use inteRact to run simulations of using equations that are not in actdata. To do so, you have to first, put your equation into the format used by inteRact, and then supply the resulting equations dataframe in the inteRact function call.

Your equation should be in the V10000 format typically used in the interact.jar program. An example is shown below:

#libraries needed
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()
## Loading required package: actdata
library(actdata)

#read in your data file here
#should be in the V1000 format
my_equation <- read.table(here::here("data-raw/2010_equations.txt"))

Then, you can run the reshape_new_equation function on your equation, to get it into the final format needed to run all inteRact functions. After reshaping the equation, you should have a dataframe with 22 columns.

#reshape equation data to be in the form interact needed
eq_df <- reshape_new_equation(my_equation)

eq_df
## # A tibble: 15 × 22
##    coef_n…¹ postAE postAP postAA postBE postBP postBA postOE postOP postOA A    
##    <chr>     <dbl>  <dbl>  <dbl>  <dbl>  <dbl>  <dbl>  <dbl>  <dbl>  <dbl> <chr>
##  1 Z000000…  -0.16  -0.06  -0.05  -0.26   0.09   0.21  -0.18   0     -0.14 000  
##  2 Z100000…   0.62   0      0      0.52   0      0      0      0      0    100  
##  3 Z010000…   0      0.57   0      0      0.53   0      0      0      0    010  
##  4 Z001000…   0      0      0.26   0      0      0.15   0      0      0    001  
##  5 Z000100…   0.46  -0.29  -0.18   0.5   -0.21  -0.12   0.26   0.51   0.33 000  
##  6 Z000010…   0      0.62   0.12   0      0.64   0      0     -0.57  -0.41 000  
##  7 Z000001…   0      0      0.86   0      0      0.91   0      0      0.31 000  
##  8 Z000000…   0      0      0      0      0      0      0.91   0      0    000  
##  9 Z000000…   0     -0.2    0      0      0      0      0      0.47   0    000  
## 10 Z000000…   0      0      0      0      0      0.09   0      0      0.54 000  
## 11 Z100100…   0      0      0      0      0      0      0.16   0      0.54 100  
## 12 Z000100…   0.29   0      0      0.32   0      0      0.11   0      0    000  
## 13 Z000010…  -0.22   0      0     -0.27   0      0     -0.15   0      0    000  
## 14 Z000100…  -0.09   0      0      0      0      0      0      0      0    000  
## 15 Z001001…   0      0      0      0      0      0      0     -0.1    0    001  
## # … with 11 more variables: B <chr>, O <chr>, AE <dbl>, AP <dbl>, AA <dbl>,
## #   BE <dbl>, BP <dbl>, BA <dbl>, OE <dbl>, OP <dbl>, OA <dbl>, and abbreviated
## #   variable name ¹​coef_name

Next, construct your simulation events dataset.

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

#make a dataframe of events
set.seed(129)
events <- tibble(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))


dplyr::glimpse(events)
## Rows: 50
## Columns: 3
## $ actor    <chr> "grandmother", "buddy", "evangelical_christian", "hermit", "c…
## $ behavior <chr> "bewilder", "experience", "torment", "pester", "overcharge", …
## $ object   <chr> "mourner", "disciplinarian", "street_preacher", "consultant",…

And enrich the events data frame with the EPA information from an ACT dictionary using the reshape_events_df. This results in a dataframe with 9 rows for each event, one for each element-dimension.

#reshape with event info
analysis_df <- reshape_events_df(events, df_format = "wide",
                                 dictionary_key = "usfullsurveyor2015",
                                 dictionary_gender = "average")
## Joining, by = c("term", "component")
glimpse(analysis_df)
## Rows: 450
## Columns: 7
## Groups: event_id [50]
## $ event_id  <int> 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, …
## $ element   <chr> "actor", "actor", "actor", "behavior", "behavior", "behavior…
## $ term      <chr> "grandmother", "grandmother", "grandmother", "bewilder", "be…
## $ component <chr> "identity", "identity", "identity", "behavior", "behavior", …
## $ event     <chr> "grandmother bewilder mourner", "grandmother bewilder mourne…
## $ dimension <chr> "E", "P", "A", "E", "P", "A", "E", "P", "A", "E", "P", "A", …
## $ estimate  <dbl> 2.76, 0.89, -1.03, -0.34, 0.68, 0.65, -0.15, -1.60, -1.65, 2…

To finalize the dataframe for analysis, nest_by the event_id. It is important to nest_by() rather than just nesting after group_by(). Here you also put your equations dataframe in a new column as such.

#nest by event
nested_analysis <- analysis_df %>% ungroup() %>% 
                   dplyr::nest_by(event_id) %>% 
                   mutate(eq_df = list(eq_df))

Now you can run the functions on the dataframe, supplying the nested data and the equations dataframe.

#get deflection
deflection <- nested_analysis %>%
              mutate(d = get_deflection(d = data, 
                             eq_df = eq_df))

glimpse(deflection)
## Rows: 50
## Columns: 4
## Rowwise: event_id
## $ event_id <int> 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18…
## $ data     <list<tibble[,6]>> [<tbl_df[9 x 6]>], [<tbl_df[9 x 6]>], [<tbl_df[9…
## $ eq_df    <list> [<tbl_df[15 x 22]>], [<tbl_df[15 x 22]>], [<tbl_df[15 x 22]>…
## $ d        <dbl> 6.380303, 10.675613, 27.817563, 21.797024, 35.270588, 7.66000…

You can also do the same with getting the entire transient impression, but you have to list() the results and then unnest() them afterwards.

transimp <- nested_analysis %>%
              mutate(ti = list(transient_impression(d = data, 
                             eq_df = eq_df)))

transimp %>% unnest(ti)
## # A tibble: 450 × 9
## # Groups:   event_id [50]
##    event_id          data eq_df    element term  compo…¹ dimen…² estim…³ trans…⁴
##       <int> <list<tibble> <list>   <chr>   <chr> <chr>   <chr>     <dbl>   <dbl>
##  1        1       [9 × 6] <tibble> actor   gran… identi… E          2.76   1.38 
##  2        1       [9 × 6] <tibble> actor   gran… identi… P          0.89   1.29 
##  3        1       [9 × 6] <tibble> actor   gran… identi… A         -1.03   0.384
##  4        1       [9 × 6] <tibble> behavi… bewi… behavi… E         -0.34   1.05 
##  5        1       [9 × 6] <tibble> behavi… bewi… behavi… P          0.68   1.07 
##  6        1       [9 × 6] <tibble> behavi… bewi… behavi… A          0.65   0.539
##  7        1       [9 × 6] <tibble> object  mour… identi… E         -0.15  -0.534
##  8        1       [9 × 6] <tibble> object  mour… identi… P         -1.6   -1.32 
##  9        1       [9 × 6] <tibble> object  mour… identi… A         -1.65  -1.73 
## 10        2       [9 × 6] <tibble> actor   buddy identi… E          2.66   2.29 
## # … with 440 more rows, and abbreviated variable names ¹​component, ²​dimension,
## #   ³​estimate, ⁴​trans_imp

Finally, you can also run functions together as such:

multiple_functions <- nested_analysis %>%
                      mutate(d = get_deflection(d = data, 
                                        eq_df = eq_df),
                            ti = list(transient_impression(d = data, 
                                        eq_df = eq_df)),
                            actor_reidentified = list(reidentify_actor(d = data, 
                                        eq_df = eq_df)))