-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 @@
We now prepare the arguments for the model function (as you would
pass to run_experiment
experiment.
-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 @@
-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