knitr::opts_chunk$set(echo = TRUE)
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) library(inteRact) 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
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)
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") glimpse(analysis_df)
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)
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)
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)))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.