```{R, include = FALSE} knitr::opts_chunk$set( fig.width = 7, collapse = TRUE, comment = "#>", message = FALSE, warning = FALSE )
To perform your first simulation you will need: 1. A `data.frame` specifying the experiment design, and 2. A list with the parameters for the model you will be using. ## The design data.frame Let's specify a blocking design. ```r library(calmr) my_blocking <- data.frame( Group = c("Exp", "Control"), Phase1 = c("10A(US)", "10C(US)"), Phase2 = c("10AB(US)", "10AB(US)"), Test = c("1#A/1#B", "1#A/1#B") ) # parsing the design and showing the original and what was detected parsed <- parse_design(my_blocking) parsed
A few rules about the design data.frame:
The trials in each phase column are specified using a very rigid notation. A handful of observations about it:
If you want to check whether your phase string will work with the package,
you can use phase_parser()
.
Warning: The function returns a list with a lot of information used by the models in the package, but the rule of thumb is that if you see a wall of text, your phase string is working.
# not specifying the number of AB trials. Error! phase_parser("AB/10AC") # putting the probe symbol out of order. Error! phase_parser("#10A") # considering a configural cue for elements AB trial <- phase_parser("10AB(AB)(US)") # different USs trial <- phase_parser("10A(US1)/10B(US2)") # tons of information! Phase parser is meant for internal use only. # you are better of using `parse_design()` on a design `data.frame` str(trial)
Now we need to pick a model and its parameters.
To get the models currently supported in calmr
, you can call supported_models()
.
supported_models()
After choosing a model, you can get some default parameters
for your design with get_parameters()
.
my_pars <- get_parameters(my_blocking, model = "RW1972") # Increasing the beta parameter for US presentations my_pars$betas_on["US"] <- .6 my_pars
For a reference on how each model is parametrized, check out the model's reference page. For example, the reference page for the "RW1972" model is here.
Or, if that many equations tire your eyes, you can consult the model parameter reference.
With all of the above, we can run our simulation using the run_experiment()
function.
This function also takes extra arguments to manipulate the number of iterations
to run the experiment for (important for designs with randomized trials),
whether to organize trials in miniblocks,
and extra configuration for more complex models
(see the help page for make_experiment()
for additional details).
Below, we keep it simple and run the experiment for a single iteration.
my_experiment <- run_experiment( my_blocking, # note we do not need to pass the parsed design model = "RW1972", parameters = my_pars ) # returns a `CalmrExperiment` object class(my_experiment) # CalmrExperiment is an S4 class, so it has slots slotNames(my_experiment) # some of the experience given to group Exp on the first (and only) iteration head(my_experiment@experiences[[1]]) # the number of times we ran the model (groups x iterations) length(experiences(my_experiment)) # an experiment has results with different levels of aggregation class(my_experiment@results) slotNames(my_experiment@results) # shorthand method to access aggregated_results results(my_experiment)
If you are an advanced R user you will be able to dig into the data straight away. However, the package also includes some methods to get a quick look at the results.
Let's use plot
method to create some plots.
Each model supports different types of plots according to the results they can produce
(e.g., associations, responses, saliences, etc.)
# get all the plots for the experiment plots <- plot(my_experiment) names(plots) # or get a specific type of plot specific_plot <- plot(my_experiment, type = "associations") names(specific_plot) # show which plots are supported by the model we are using supported_plots("RW1972")
In this case, the RW model supports both associations (associations) and responses (responses).
The columns in the plots below are the phases of the design and the rows denote the source of the association.
The colors within each panel determine the target of the association. For example, associations towards the US are shown in yellow.
plot(my_experiment, type = "associations")
Fairly similar to the above, but responding is a function of the stimuli presented in each trial.
plot(my_experiment, type = "responses")
You can also take a look at the state of the model's associations at any
point during the experiment, using the graph
method. The graphs are created using
the ggnetwork
package.
# some general options for ggnetwork my_graph_opts <- get_graph_opts("small") # passing the argument t to specify the trial we're interested in. # end of acquisition patch_graphs(graph(my_experiment, t = 10, options = my_graph_opts)) # end of blocking patch_graphs(graph(my_experiment, t = 20, options = my_graph_opts))
The design philosophy behind calmr
package revolves around simplicity and ease of access.
The user only needs to specify a design as well as a model to generate model predictions. In fact, there is also an app that lets users access the basic package functionality using a GUI.
That said, the package has plenty of features for more advanced R users. If you're one of them, make sure to check the other vignettes when you are ready.
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.