diff --git a/articles/HD2022.html b/articles/HD2022.html index 67befdb..f8bb0d3 100644 --- a/articles/HD2022.html +++ b/articles/HD2022.html @@ -192,7 +192,7 @@

2 - Pooling the strength of associ

2.1 - Combined associative strength

The quantity \(o_{j,M}\) is the -result of combining the associative strength of forwards and backwards +result of combining the associative strength of forward and backward associations to and from stimulus \(j\) as

\[ @@ -200,14 +200,14 @@

2.1 - Combined associative strength

-

where each of the sums above run over all stimuli \(M\) presented in the trial, that are also -different from stimulus \(j\).2 The left -hand term describes how the forward associations from stimuli \(M\) to \(j\) affect the representation of \(j\), whereas the right hand term describes -how the backward associations that \(j\) has with stimuli \(M\) affect its own representation (although +exhaustively.</p>'>2 The left-hand term +describes how the forward associations from stimuli \(M\) to \(j\) affect the representation of \(j\), whereas the right-hand term describes +how the backward associations that \(j\) has with stimuli \(M\) affect its representation (although these are modulated by the forward associations themselves).

@@ -226,17 +226,19 @@

2.2 - Chained associative strength\(M\).

In Honey and Dwyer (2022), the authors specify a similarity-based mechanism that modulates the effect of associative chains according to -the similarity of the salience of nominal and retrieved stimuli. As -such, Eq. 6a is expanded as:

+the similarity of the salience of nominal and retrieved stimuli
3. As such, +Eq. 6a is expanded as:

\[ \tag{Eq. 6b} h_{j,M} = \sum_{m \neq j}^{M} \sum_{n}^{N}S(\alpha_{n}, \alpha'_n)\frac{v_{m,n}o_{j,n}}{c} \]

where \(S\) is a similarity function -that takes the nominal salience of stimulus n, \(\alpha_n\) (as perceived when \(n\) is actually presented on a trial) and -its retrieved salience, \(\alpha'_n\) (as perceived when \(n\) is retrieved via other stimuli M, see -ahead). This function is defined as:

+that takes the nominal salience of stimulus n, \(\alpha_n\) (as perceived when \(n\) is presented on a trial) and its +retrieved salience, \(\alpha'_n\) +(as perceived when \(n\) is retrieved +via other stimuli M, see ahead). This function is defined as:

\[ \tag{Eq. 7} S(\alpha_n, \alpha'_n) = \frac{\alpha_n}{\alpha_n + @@ -273,19 +275,19 @@

3 - Distrib \alpha_k, & \text{otherwise} \end{cases} \]

-

Note that the quantity for absent stimuli is absolute, in order to -prevent negative \(\theta\) values due -to inhibitory associations3. Also note a summation term is used on the +extensively used in neural networks. Another alternative that avoids the +use of absolute values or a rectifying mechanism would be to use +quantities of <span class="math inline">\(e^{\theta(k)}\)</span> instead +of <span class="math inline">\(\theta(k)\)</span>.</p>'>4. Also, note a summation term is used on the left-hand side of the expression for an absent stimulus. It implies that all the present stimuli \(M\) -contribute to the salience of stimulus \(k\). Finally, note on the right side of the -same expression that the present stimuli contribute not only via the -direct association each of them have with \(k\), \(v_{m,k}\), but also through associative +contribute to the salience of stimulus \(k\). Finally, note on the right-hand side +of the same expression that the present stimuli contribute not only via +the direct association each of them has with \(k\), \(v_{m,k}\) but also through associative chains with other absent stimuli (c.f., Eq. 6a).

diff --git a/articles/MAC1975.html b/articles/MAC1975.html index 1940e10..2648bbb 100644 --- a/articles/MAC1975.html +++ b/articles/MAC1975.html @@ -108,7 +108,7 @@

Victor

The mathematics behind MAC1975

A grand departure from global error term models such as RW1972 (Rescorla & Wagner, 1972), the MAC1975 model -(Mackintosh, 1975) uses local error terms, +(Mackintosh, 1975) uses local error terms and changes stimulus associability (\(\alpha\)) via an error comparison mechanism that promotes learning about uncertain stimuli:

4 - Generating responses diff --git a/articles/PKH1982.html b/articles/PKH1982.html index 39579e6..7981cc7 100644 --- a/articles/PKH1982.html +++ b/articles/PKH1982.html @@ -154,11 +154,12 @@

2 - Learning associations\(j\), is lower than its excitatory asymptote (i.e., \(e_j < \lambda_j\)), but 0 if not. This implies that the model stops strengthening \(v_{i,j}\) if the expectation of \(j\) is higher than its excitatory -assymptote.

+asymptote.

As mentioned in the introductory note, the PKH1982 model does not learn excitatory associations via correction error. However, the model does learn inhibitory associations via correction -error, as the overexpectation term above, \(\overline {\lambda_j}\) is equal to \(min(\lambda_j - e_j, 0)\), where \(min\) is the minimum function. This implies +error, as the overexpectation term above, \(\overline +{\lambda_j}\) is equal to \(min(\lambda_j - e_j, 0)\), where \(min\) is the minimum function. This implies \(\overline {\lambda_j}\) only takes non-zero values when the expectation of \(j\) is higher than its intensity on the trial (\(\lambda_j\)).

@@ -173,7 +174,7 @@

3 - Learning to attend\(\gamma_j\) denotes -the contribution of the prediction error based on the jth stimulus. To +the contribution of the prediction error based on the jth stimulus. In this regard, it is important to note that Pearce et al. (1982) did not extend their model to account for the predictive power of within-compound associations, yet the implementation @@ -181,10 +182,10 @@

3 - Learning to attend\(\gamma_j\) (defaulting to 1/K) that denotes whether the expectation of stimulus \(j\) contributes to attentional learning. As -such, the user can set these parameters manually in order to reflect +such, the user can set these parameters manually to reflect the contribution of the different experimental stimuli. For example, in a -simple “AB>(US)” design, setting \(\gamma_{US}\) = 1 and \(\gamma_{A} = \gamma_{B} = 0\) leads to the -behaviour of the original model.

+simple “AB>(US)” design, setting \(\gamma_{US}\) = 1 and \(\gamma_{A} = +\gamma_{B} = 0\) leads to the behavior of the original model.

The PKH1982 model improves upon the Pearce & Hall (1980) model by adding an extra parameter that controls the rate at which associability changes. If we qualify the diff --git a/articles/RAND.html b/articles/RAND.html index 9d78157..1b5834e 100644 --- a/articles/RAND.html +++ b/articles/RAND.html @@ -107,7 +107,7 @@

Victor

The mathematics behind RAND

-

RAND is a model is a RW-based model that has its associations +

RAND is a model is an RW-based model that has its associations randomized on every trial. Therefore, the model responds randomly.

This model is meant to be in comparisons only.

diff --git a/articles/SM2007.html b/articles/SM2007.html index 5266fdb..a7c4069 100644 --- a/articles/SM2007.html +++ b/articles/SM2007.html @@ -129,7 +129,7 @@

1 - Learning associations\(t\). As such, the SOCR model only learns about stimuli that are presented. The parameters \(\alpha_i\) and \(\alpha_j\) are the saliencies of stimuli i and j, respectively, and \(\lambda_j\) -is a the maximum association strength supported by \(j\) (the asymptote).

+is the maximum association strength supported by \(j\) (the asymptote).

Whenever stimulus \(i\) is presented alone (i.e., stimulus \(j\) is absent), the weakening of that association is given by:

@@ -197,11 +197,11 @@

3 - Generating responses processes themselves. The number of potential comparison processes is technically infinite (each comparison process can nest two extra comparison processes itself), so the user must determine the order of -model using an extra global parameter (order). For all n-th -order models (with \(n > 0\)), the -model will behave like the extended comparator hypothesis (Denniston et al., 2001), implementing \(n\) comparison processes each time the +the model using an extra global parameter (order). For all +n-th order models (with \(n > 0\)), +the model will behave like the extended comparator hypothesis (Denniston et al., 2001), implementing \(n\) comparison processes each time the relative activations are calculated. With order = 0, SM2007 -will behave like it was originally written, and only consider one +will behave like it was originally written and only consider one comparison process. Indeed, n-th order models are accomplished via recursion using the 0-th order model as the stopping condition. When such a condition is reached, the \(r^k_i\) and \(r^j_k\) terms in Eq. 3 become \(act_{i,k}\) and \(act_{k,j}\), respectively.

diff --git a/articles/calm_basics.html b/articles/calm_basics.html index ca4e4d8..6ba06c8 100644 --- a/articles/calm_basics.html +++ b/articles/calm_basics.html @@ -116,28 +116,41 @@

Your first simulation

The design data.frame

-

We will use a data.frame to specify our experimental design. Let’s -specify a blocking design.

+

For this example we will use a blocking design.

 library(calm)
 
 my_blocking <- data.frame(
   Group = c("Exp", "Control"),
-  Phase1 = c("10A>(US)", "10C>(US)"),
+  Phase1 = c("10A(US)", "10C(US)"),
   R1 = c(FALSE, FALSE),
-  Phase2 = c("10AB>(US)", "10AB>(US)"),
+  Phase2 = c("10AB(US)", "10AB(US)"),
   R2 = c(FALSE, FALSE),
-  Test = c("1A#/1B#", "1A#/1B#"),
+  Test = c("1#A/1#B", "1#A/1#B"),
   R3 = c(FALSE, FALSE)
 )
-my_blocking
-#>     Group   Phase1    R1    Phase2    R2    Test    R3
-#> 1     Exp 10A>(US) FALSE 10AB>(US) FALSE 1A#/1B# FALSE
-#> 2 Control 10C>(US) FALSE 10AB>(US) FALSE 1A#/1B# FALSE
+# parsing the design and showing the original and what was detected +parsed <- parse_design(my_blocking) +parsed +#> CalmDesign built from data.frame: +#> Group Phase1 R1 Phase2 R2 Test R3 +#> 1 Exp 10A(US) FALSE 10AB(US) FALSE 1#A/1#B FALSE +#> 2 Control 10C(US) FALSE 10AB(US) FALSE 1#A/1#B FALSE +#> ---------------- +#> Trials detected: +#> group phase trial_names trial_repeats is_test stimuli +#> 1 Exp Phase1 A(US) 10 FALSE A;US +#> 2 Exp Phase2 AB(US) 10 FALSE A;B;US +#> 3 Exp Test #A 1 TRUE A +#> 4 Exp Test #B 1 TRUE B +#> 5 Control Phase1 C(US) 10 FALSE C;US +#> 6 Control Phase2 AB(US) 10 FALSE A;B;US +#> 7 Control Test #A 1 TRUE A +#> 8 Control Test #B 1 TRUE B

A few rules about the design data.frame:

  1. Each row represents a group.
  2. -
  3. Its first column contains the group labels.
  4. +
  5. The first column contains the group labels.
  6. The remaining columns are organized in pairs (trials in a phase, and whether to randomize them)
@@ -145,8 +158,8 @@

The design data.frame
  1. Trials are preceded by a number. That number represents the number -of times that trial will be given in each phase. “10A>(US)” means -that the “A>(US)” trial will be given 10 times.
  2. +of times that trial will be given in each phase. “10A(US)” means that +the “A(US)” trial will be given 10 times.
  3. The presence and absence of the unconditioned stimulus are not denoted with the traditional “+” and “-” symbols. Instead, here we use parenthesis to denote “complex” stimuli. These can be thought of as an @@ -155,10 +168,6 @@

    The design data.frameIn the same vein, multiple characters with no parentheses denote individual elements. For example, “AB” implies the presence of two stimuli, A and B.

  4. -
  5. The “>” character is used as a separator of the “expectations” -and “correction” steps within the trial. “10A>(US)” means that the -model generates an expectation with A only, but learns from the -co-occurrence of A and the US.
  6. The “/” character is used as a trial separator (it does not imply randomization by itself). Thus, “1A/1B” specifies that a single “A” trial and a single “B” trial will be given during that phase. Recall @@ -170,25 +179,21 @@

    The design data.frame

-

If you want to check whether your trial string will work with the +

If you want to check whether your phase string will work with the simulator, you can use phase_parser. The function returns a list with a lot of information, so let’s print only some of the fields.

-# not specifying a number of AB trials. Bad practice!
-trial <- phase_parser("AB/10AC")
-trial$general_info[c("trial_names", "trial_repeats")]
-#> $trial_names
-#> [1] "AB" "AC"
-#> 
-#> $trial_repeats
-#> [1]  1 10
+# not specifying a number of AB trials. Error!
+phase_parser("AB/10AC")
+#> Error in if (is.na(treps)) 1 else treps: argument is of length zero
+# putting the probe symbol out of order. Error!
+phase_parser("#10A")
+#> Error in if (is.na(treps)) 1 else treps: argument is of length zero
 # considering a configural cue for elements AB
 trial <- phase_parser("10AB(AB)(US)")
-trial$general_info[c("func2nomi")]
-#> $func2nomi
-#>    A    B   AB   US 
-#>  "A"  "B" "AB" "US"
+# different USs +trial <- phase_parser("10A(US1)/10B(US2)")

The parameters list @@ -200,8 +205,8 @@

The parameters listsupported_models() #> [1] "HDI2020" "HD2022" "RW1972" "MAC1975" "PKH1982" "SM2007" "RAND" #> [8] "ANCCR"

-

After picking a model, you can get default parameters for your design -with get_parameters.

+

After choosing a model, you can get default parameters for your +design with get_parameters.

 my_pars <- get_parameters(my_blocking, model = "RW1972")
 # Increasing the beta parameter for US presentations
@@ -223,91 +228,98 @@ 

The parameters list#> A B C US #> 1 1 1 1

-

The (optional) additional options -

-

If you opt to, you can also pass a list with simulation options. -Simulation options are entirely optional, and if you don’t pass them you -will just get a warning.

-

We can get a default one with get_exp_opts, and modify -them accordingly.

-
-my_opts <- get_exp_opts()
-# Increase number of simulations to average out randomization effects
-my_opts$iterations <- 5
-my_opts
-#> $iterations
-#> [1] 5
-#> 
-#> $miniblocks
-#> [1] TRUE
-
-

Simulating

With all of the above, we can run our simulation using the -run_experiment function.

-
+run_experiment function. This function also takes extra
+arguments to manipulate the number of iterations to run the experiment
+for, and whether to organize trials in miniblocks (see
+help(make_experiment) for additional details). Below, we
+run the experiment for 5 iterations.

+
 my_experiment <- run_experiment(
-  my_blocking,
+  my_blocking, # note we do not need to pass the parsed design
   model = "RW1972",
   parameters = my_pars,
-  options = my_opts,
+  iterations = 5
 )
+# returns an CalmExperiment object
+class(my_experiment)
+#> [1] "CalmExperiment"
+#> attr(,"package")
+#> [1] "calm"
+# CalmExperiment is an S4 class, so it has slots
 slotNames(my_experiment)
-#> [1] "arguments" "design"    "results"
-# access arguments (see how many iterations we ran?)
-my_experiment@arguments
-#> # A tibble: 10 × 6
-#>    iteration model  group   experience    mapping           parameters      
-#>        <int> <chr>  <chr>   <list>        <list>            <list>          
-#>  1         1 RW1972 Control <df [22 × 7]> <named list [12]> <named list [4]>
-#>  2         1 RW1972 Exp     <df [22 × 7]> <named list [12]> <named list [4]>
-#>  3         2 RW1972 Control <df [22 × 7]> <named list [12]> <named list [4]>
-#>  4         2 RW1972 Exp     <df [22 × 7]> <named list [12]> <named list [4]>
-#>  5         3 RW1972 Control <df [22 × 7]> <named list [12]> <named list [4]>
-#>  6         3 RW1972 Exp     <df [22 × 7]> <named list [12]> <named list [4]>
-#>  7         4 RW1972 Control <df [22 × 7]> <named list [12]> <named list [4]>
-#>  8         4 RW1972 Exp     <df [22 × 7]> <named list [12]> <named list [4]>
-#>  9         5 RW1972 Control <df [22 × 7]> <named list [12]> <named list [4]>
-#> 10         5 RW1972 Exp     <df [22 × 7]> <named list [12]> <named list [4]>
-# access results
+#> [1] "design"      "model"       "groups"      "parameters"  "experiences"
+#> [6] "results"     ".model"      ".group"      ".iter"
+# the experience given to group Exp on the first iteration
+my_experiment@experiences[[1]]
+#>     model group  phase tp     tn is_test block_size trial
+#> 1  RW1972   Exp Phase1  1  A(US)   FALSE          1     1
+#> 2  RW1972   Exp Phase1  1  A(US)   FALSE          1     2
+#> 3  RW1972   Exp Phase1  1  A(US)   FALSE          1     3
+#> 4  RW1972   Exp Phase1  1  A(US)   FALSE          1     4
+#> 5  RW1972   Exp Phase1  1  A(US)   FALSE          1     5
+#> 6  RW1972   Exp Phase1  1  A(US)   FALSE          1     6
+#> 7  RW1972   Exp Phase1  1  A(US)   FALSE          1     7
+#> 8  RW1972   Exp Phase1  1  A(US)   FALSE          1     8
+#> 9  RW1972   Exp Phase1  1  A(US)   FALSE          1     9
+#> 10 RW1972   Exp Phase1  1  A(US)   FALSE          1    10
+#> 11 RW1972   Exp Phase2  2 AB(US)   FALSE          1    11
+#> 12 RW1972   Exp Phase2  2 AB(US)   FALSE          1    12
+#> 13 RW1972   Exp Phase2  2 AB(US)   FALSE          1    13
+#> 14 RW1972   Exp Phase2  2 AB(US)   FALSE          1    14
+#> 15 RW1972   Exp Phase2  2 AB(US)   FALSE          1    15
+#> 16 RW1972   Exp Phase2  2 AB(US)   FALSE          1    16
+#> 17 RW1972   Exp Phase2  2 AB(US)   FALSE          1    17
+#> 18 RW1972   Exp Phase2  2 AB(US)   FALSE          1    18
+#> 19 RW1972   Exp Phase2  2 AB(US)   FALSE          1    19
+#> 20 RW1972   Exp Phase2  2 AB(US)   FALSE          1    20
+#> 21 RW1972   Exp   Test  3     #A    TRUE          2    21
+#> 22 RW1972   Exp   Test  4     #B    TRUE          2    22
+# the number of times we ran the model (groups x iterations)
+length(experiences(my_experiment))
+#> [1] 10
+# an experiment has results with different levels of aggregation
+class(my_experiment@results)
+#> [1] "CalmExperimentResult"
+#> attr(,"package")
+#> [1] "calm"
+slotNames(my_experiment@results)
+#> [1] "aggregated_results" "parsed_results"     "raw_results"
+# shorthand method to access aggregated_results
 results(my_experiment)
 #> $rs
-#> # A tibble: 704 × 9
-#>    model  group   phase  trial_type trial s1    s2    block_size value
-#>    <chr>  <chr>   <chr>  <chr>      <int> <chr> <chr>      <dbl> <dbl>
-#>  1 RW1972 Control Phase1 C>(US)         1 A     A              1     0
-#>  2 RW1972 Control Phase1 C>(US)         1 A     B              1     0
-#>  3 RW1972 Control Phase1 C>(US)         1 A     C              1     0
-#>  4 RW1972 Control Phase1 C>(US)         1 A     US             1     0
-#>  5 RW1972 Control Phase1 C>(US)         1 B     A              1     0
-#>  6 RW1972 Control Phase1 C>(US)         1 B     B              1     0
-#>  7 RW1972 Control Phase1 C>(US)         1 B     C              1     0
-#>  8 RW1972 Control Phase1 C>(US)         1 B     US             1     0
-#>  9 RW1972 Control Phase1 C>(US)         1 C     A              1     0
-#> 10 RW1972 Control Phase1 C>(US)         1 C     B              1     0
-#> # ℹ 694 more rows
+#>        group  phase trial_type trial     s1     s2 block_size value  model
+#>       <char> <char>     <char> <int> <char> <char>      <num> <num> <char>
+#>   1:     Exp Phase1      A(US)     1      A      A          1     0 RW1972
+#>   2:     Exp Phase1      A(US)     1      A      B          1     0 RW1972
+#>   3:     Exp Phase1      A(US)     1      A      C          1     0 RW1972
+#>   4:     Exp Phase1      A(US)     1      A     US          1     0 RW1972
+#>   5:     Exp Phase1      A(US)     1      B      A          1     0 RW1972
+#>  ---                                                                      
+#> 700: Control   Test         #B    22      C     US          2     0 RW1972
+#> 701: Control   Test         #B    22     US      A          2     0 RW1972
+#> 702: Control   Test         #B    22     US      B          2     0 RW1972
+#> 703: Control   Test         #B    22     US      C          2     0 RW1972
+#> 704: Control   Test         #B    22     US     US          2     0 RW1972
 #> 
 #> $vs
-#> # A tibble: 704 × 9
-#>    model  group   phase  trial_type trial s1    s2    block_size value
-#>    <chr>  <chr>   <chr>  <chr>      <int> <chr> <chr>      <dbl> <dbl>
-#>  1 RW1972 Control Phase1 C>(US)         1 A     A              1     0
-#>  2 RW1972 Control Phase1 C>(US)         1 A     B              1     0
-#>  3 RW1972 Control Phase1 C>(US)         1 A     C              1     0
-#>  4 RW1972 Control Phase1 C>(US)         1 A     US             1     0
-#>  5 RW1972 Control Phase1 C>(US)         1 B     A              1     0
-#>  6 RW1972 Control Phase1 C>(US)         1 B     B              1     0
-#>  7 RW1972 Control Phase1 C>(US)         1 B     C              1     0
-#>  8 RW1972 Control Phase1 C>(US)         1 B     US             1     0
-#>  9 RW1972 Control Phase1 C>(US)         1 C     A              1     0
-#> 10 RW1972 Control Phase1 C>(US)         1 C     B              1     0
-#> # ℹ 694 more rows
-

The run_experiment returns a lot of information. The str -function will be your best friend, and there is plenty of documentation -to go about.

-

Of course, if you are an advanced R user you will be able to dig into -the data straight away.

+#> group phase trial_type trial s1 s2 block_size value model +#> <char> <char> <char> <int> <char> <char> <num> <num> <char> +#> 1: Exp Phase1 A(US) 1 A A 1 0.0000000 RW1972 +#> 2: Exp Phase1 A(US) 1 A B 1 0.0000000 RW1972 +#> 3: Exp Phase1 A(US) 1 A C 1 0.0000000 RW1972 +#> 4: Exp Phase1 A(US) 1 A US 1 0.0000000 RW1972 +#> 5: Exp Phase1 A(US) 1 B A 1 0.0000000 RW1972 +#> --- +#> 700: Control Test #B 22 C US 2 0.9939534 RW1972 +#> 701: Control Test #B 22 US A 2 0.4999999 RW1972 +#> 702: Control Test #B 22 US B 2 0.4999999 RW1972 +#> 703: Control Test #B 22 US C 2 0.6626356 RW1972 +#> 704: Control Test #B 22 US US 2 0.0000000 RW1972
+

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.

@@ -318,19 +330,19 @@

PlottingLet’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)
-#> [1] "Control - Response Strength (RW1972)"   
-#> [2] "Exp - Response Strength (RW1972)"       
-#> [3] "Control - Association Strength (RW1972)"
-#> [4] "Exp - Association Strength (RW1972)"
+#> [1] "Exp - Response Strength (RW1972)"       
+#> [2] "Control - Response Strength (RW1972)"   
+#> [3] "Exp - Association Strength (RW1972)"    
+#> [4] "Control - Association Strength (RW1972)"
 # or get a specific type of plot
 specific_plot <- plot(my_experiment, type = "vs")
 names(specific_plot)
-#> [1] "Control - Association Strength (RW1972)"
-#> [2] "Exp - Association Strength (RW1972)"
+#> [1] "Exp - Association Strength (RW1972)"    
+#> [2] "Control - Association Strength (RW1972)"
 # show which plots are supported by the model we are using
 supported_plots("RW1972")
 #> [1] "rs" "vs"
@@ -342,51 +354,51 @@

Stimulus associationsThe columns 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.

-
+
 plot(my_experiment, type = "vs")
-#> $`Control - Association Strength (RW1972)`
-

+#> $`Exp - Association Strength (RW1972)`
+

#> 
-#> $`Exp - Association Strength (RW1972)`
-

+#> $`Control - Association Strength (RW1972)`

+

Responding

Fairly similar to the above, but this time responding is a function of the stimuli presented on a trial.

-
+
 plot(my_experiment, type = "rs")
-#> $`Control - Response Strength (RW1972)`
-

+#> $`Exp - Response Strength (RW1972)`
+

#> 
-#> $`Exp - Response Strength (RW1972)`
-

+#> $`Control - Response Strength (RW1972)` +

Graphing

You can also take a look at the state of the model’s associations at -any point during training, using the graph method on your +any point during training, using the graph method in your experiment.

-
+
 my_graph_opts <- get_graph_opts("small")
-graph(my_experiment, t = 20, graph_opts = my_graph_opts)
+graph(my_experiment, t = 20, graph_opts = my_graph_opts)
 #> $RW1972
-#> $RW1972$`Control - Associations (RW1972)`
-

+#> $RW1972$`Exp - Associations (RW1972)`
+

#> 
-#> $RW1972$`Exp - Associations (RW1972)`
-

+#> $RW1972$`Control - Associations (RW1972)` +

Final thoughts

The calm package was designed to simulate quickly: write -your design and get a glance at model predictions. That said, the -package also has some features for advanced R users, so make sure to -check more advanced vignettes when you are ready.

+your design and get a glance at model predictions.

+

Yet, the package also has some features for advanced R users, so make +sure to check the other vignettes when you are ready.

diff --git a/articles/calm_basics_files/figure-html/unnamed-chunk-10-1.png b/articles/calm_basics_files/figure-html/unnamed-chunk-10-1.png index b0ef381..e342976 100644 Binary files a/articles/calm_basics_files/figure-html/unnamed-chunk-10-1.png and b/articles/calm_basics_files/figure-html/unnamed-chunk-10-1.png differ diff --git a/articles/calm_basics_files/figure-html/unnamed-chunk-10-2.png b/articles/calm_basics_files/figure-html/unnamed-chunk-10-2.png index f1f8386..cf1cca0 100644 Binary files a/articles/calm_basics_files/figure-html/unnamed-chunk-10-2.png and b/articles/calm_basics_files/figure-html/unnamed-chunk-10-2.png differ diff --git a/articles/calm_basics_files/figure-html/unnamed-chunk-8-1.png b/articles/calm_basics_files/figure-html/unnamed-chunk-8-1.png new file mode 100644 index 0000000..fa21bb6 Binary files /dev/null and b/articles/calm_basics_files/figure-html/unnamed-chunk-8-1.png differ diff --git a/articles/calm_basics_files/figure-html/unnamed-chunk-8-2.png b/articles/calm_basics_files/figure-html/unnamed-chunk-8-2.png new file mode 100644 index 0000000..f8ff956 Binary files /dev/null and b/articles/calm_basics_files/figure-html/unnamed-chunk-8-2.png differ diff --git a/articles/calm_basics_files/figure-html/unnamed-chunk-9-1.png b/articles/calm_basics_files/figure-html/unnamed-chunk-9-1.png index f8ff956..ee6088f 100644 Binary files a/articles/calm_basics_files/figure-html/unnamed-chunk-9-1.png and b/articles/calm_basics_files/figure-html/unnamed-chunk-9-1.png differ diff --git a/articles/calm_basics_files/figure-html/unnamed-chunk-9-2.png b/articles/calm_basics_files/figure-html/unnamed-chunk-9-2.png index fa21bb6..88f0444 100644 Binary files a/articles/calm_basics_files/figure-html/unnamed-chunk-9-2.png and b/articles/calm_basics_files/figure-html/unnamed-chunk-9-2.png differ diff --git a/articles/calm_fits.html b/articles/calm_fits.html index c8685f4..4a84778 100644 --- a/articles/calm_fits.html +++ b/articles/calm_fits.html @@ -107,7 +107,6 @@

Victor
 library(calm)
 library(ggplot2)
-library(magrittr)
 library(dplyr)
 library(tidyr)
 theme_set(theme_bw())
@@ -140,7 +139,7 @@ 

The data#> $ us <chr> "P", "P", "P", "P", "P", "P", "S", "S", "S", "S", "S", "S", "… #> $ response <fct> lp, lp, lp, lp, lp, lp, lp, lp, lp, lp, lp, lp, np, np, np, n… #> $ rpert <dbl> 0.9000, 1.5500, 3.3500, 4.1500, 4.6500, 4.3250, 0.4000, 0.162… -pati %>% ggplot(aes(x = block, y = rpert, colour = us)) + +pati |> ggplot(aes(x = block, y = rpert, colour = us)) + geom_line(aes(group = interaction(us, subject)), alpha = .3) + stat_summary(geom = "line", fun = "mean", linewidth = 1) + labs(x = "Block", y = "Responses per trial", colour = "US") + @@ -160,8 +159,8 @@

Writing the model function
-pati_summ <- pati %>%
-  group_by(block, us, response) %>%
+pati_summ <- pati |>
+  group_by(block, us, response) |>
   summarise(rpert = mean(rpert), .groups = "drop")
 head(pati_summ)
 #> # A tibble: 6 × 4
@@ -175,19 +174,19 @@ 

Writing the model function#> 6 2 P np 3.51

We now prepare the arguments for the model function (as you would pass to run_experimentexperiment.

-

This is no minor issue, because the HeiDI is sensitive to order -effects. Hence, it is important that the arguments we prepare here -reflect the behavior of the model after an “general” experimental -procedure, and not the quirks of an unfortunate run of tials. Here, we -simply address this issue by running several iterations of the model -(with random trial orders) and average all models before evaluating the -likelihood of the parameters.

-

So what do we have to design? The experiment presented in Patittuci +

This is no minor issue because the HeiDI is sensitive to order +effects. Hence, the arguments we prepare here must reflect the behavior +of the model after a “general” experimental procedure, and not the +quirks of an unfortunate run of trials. Here, we simply address this +issue by running several iterations of the model (with random trial +orders) and averaging all models before evaluating the likelihood of the +parameters.

+

So what do we have to design? The experiment presented by Patittuci et al. (2016) was fairly simple, and it can be reduced to the presentations of two levers, each followed by a different appetitive outcome. Here, we will assume that the two outcomes are independent from each other. We will also take some liberties with the number of trials -we specify, in order to reduce computing time.

+we specify, to reduce computing time.

 # The design data.frame
 des_df <- data.frame(
@@ -204,89 +203,109 @@ 

Writing the model functionparameters <- get_parameters(des_df, model = "HD2022" ) -# The options -options <- get_exp_opts(iterations = 4) # The arguments experiment <- make_experiment(des_df, parameters = parameters, model = "HD2022", - options = options + iterations = 4 )

-

Note we specified two counterbalancings as groups. It is very -important that we reproduce the counterbalancings in the data we are -trying to fit as close as possible. Otherwise, the optimization process -might latch onto experimentally-irrelevant variables. For example, it -can be seen in pati that there was more lever pressing -whenever a lever was paired with pellets. If we didn’t counterbalance -the identities of the levers and USs, the optimization might result into -one of the levers being less salient than the other.

+

Note we specified two counterbalancings as groups. We must reproduce +the counterbalancings in the data we are trying to fit as close as +possible. Otherwise, the optimization process might latch onto +experimentally-irrelevant variables. For example, it can be seen in +pati that there was more lever pressing whenever a lever +was paired with pellets. If we didn’t counterbalance the identities of +the levers and USs, the optimization might result in one of the levers +being less salient than the other.

We can now begin to write the model function. First, it would be a -good idea to see what results run_experiment returns.

+good to see what results run_experiment returns.

 exp_res <- run_experiment(experiment)
 results(exp_res)
 #> $as
-#> # A tibble: 344 × 8
-#>    model  group phase    trial_type  trial s1    block_size value
-#>    <chr>  <chr> <chr>    <chr>       <int> <fct>      <dbl> <dbl>
-#>  1 HD2022 CB1   training L>(Pellet)      1 L              2   0.4
-#>  2 HD2022 CB1   training R>(Sucrose)     2 L              2   0  
-#>  3 HD2022 CB1   training R>(Sucrose)     3 L              2   0  
-#>  4 HD2022 CB1   training L>(Pellet)      4 L              2   0.4
-#>  5 HD2022 CB1   training R>(Sucrose)     5 L              2   0  
-#>  6 HD2022 CB1   training L>(Pellet)      6 L              2   0.4
-#>  7 HD2022 CB1   training L>(Pellet)      7 L              2   0.4
-#>  8 HD2022 CB1   training R>(Sucrose)     8 L              2   0  
-#>  9 HD2022 CB1   training R>(Sucrose)     9 L              2   0  
-#> 10 HD2022 CB1   training L>(Pellet)     10 L              2   0.4
-#> # ℹ 334 more rows
+#>       group    phase  trial_type trial      s1 block_size value  model
+#>      <char>   <char>      <char> <int>  <fctr>      <num> <num> <char>
+#>   1:    CB1 training  L>(Pellet)     1       L          2   0.4 HD2022
+#>   2:    CB1 training R>(Sucrose)     2       L          2   0.0 HD2022
+#>   3:    CB1 training R>(Sucrose)     3       L          2   0.0 HD2022
+#>   4:    CB1 training  L>(Pellet)     4       L          2   0.4 HD2022
+#>   5:    CB1 training R>(Sucrose)     5       L          2   0.0 HD2022
+#>  ---                                                                  
+#> 340:    CB2 training  R>(Pellet)    10  Pellet          2   0.4 HD2022
+#> 341:    CB2 training L>(Sucrose)     9       R          2   0.0 HD2022
+#> 342:    CB2 training  R>(Pellet)    10       R          2   0.4 HD2022
+#> 343:    CB2 training L>(Sucrose)     9 Sucrose          2   0.4 HD2022
+#> 344:    CB2 training  R>(Pellet)    10 Sucrose          2   0.0 HD2022
 #> 
 #> $acts
-#> # A tibble: 1,272 × 10
-#>    model  group phase    trial_type  trial s1      s2     block_size type  value
-#>    <chr>  <chr> <chr>    <chr>       <int> <chr>   <chr>       <dbl> <chr> <dbl>
-#>  1 HD2022 CB1   training L>(Pellet)      1 LPellet L               2 comb…     0
-#>  2 HD2022 CB1   training L>(Pellet)      1 LPellet Pellet          2 comb…     0
-#>  3 HD2022 CB1   training L>(Pellet)      1 LPellet R               2 comb…     0
-#>  4 HD2022 CB1   training L>(Pellet)      1 LPellet Sucro…          2 comb…     0
-#>  5 HD2022 CB1   training R>(Sucrose)     2 LPellet L               2 comb…     0
-#>  6 HD2022 CB1   training R>(Sucrose)     2 LPellet Pellet          2 comb…     0
-#>  7 HD2022 CB1   training R>(Sucrose)     2 LPellet R               2 comb…     0
-#>  8 HD2022 CB1   training R>(Sucrose)     2 LPellet Sucro…          2 comb…     0
-#>  9 HD2022 CB1   training R>(Sucrose)     3 LPellet L               2 comb…     0
-#> 10 HD2022 CB1   training R>(Sucrose)     3 LPellet Pellet          2 comb…     0
-#> # ℹ 1,262 more rows
+#>        group    phase  trial_type trial      s1      s2 block_size    type
+#>       <char>   <char>      <char> <int>  <char>  <char>      <num>  <char>
+#>    1:    CB1 training  L>(Pellet)     1 LPellet       L          2  combvs
+#>    2:    CB1 training  L>(Pellet)     1 LPellet  Pellet          2  combvs
+#>    3:    CB1 training  L>(Pellet)     1 LPellet       R          2  combvs
+#>    4:    CB1 training  L>(Pellet)     1 LPellet Sucrose          2  combvs
+#>    5:    CB1 training R>(Sucrose)     2 LPellet       L          2  combvs
+#>   ---                                                                     
+#> 1268:    CB2 training  R>(Pellet)    10       L Sucrose          2 chainvs
+#> 1269:    CB2 training  R>(Pellet)    10 Sucrose       L          2 chainvs
+#> 1270:    CB2 training  R>(Pellet)    10 Sucrose  Pellet          2 chainvs
+#> 1271:    CB2 training  R>(Pellet)    10 Sucrose       R          2 chainvs
+#> 1272:    CB2 training  R>(Pellet)    10 Sucrose Sucrose          2 chainvs
+#>       value  model
+#>       <num> <char>
+#>    1:     0 HD2022
+#>    2:     0 HD2022
+#>    3:     0 HD2022
+#>    4:     0 HD2022
+#>    5:     0 HD2022
+#>   ---             
+#> 1268:     0 HD2022
+#> 1269:     0 HD2022
+#> 1270:     0 HD2022
+#> 1271:     0 HD2022
+#> 1272:     0 HD2022
 #> 
 #> $rs
-#> # A tibble: 1,376 × 9
-#>    model  group phase    trial_type trial s1     s2      block_size value
-#>    <chr>  <chr> <chr>    <chr>      <int> <chr>  <chr>        <dbl> <dbl>
-#>  1 HD2022 CB1   training L>(Pellet)     1 L      L                2     0
-#>  2 HD2022 CB1   training L>(Pellet)     1 L      Pellet           2     0
-#>  3 HD2022 CB1   training L>(Pellet)     1 L      R                2     0
-#>  4 HD2022 CB1   training L>(Pellet)     1 L      Sucrose          2     0
-#>  5 HD2022 CB1   training L>(Pellet)     1 Pellet L                2     0
-#>  6 HD2022 CB1   training L>(Pellet)     1 Pellet Pellet           2     0
-#>  7 HD2022 CB1   training L>(Pellet)     1 Pellet R                2     0
-#>  8 HD2022 CB1   training L>(Pellet)     1 Pellet Sucrose          2     0
-#>  9 HD2022 CB1   training L>(Pellet)     1 R      L                2     0
-#> 10 HD2022 CB1   training L>(Pellet)     1 R      Pellet           2     0
-#> # ℹ 1,366 more rows
+#>        group    phase trial_type trial      s1      s2 block_size value  model
+#>       <char>   <char>     <char> <int>  <char>  <char>      <num> <num> <char>
+#>    1:    CB1 training L>(Pellet)     1       L       L          2     0 HD2022
+#>    2:    CB1 training L>(Pellet)     1       L  Pellet          2     0 HD2022
+#>    3:    CB1 training L>(Pellet)     1       L       R          2     0 HD2022
+#>    4:    CB1 training L>(Pellet)     1       L Sucrose          2     0 HD2022
+#>    5:    CB1 training L>(Pellet)     1  Pellet       L          2     0 HD2022
+#>   ---                                                                         
+#> 1372:    CB2 training R>(Pellet)    10       R Sucrose          2     0 HD2022
+#> 1373:    CB2 training R>(Pellet)    10 Sucrose       L          2     0 HD2022
+#> 1374:    CB2 training R>(Pellet)    10 Sucrose  Pellet          2     0 HD2022
+#> 1375:    CB2 training R>(Pellet)    10 Sucrose       R          2     0 HD2022
+#> 1376:    CB2 training R>(Pellet)    10 Sucrose Sucrose          2     0 HD2022
 #> 
 #> $vs
-#> # A tibble: 1,376 × 9
-#>    model  group phase    trial_type trial s1     s2      block_size value
-#>    <chr>  <chr> <chr>    <chr>      <int> <chr>  <chr>        <dbl> <dbl>
-#>  1 HD2022 CB1   training L>(Pellet)     1 L      L                2     0
-#>  2 HD2022 CB1   training L>(Pellet)     1 L      Pellet           2     0
-#>  3 HD2022 CB1   training L>(Pellet)     1 L      R                2     0
-#>  4 HD2022 CB1   training L>(Pellet)     1 L      Sucrose          2     0
-#>  5 HD2022 CB1   training L>(Pellet)     1 Pellet L                2     0
-#>  6 HD2022 CB1   training L>(Pellet)     1 Pellet Pellet           2     0
-#>  7 HD2022 CB1   training L>(Pellet)     1 Pellet R                2     0
-#>  8 HD2022 CB1   training L>(Pellet)     1 Pellet Sucrose          2     0
-#>  9 HD2022 CB1   training L>(Pellet)     1 R      L                2     0
-#> 10 HD2022 CB1   training L>(Pellet)     1 R      Pellet           2     0
-#> # ℹ 1,366 more rows
+#> group phase trial_type trial s1 s2 block_size value +#> <char> <char> <char> <int> <char> <char> <num> <num> +#> 1: CB1 training L>(Pellet) 1 L L 2 0.000000 +#> 2: CB1 training L>(Pellet) 1 L Pellet 2 0.000000 +#> 3: CB1 training L>(Pellet) 1 L R 2 0.000000 +#> 4: CB1 training L>(Pellet) 1 L Sucrose 2 0.000000 +#> 5: CB1 training L>(Pellet) 1 Pellet L 2 0.000000 +#> --- +#> 1372: CB2 training R>(Pellet) 10 R Sucrose 2 0.000000 +#> 1373: CB2 training R>(Pellet) 10 Sucrose L 2 0.368896 +#> 1374: CB2 training R>(Pellet) 10 Sucrose Pellet 2 0.000000 +#> 1375: CB2 training R>(Pellet) 10 Sucrose R 2 0.000000 +#> 1376: CB2 training R>(Pellet) 10 Sucrose Sucrose 2 0.000000 +#> model +#> <char> +#> 1: HD2022 +#> 2: HD2022 +#> 3: HD2022 +#> 4: HD2022 +#> 5: HD2022 +#> --- +#> 1372: HD2022 +#> 1373: HD2022 +#> 1374: HD2022 +#> 1375: HD2022 +#> 1376: HD2022

Although the run_experiment function returns an S4 class with many things, we only care about one of them: rs (the model responses). With them, we can write our model function.

@@ -299,18 +318,18 @@

Writing the model function # running the model and selecting rs exp_res <- run_experiment(experiment) # summarizing the model - rs <- results(exp_res)$rs %>% - filter(s2 %in% c("Pellet", "Sucrose")) %>% + rs <- results(exp_res)$rs |> + filter(s2 %in% c("Pellet", "Sucrose")) |> mutate( response = ifelse(s1 %in% c("Pellet", "Sucrose"), "np", "lp"), block = ceiling(trial / 4) - ) %>% - rowwise() %>% + ) |> + rowwise() |> # note this filter below; # we do not allow lever presses if the lever was not presented on the trial - filter(response == "np" | (response == "lp" & grepl(s1, trial_type))) %>% - mutate(us = ifelse(grepl("Pellet", trial_type), "P", "S")) %>% - group_by(block, us, response) %>% + filter(response == "np" | (response == "lp" & grepl(s1, trial_type))) |> + mutate(us = ifelse(grepl("Pellet", trial_type), "P", "S")) |> + group_by(block, us, response) |> summarise(value = mean(value), .groups = "drop") rs$value } @@ -446,13 +465,13 @@

Fitting the model
 pati_summ$prediction <- predict(the_fit, experiment = experiment)
-pati_summ %>%
-  rename("data" = "rpert") %>%
+pati_summ |>
+  rename("data" = "rpert") |>
   pivot_longer(
     cols = c("prediction", "data"),
     names_to = "type",
     values_to = "value"
-  ) %>%
+  ) |>
   ggplot(ggplot2::aes(x = block, y = value, colour = us, linetype = type)) +
   geom_line() +
   theme_bw() +
diff --git a/articles/heidi_similarity.html b/articles/heidi_similarity.html
index 9abb26b..4894dad 100644
--- a/articles/heidi_similarity.html
+++ b/articles/heidi_similarity.html
@@ -107,7 +107,6 @@ 

Victor

Plotting the similarity between saliencies @@ -166,10 +165,10 @@

Plotting the similarity betw function used to calculate the similarity calm:::.alphaSim.

-results(model)$vs %>%
-  filter(s1 == "A" & s2 == "X" & phase == "P1") %>% # using only the first phase
-  mutate(nominal_alpha = ifelse(group == "Reduced", mean(.36, .40), .40)) %>%
-  mutate(similarity = calm:::.alphaSim(value, nominal_alpha)) %>%
+results(model)$vs |>
+  filter(s1 == "A" & s2 == "X" & phase == "P1") |> # using only the first phase
+  mutate(nominal_alpha = ifelse(group == "Reduced", mean(.36, .40), .40)) |>
+  mutate(similarity = calm:::.alphaSim(value, nominal_alpha)) |>
   ggplot(aes(x = trial, y = similarity, linetype = group)) +
   geom_line() +
   theme_bw() +
@@ -179,7 +178,7 @@ 

Plotting the similarity betw

Plotting the distribution of responding

-

This one is a little bit trickier, because the figure in the +

This one is a little bit trickier because the figure in the manuscript effectively contains many experiments varying the number of XA trials before starting the first-order conditioning phase. To address this, we run multiple simulations with different experimental @@ -192,32 +191,32 @@

Plotting the distribution of re R1 = FALSE, P2 = rep(c("10(X_a)>(US)", "10(X_b)>(US)"), each = 10), R2 = FALSE, - P3 = "A#", + P3 = "1A#", R3 = FALSE ) head(df) -#> Group P1 R1 P2 R2 P3 R3 -#> 1 S1 1A(X_a) FALSE 10(X_a)>(US) FALSE A# FALSE -#> 2 S2 2A(X_a) FALSE 10(X_a)>(US) FALSE A# FALSE -#> 3 S3 3A(X_a) FALSE 10(X_a)>(US) FALSE A# FALSE -#> 4 S4 4A(X_a) FALSE 10(X_a)>(US) FALSE A# FALSE -#> 5 S5 5A(X_a) FALSE 10(X_a)>(US) FALSE A# FALSE -#> 6 S6 6A(X_a) FALSE 10(X_a)>(US) FALSE A# FALSE

+#> Group P1 R1 P2 R2 P3 R3 +#> 1 S1 1A(X_a) FALSE 10(X_a)>(US) FALSE 1A# FALSE +#> 2 S2 2A(X_a) FALSE 10(X_a)>(US) FALSE 1A# FALSE +#> 3 S3 3A(X_a) FALSE 10(X_a)>(US) FALSE 1A# FALSE +#> 4 S4 4A(X_a) FALSE 10(X_a)>(US) FALSE 1A# FALSE +#> 5 S5 5A(X_a) FALSE 10(X_a)>(US) FALSE 1A# FALSE +#> 6 S6 6A(X_a) FALSE 10(X_a)>(US) FALSE 1A# FALSE

Run the model.

 model <- run_experiment(df,
   model = "HD2022",
-  parameters = params, options = get_exp_opts()
+  parameters = params
 )

And now we can manually plot the distribution of responding among stimuli model$rs.

diff --git a/articles/parallelism_in_calm.html b/articles/parallelism_in_calm.html index a93a528..9b2bdf7 100644 --- a/articles/parallelism_in_calm.html +++ b/articles/parallelism_in_calm.html @@ -133,10 +133,11 @@

Why run things in parallel?) # set options to introduce more randomness pars <- get_parameters(pav_inhib, model = "HDI2020") -opts <- get_exp_opts(iterations = 100, miniblocks = FALSE) exp <- make_experiment(pav_inhib, parameters = pars, - model = "HDI2020", options = opts + model = "HDI2020", + iterations = 100, + miniblocks = FALSE ) # time it @@ -145,7 +146,7 @@

Why run things in parallel?end <- proc.time() - start end #> user system elapsed -#> 6.050 0.050 4.365 +#> 4.892 0.063 3.611

You can see the timings above, under the elapsed column. Let’s try parallelizing now.

@@ -167,12 +168,12 @@

Running an experiment in parallelend <- proc.time() - start end #> user system elapsed -#> 0.779 0.104 4.349 +#> 0.718 0.124 3.351 # go back to non-parallel evaluations plan(sequential)

In this case, the parallel evaluation was slower. The -future package trades off ease-of-use for bulkier +future package trades off ease of use for bulkier overheads. As those overheads tend to be constant, the parallelization will have a better payoff once you run more iterations.

diff --git a/articles/using_time_models.html b/articles/using_time_models.html index 92c0428..6bbf998 100644 --- a/articles/using_time_models.html +++ b/articles/using_time_models.html @@ -150,7 +150,7 @@

Specifying a design for time- # increase learning rates pars$alpha_reward <- 0.8 pars$alpha <- 0.08 -# increase sampling interval +# increase sampling interval to speed up the model pars$sampling_interval <- 5 pars #> $reward_magnitude @@ -256,28 +256,28 @@

Specifying a design for time- parameters = pars, model = "ANCCR" ) -head(experience(experiment)[[1]], 20) -#> group trial tp tn is_test phase block_size stimulus time reward_mag -#> 1 FN 1 3 F>T FALSE phase1 2 F 28.38458 1 -#> 2 FN 1 3 F>T FALSE phase1 2 T 29.38458 1 -#> 3 FN 2 4 T>(US) FALSE phase1 2 T 53.77464 1 -#> 4 FN 2 4 T>(US) FALSE phase1 2 US 54.77464 1 -#> 5 FN 3 4 T>(US) FALSE phase1 2 T 72.51985 1 -#> 6 FN 3 4 T>(US) FALSE phase1 2 US 73.51985 1 -#> 7 FN 4 3 F>T FALSE phase1 2 F 127.34227 1 -#> 8 FN 4 3 F>T FALSE phase1 2 T 128.34227 1 -#> 9 FN 5 4 T>(US) FALSE phase1 2 T 146.59053 1 -#> 10 FN 5 4 T>(US) FALSE phase1 2 US 147.59053 1 -#> 11 FN 6 3 F>T FALSE phase1 2 F 170.93884 1 -#> 12 FN 6 3 F>T FALSE phase1 2 T 171.93884 1 -#> 13 FN 7 4 T>(US) FALSE phase1 2 T 174.87341 1 -#> 14 FN 7 4 T>(US) FALSE phase1 2 US 175.87341 1 -#> 15 FN 8 3 F>T FALSE phase1 2 F 182.04159 1 -#> 16 FN 8 3 F>T FALSE phase1 2 T 183.04159 1 -#> 17 FN 9 3 F>T FALSE phase1 2 F 222.41382 1 -#> 18 FN 9 3 F>T FALSE phase1 2 T 223.41382 1 -#> 19 FN 10 4 T>(US) FALSE phase1 2 T 264.77391 1 -#> 20 FN 10 4 T>(US) FALSE phase1 2 US 265.77391 1

+head(experiences(experiment)[[1]], 20) +#> model group phase tp tn is_test block_size trial stimulus time reward_mag +#> 1 ANCCR FP phase1 2 T FALSE 2 1 T 7.245777 1 +#> 2 ANCCR FP phase1 1 F>T>(US) FALSE 2 2 F 23.071174 1 +#> 3 ANCCR FP phase1 1 F>T>(US) FALSE 2 2 T 24.071174 1 +#> 4 ANCCR FP phase1 1 F>T>(US) FALSE 2 2 US 25.071174 1 +#> 5 ANCCR FP phase1 1 F>T>(US) FALSE 2 3 F 44.042951 1 +#> 6 ANCCR FP phase1 1 F>T>(US) FALSE 2 3 T 45.042951 1 +#> 7 ANCCR FP phase1 1 F>T>(US) FALSE 2 3 US 46.042951 1 +#> 8 ANCCR FP phase1 2 T FALSE 2 4 T 73.128900 1 +#> 9 ANCCR FP phase1 1 F>T>(US) FALSE 2 5 F 114.533715 1 +#> 10 ANCCR FP phase1 1 F>T>(US) FALSE 2 5 T 115.533715 1 +#> 11 ANCCR FP phase1 1 F>T>(US) FALSE 2 5 US 116.533715 1 +#> 12 ANCCR FP phase1 2 T FALSE 2 6 T 198.005008 1 +#> 13 ANCCR FP phase1 2 T FALSE 2 7 T 261.247059 1 +#> 14 ANCCR FP phase1 1 F>T>(US) FALSE 2 8 F 279.902332 1 +#> 15 ANCCR FP phase1 1 F>T>(US) FALSE 2 8 T 280.902332 1 +#> 16 ANCCR FP phase1 1 F>T>(US) FALSE 2 8 US 281.902332 1 +#> 17 ANCCR FP phase1 1 F>T>(US) FALSE 2 9 F 301.809090 1 +#> 18 ANCCR FP phase1 1 F>T>(US) FALSE 2 9 T 302.809090 1 +#> 19 ANCCR FP phase1 1 F>T>(US) FALSE 2 9 US 303.809090 1 +#> 20 ANCCR FP phase1 2 T FALSE 2 10 T 311.025365 1

As you can see above, there are several rows per trial, each specifying a different stimulus. Time-based models like ANCCR run over a time log because they make ample use of the time difference between diff --git a/articles/using_time_models_files/figure-html/unnamed-chunk-6-1.png b/articles/using_time_models_files/figure-html/unnamed-chunk-6-1.png index 25377b7..be423af 100644 Binary files a/articles/using_time_models_files/figure-html/unnamed-chunk-6-1.png and b/articles/using_time_models_files/figure-html/unnamed-chunk-6-1.png differ diff --git a/articles/using_time_models_files/figure-html/unnamed-chunk-6-2.png b/articles/using_time_models_files/figure-html/unnamed-chunk-6-2.png index 2c80259..cd31685 100644 Binary files a/articles/using_time_models_files/figure-html/unnamed-chunk-6-2.png and b/articles/using_time_models_files/figure-html/unnamed-chunk-6-2.png differ diff --git a/articles/using_time_models_files/figure-html/unnamed-chunk-6-3.png b/articles/using_time_models_files/figure-html/unnamed-chunk-6-3.png index fbf4208..ee1d4ee 100644 Binary files a/articles/using_time_models_files/figure-html/unnamed-chunk-6-3.png and b/articles/using_time_models_files/figure-html/unnamed-chunk-6-3.png differ diff --git a/index.html b/index.html index 28fe489..ab010e2 100644 --- a/index.html +++ b/index.html @@ -93,19 +93,19 @@

calm

-

Canonical Associative Learning Models in R

+

Canonical Associative Learning Models

Installation

You will need devtools to install this package from github. If you do not have it, run:

install.packages("devtools")

-

Afterwards, you can install directly from this repository via:

+

Afterward, you can install directly from this repository via:

devtools::install_github("victor-navarro/calm", build_vignettes = TRUE)

If you managed to build the vignettes, there’s a vignette showing the basics of the package in

vignette("calm_basics", package = "calm")

-

If you just want to do some quick simulating, launch the visual interface via:

-
library(calm)
-app()
+

If you want to do some simulations using the companion app, you must install the calm.app package and then launch the app.

+
devtools::install_github("victor-navarro/calm.app")
+calm.app::launch_app()

Try the online Shiny app diff --git a/pkgdown.yml b/pkgdown.yml index 3d0f6cb..7bb695b 100644 --- a/pkgdown.yml +++ b/pkgdown.yml @@ -15,7 +15,7 @@ articles: heidi_similarity: heidi_similarity.html parallelism_in_calm: parallelism_in_calm.html using_time_models: using_time_models.html -last_built: 2024-03-07T22:05Z +last_built: 2024-03-10T11:50Z urls: reference: https://victornavarro.org/calm/reference article: https://victornavarro.org/calm/articles diff --git a/reference/CalmDesign-class.html b/reference/CalmDesign-class.html index 7746731..90178cb 100644 --- a/reference/CalmDesign-class.html +++ b/reference/CalmDesign-class.html @@ -1,5 +1,5 @@ -S4 class for Calm designs — CalmDesign-class • calmS4 class for Calm designs — CalmDesign-class • calm @@ -67,7 +67,7 @@

-

Inherits from the tbl class

+

S4 class for Calm designs

@@ -76,7 +76,7 @@

Slots

design:
-

A tbl containing the object.

+

A list containing design information.

mapping:

A list containing the object mapping.

diff --git a/reference/CalmExperiment-methods.html b/reference/CalmExperiment-methods.html index e75491f..b572f78 100644 --- a/reference/CalmExperiment-methods.html +++ b/reference/CalmExperiment-methods.html @@ -79,10 +79,7 @@

Usage design(x) # S4 method for CalmExperiment -arguments(x) - -# S4 method for CalmExperiment -c(x, ..., recursive = FALSE) +trials(object) parameters(x) <- value @@ -92,13 +89,8 @@

Usage # S4 method for CalmExperiment parameters(x) <- value -experience(x) <- value - # S4 method for CalmExperiment -experience(x) - -# S4 method for CalmExperiment -experience(x) <- value +experiences(x) # S4 method for CalmExperiment results(object) @@ -121,25 +113,30 @@

Usage aggregate(x, ...) # S4 method for CalmExperiment -plot(x, type = NULL, ...) +plot(x, type = NULL, ...) + +graph(x, ...) + +# S4 method for CalmExperiment +graph(x, ...)

Arguments

-
x
-

An object of class CalmExperiment-class.

+
object
+

A CalmExperiment object

-
...
-

Objects to concatenate

+
x
+

A CalmExperiment

-
recursive
-

Unused

+
value
+

A list of parameter lists.

-
value
-

A list of experiences.

+
...
+

Additional parameters passed to graph_calm_model

type
@@ -158,27 +155,6 @@

Note

With type = NULL, all supported plots are returned.

-
-

Examples

-
# Concatenate experiments
-df <- get_design("blocking")
-mods <- c("RW1972", "MAC1975")
-exs <- lapply(mods, function(m) {
-  make_experiment(df, parameters = get_parameters(df, model = m), model = m)
-})
-# joining separate experiments
-c(exs[[1]], exs[[2]])
-#> # A tibble: 4 × 6
-#>   iteration model   group    experience    mapping           parameters      
-#>       <int> <chr>   <chr>    <list>        <list>            <list>          
-#> 1         1 RW1972  Blocking <df [21 × 7]> <named list [12]> <named list [4]>
-#> 2         1 RW1972  Control  <df [11 × 7]> <named list [12]> <named list [4]>
-#> 3         1 MAC1975 Blocking <df [21 × 7]> <named list [12]> <named list [8]>
-#> 4         1 MAC1975 Control  <df [11 × 7]> <named list [12]> <named list [8]>
-# joining a list of experiments
-joint <- do.call(c, exs)
-
-
diff --git a/reference/CalmExperiment.html b/reference/CalmExperiment.html index efcf2c9..dbb435b 100644 --- a/reference/CalmExperiment.html +++ b/reference/CalmExperiment.html @@ -75,15 +75,33 @@

Slots

-
arguments:
-

A tbl containing arguments to run models.

- -
design:
+
design:

A CalmDesign object.

+
model:
+

A string specifying the model used.

+ +
groups:
+

A string specifying the groups in the design.

+ +
parameters:
+

A list with the parameters used, per group.

+ +
experiences:
+

A list with the experiences for the model.

+
results:

A CalmExperimentResult object.

+
.model:
+

Internal. The model associated with the iteration.

+ +
.group:
+

Internal. The group associated with the iteration.

+ +
.iter:
+

Internal. The iteration number.

+
diff --git a/reference/CalmFit-methods.html b/reference/CalmFit-methods.html index 096dfc9..aba441c 100644 --- a/reference/CalmFit-methods.html +++ b/reference/CalmFit-methods.html @@ -1,5 +1,7 @@ -CalmFit Methods — show,CalmFit-method • calmCalmFit Methods — show,CalmFit-method • calm @@ -68,6 +70,7 @@

CalmFit Methods

+

CalmFit methods

@@ -81,6 +84,9 @@

Usage NLL(object) # S4 method for CalmFit +NLL(object) + +# S4 method for CalmFit AIC(object, k = 2) # S4 method for CalmFit @@ -97,6 +103,10 @@

ArgumentsSlots

distances:

List. Pairwise distance matrices

-
arguments:
+
args:

List. Arguments used to create the object.

test_data:
diff --git a/reference/CalmRSA-methods.html b/reference/CalmRSA-methods.html index 77a5019..a8505a4 100644 --- a/reference/CalmRSA-methods.html +++ b/reference/CalmRSA-methods.html @@ -1,5 +1,7 @@ -CalmRSA Methods — show,CalmRSA-method • calmCalmRSA Methods — show,CalmRSA-method • calm @@ -68,12 +70,21 @@

CalmRSA Methods

+

Test CalmRSA object via permutation test

Usage

# S4 method for CalmRSA
-show(object)
+show(object) + +test(object, n_samples = 1000, p = 0.95) + +# S4 method for CalmRSA +test(object, n_samples = 1000, p = 0.95) + +# S4 method for CalmRSA +plot(x, y, ...)
@@ -81,7 +92,35 @@

Arguments +

Value

+ + +

A CalmRSA object with the test results

+

diff --git a/reference/CalmResult-methods.html b/reference/CalmResult-methods.html index 829bc7e..81ce0f8 100644 --- a/reference/CalmResult-methods.html +++ b/reference/CalmResult-methods.html @@ -73,10 +73,7 @@

Usage

# S4 method for CalmResult
-show(object)
-
-# S4 method for CalmExperimentResult
-c(x, ..., recursive = FALSE)
+show(object)
@@ -84,18 +81,6 @@

Arguments
-

Test CalmRSA object via permutation test

+

Perform representational similarity analysis on CalmExperiment

Usage

-
# S4 method for CalmRSA
-test(object, n_samples = 1000, p = 0.95)
-
-# S4 method for CalmRSA
-plot(x, y, ...)
+
rsa(x, comparisons, test = FALSE, ...)

Arguments

-
object
-

A CalmRSA object

+
x
+

A list of CalmExperiment objects

-
n_samples
-

The number of samples for the permutation test -(default = 1e3)

+
comparisons
+

A model-named list containing the model +outputs to compare.

-
p
-

The critical threshold level for the permutation test -(default = 0.95)

+
test
+

Whether to test the RSA via permutation test. Default = FALSE.

...
-

Extra parameters passed to the plot call

+

Additional parameters passed to stats::dist +and stats::cor

Value

-

A CalmRSA object with the test results

+

A CalmRSA object

+
+
+

Note

+

The object returned by this function +can be later tested via its own test method.

+
+

Examples

+
# Comparing the associations in three models
+exp <- data.frame(
+  Group = c("A", "B"),
+  P1 = c("2(A)>(US)/1B>(US)", "1(A)>(US)/2B>(US)"),
+  R1 = TRUE
+)
+models <- c("HD2022", "RW1972", "PKH1982")
+parameters <- sapply(models, get_parameters, design = exp)
+exp_res <- compare_models(exp,
+  models = models
+)
+comparisons <- list(
+  "HD2022" = c("vs"),
+  "RW1972" = c("vs"),
+  "PKH1982" = c("eivs")
+)
+res <- rsa(exp_res, comparisons = comparisons)
+test(res, n_samples = 100)
+#> CalmRSA object
+#> ---------------
+#> Correlation matrix:
+#>               HD2022.vs RW1972.vs PKH1982.eivs
+#> HD2022.vs     1.0000000 0.3022383   -0.9178532
+#> RW1972.vs     0.3022383 1.0000000    0.1009465
+#> PKH1982.eivs -0.9178532 0.1009465    1.0000000
+#> 
+#> Significance matrix:
+#> 
+#>              HD2022.vs RW1972.vs PKH1982.eivs
+#> HD2022.vs        FALSE     FALSE        FALSE
+#> RW1972.vs        FALSE     FALSE        FALSE
+#> PKH1982.eivs     FALSE     FALSE        FALSE
+#> 
+#> 100 permutation samples, two-tailed test with alpha = 0.05.
+
+
diff --git a/reference/calm_model_plot.html b/reference/calm_model_plot.html index 7277e13..9db9c5b 100644 --- a/reference/calm_model_plot.html +++ b/reference/calm_model_plot.html @@ -78,7 +78,7 @@

Usage

Arguments

dat
-

A tbl with data to use in the plot

+

A data.frame-like with data to use in the plot

type
diff --git a/reference/compare_models.html b/reference/compare_models.html index 25addc3..0b59146 100644 --- a/reference/compare_models.html +++ b/reference/compare_models.html @@ -72,48 +72,46 @@

Usage

-
compare_models(design, models, parameters = NULL, options = NULL)
+
compare_models(x, models = NULL, ...)

Arguments

-
design
-

A design data.frame or CalmDesign

+
x
+

A list of CalmExperiment objects or a design data.frame

models
-

A character vector of length m, specifying the models to run.

+

A character vector of length m, specifying the models to run. +Ignored if x is a list of CalmExperiment objects.

-
parameters
-

A list of length m, -with each entry containing a list with model parameters, -as returned by get_parameters

- - -
options
-

A list of options, as returned by get_exp_opts.

+
...
+

Arguments passed to make_experiment

Value

-

A CalmExperiment object

+

A list of CalmExperiment objects

Examples

-
exp <- data.frame(
-  Group = c("A", "B"),
-  P1 = c("10(A)>(US)/5B>(US)", "5(A)>(US)/10B>(US)"),
-  R1 = TRUE
-)
-exp <- parse_design(exp)
+    
# By making experiment beforehand (recommended)
+df <- get_design("blocking")
 models <- c("HD2022", "RW1972", "PKH1982")
-parameters <- sapply(models, get_parameters, design = exp)
-comp <- compare_models(exp, models = models, parameters = parameters)
-#> Warning: No experiment options passed. Using default options.
+exps <- lapply(models, function(m) {
+  make_experiment(df,
+    parameters = get_parameters(df, model = m),
+    model = m
+  )
+})
+comp <- compare_models(exps)
+
+# By passing minimal arguments (not recommended; default parameters)
+comp <- compare_models(df, models = models)
 

Arguments

x
-

A CalmExperiment

+

A data.frame-like with data to use in the plot

loops
@@ -118,7 +112,7 @@

ArgumentsAll functionsshow(<CalmExperiment>) design(<CalmExperiment>) arguments(<CalmExperiment>) c(<CalmExperiment>) `parameters<-`() parameters(<CalmExperiment>) `experience<-`() experience(<CalmExperiment>) results(<CalmExperiment>) raw_results(<CalmExperiment>) parsed_results(<CalmExperiment>) length(<CalmExperiment>) parse() aggregate(<CalmExperiment>) plot(<CalmExperiment>) + show(<CalmExperiment>) design(<CalmExperiment>) trials(<CalmExperiment>) `parameters<-`() parameters(<CalmExperiment>) experiences(<CalmExperiment>) results(<CalmExperiment>) raw_results(<CalmExperiment>) parsed_results(<CalmExperiment>) length(<CalmExperiment>) parse() aggregate(<CalmExperiment>) plot(<CalmExperiment>) graph()
CalmExperiment methods

@@ -122,12 +122,12 @@

All functionsshow(<CalmRSA>) + show(<CalmRSA>) test() plot(<CalmRSA>)

CalmRSA Methods
- show(<CalmResult>) c(<CalmExperimentResult>) + show(<CalmResult>)
Methods for CalmResult
@@ -162,9 +162,9 @@

All functionstest(<CalmRSA>) plot(<CalmRSA>) + rsa()

-
Test CalmRSA object via permutation test
+
Perform representational similarity analysis on CalmExperiment
RW1972() @@ -177,11 +177,6 @@

All functionsapp() -

-
Run the calm shiny application
-
- calm_model_plot()
Create a plot with calm data
@@ -207,11 +202,6 @@

All functionsget_exp_opts() - -
Get options for an experiment
-

- get_graph_opts()
Get options for calm graph
@@ -227,7 +217,7 @@

All functionscalm_model_graph() graph(<CalmExperiment>) + calm_model_graph()
Create a graph with calm data

@@ -267,11 +257,6 @@

All functionsrsa(<CalmExperiment>) -

-
Perform representational similarity analysis on CalmExperiment
-
- run_experiment()
Run experiment
diff --git a/reference/make_experiment.html b/reference/make_experiment.html index 4b6ee74..3594162 100644 --- a/reference/make_experiment.html +++ b/reference/make_experiment.html @@ -79,7 +79,8 @@

Usage design, parameters = NULL, model = NULL, - options = get_exp_opts(), + iterations = 1, + miniblocks = TRUE, .callback_fn = NULL, ... )

@@ -100,8 +101,12 @@

Argumentssupported_models()

-
options
-

A list with options as returned by get_exp_opts

+
iterations
+

An integer specifying the number of iterations per group.

+ + +
miniblocks
+

Whether to organize trials in miniblocks.

.callback_fn
@@ -117,27 +122,44 @@

Value

A CalmExperiment object

+
+
+

Note

+

The miniblocks option will direct the sampling function to create +equally-sized miniblocks with random trials within a phase. +For example, the phase string "2A/2B" will create two miniblocks +with one of each trial. The phase string "2A/4B" will create two miniblocks +with one A trial, and 2 B trials. However, the phase string "2A/1B" will +not result in miniblocks, even if miniblocks here is set to TRUE.

Examples

des <- data.frame(Group = "G1", P1 = "10A>(US)", R1 = TRUE)
 ps <- get_parameters(des, model = "HD2022")
-op <- get_exp_opts(miniblocks = TRUE, iterations = 2)
 make_experiment(
   design = des, parameters = ps,
-  model = "HD2022", options = op
+  model = "HD2022", iterations = 2
 )
-#> # A tibble: 2 × 6
-#>   iteration model  group experience    mapping           parameters      
-#>       <int> <chr>  <chr> <list>        <list>            <list>          
-#> 1         1 HD2022 G1    <df [10 × 7]> <named list [12]> <named list [1]>
-#> 2         2 HD2022 G1    <df [10 × 7]> <named list [12]> <named list [1]>
+#> -----------------------------
+#> CalmExperiment with model:
+#> HD2022 
+#> -----------------------------
+#> For design:
+#>   Group       P1   R1
+#> 1    G1 10A>(US) TRUE
+#> -----------------------------
+#> With parameters:
+#> $G1
+#> $G1$alphas
+#>   A  US 
+#> 0.4 0.4 
+#> 
+#> 
 
 
diff --git a/reference/parse_design.html b/reference/parse_design.html index ba6dfeb..bf19ade 100644 --- a/reference/parse_design.html +++ b/reference/parse_design.html @@ -113,11 +113,15 @@

Examples P1 = c("10AB(US)", "10A(US)"), R1 = c(TRUE, TRUE) ) parse_design(df) -#> # A tibble: 2 × 5 -#> group phase parse_string randomize phase_info -#> <chr> <chr> <chr> <lgl> <list> -#> 1 Group 1 P1 10AB(US) TRUE <named list [2]> -#> 2 Group 2 P1 10A(US) TRUE <named list [2]> +#> CalmDesign built from data.frame: +#> Group P1 R1 +#> 1 Group 1 10AB(US) TRUE +#> 2 Group 2 10A(US) TRUE +#> ---------------- +#> Trials detected: +#> group phase trial_names trial_repeats is_test stimuli +#> 1 Group 1 P1 AB(US) 10 FALSE A;B;US +#> 2 Group 2 P1 A(US) 10 FALSE A;US