Overview: Experimental design types

The experimental design specifies the experimental conditions and other variables that are supposed to have an influence on the simulated data. Currently, there are three types of designs implemented: SingleSubjectDesign, MultiSubjectDesign and RepeatDesign.

Setup

Click to expand
# Load required packages
using UnfoldSim
using Random

Single-subject designs

As the name suggests, the SingleSubjectDesign type can be used to specify the experimental design for a single subject. Using the conditions arguments, the user can specify all relevant conditions or predictors and their levels or value range.

The current implementation assumes a full factorial design (also called fully crossed design) in which each level of a factor occurs with each level of the other factors. Moreover, in the current implementation, there is exactly one instance of each of these factor combinations.

Example:

design_single = SingleSubjectDesign(;
    conditions = Dict(
        :stimulus_type => ["natural", "artificial"],
        :contrast_level => range(0, 1, length = 3),
    ),
);

In order to inspect the design, we can use the generate_events function to create an event table based on the design we specified.

generate_events(design_single)
6×2 DataFrame
Rowcontrast_levelstimulus_type
Float64String
10.0natural
20.5natural
31.0natural
40.0artificial
50.5artificial
61.0artificial

To change the order of the trials e.g. to sort or shuffle them, one can use the event_order_function argument. Example: Randomize the order of trials

design_single_shuffled = SingleSubjectDesign(;
    conditions = Dict(
        :stimulus_type => ["natural", "artificial"],
        :contrast_level => range(0, 1, length = 3),
    ),
    event_order_function = shuffle,
);
Click to expand event table
generate_events(design_single_shuffled)
6×2 DataFrame
Rowcontrast_levelstimulus_type
Float64String
11.0artificial
20.5natural
30.0artificial
40.0natural
51.0natural
60.5artificial

Multi-subject designs

The MultiSubjectDesign type can be used to simulate data for an experiment with multiple subjects. Internally, it uses the MixedModelsSim.jl package. One needs to specify the number of subjects n_subjects and the number of items n_items i.e. stimuli. In addition, one needs to decide for every experimental factor whether it should be between- or within-subject (and item).

Note

For factors that are not listed in items_between it is assumed that they vary within-item (accordingly for subjects_between).

design_multi = MultiSubjectDesign(
    n_subjects = 6,
    n_items = 4,
    items_between = Dict(:colour => ["red", "blue"]),
    subjects_between = Dict(:age_group => ["young", "old"]),
    both_within = Dict(:luminance => range(0, 1, length = 3)),
);
Click to expand event table
generate_events(design_multi)
72×5 DataFrame
Rowsubjectage_groupitemcolourluminance
StringStringStringStringFloat64
1S1youngI1red0.0
2S1youngI2blue0.0
3S1youngI3red0.0
4S1youngI4blue0.0
5S1youngI1red0.5
6S1youngI2blue0.5
7S1youngI3red0.5
8S1youngI4blue0.5
9S1youngI1red1.0
10S1youngI2blue1.0
11S1youngI3red1.0
12S1youngI4blue1.0
13S2oldI1red0.0
14S2oldI2blue0.0
15S2oldI3red0.0
16S2oldI4blue0.0
17S2oldI1red0.5
18S2oldI2blue0.5
19S2oldI3red0.5
20S2oldI4blue0.5
21S2oldI1red1.0
22S2oldI2blue1.0
23S2oldI3red1.0
24S2oldI4blue1.0
25S3youngI1red0.0
26S3youngI2blue0.0
27S3youngI3red0.0
28S3youngI4blue0.0
29S3youngI1red0.5
30S3youngI2blue0.5
31S3youngI3red0.5
32S3youngI4blue0.5
33S3youngI1red1.0
34S3youngI2blue1.0
35S3youngI3red1.0
36S3youngI4blue1.0
37S4oldI1red0.0
38S4oldI2blue0.0
39S4oldI3red0.0
40S4oldI4blue0.0
41S4oldI1red0.5
42S4oldI2blue0.5
43S4oldI3red0.5
44S4oldI4blue0.5
45S4oldI1red1.0
46S4oldI2blue1.0
47S4oldI3red1.0
48S4oldI4blue1.0
49S5youngI1red0.0
50S5youngI2blue0.0
51S5youngI3red0.0
52S5youngI4blue0.0
53S5youngI1red0.5
54S5youngI2blue0.5
55S5youngI3red0.5
56S5youngI4blue0.5
57S5youngI1red1.0
58S5youngI2blue1.0
59S5youngI3red1.0
60S5youngI4blue1.0
61S6oldI1red0.0
62S6oldI2blue0.0
63S6oldI3red0.0
64S6oldI4blue0.0
65S6oldI1red0.5
66S6oldI2blue0.5
67S6oldI3red0.5
68S6oldI4blue0.5
69S6oldI1red1.0
70S6oldI2blue1.0
71S6oldI3red1.0
72S6oldI4blue1.0

As with the SingleSubjectDesign one can use the event_order_function argument to determine the order of events/trials.

Important

The number of subjects/items has to be a divisor of the number of factor level combinations, i.e. it is assumed that the design is balanced which means that there is an equal number of observations for all possible factor level combinations.

Repeat designs

The RepeatDesign type is a functionality to encapsulate single- or multi-subject designs. It allows to repeat a generated event table multiple times. In other words, the RepeatDesign type allows to have multiple instances of the same item/subject/factor level combination.

Example: Assume, we have the following single-subject design from above:

Click to expand event table
generate_events(design_single)
6×2 DataFrame
Rowcontrast_levelstimulus_type
Float64String
10.0natural
20.5natural
31.0natural
40.0artificial
50.5artificial
61.0artificial

But instead of having only one instance of the factor combinations e.g. stimulus_type: natural and contrast_level: 0, we will repeat the design three times such that there are three occurrences of each combination.

design_repeated = RepeatDesign(design_single, 3);
generate_events(design_repeated)
18×2 DataFrame
Rowcontrast_levelstimulus_type
Float64String
10.0natural
20.5natural
31.0natural
40.0artificial
50.5artificial
61.0artificial
70.0natural
80.5natural
91.0natural
100.0artificial
110.5artificial
121.0artificial
130.0natural
140.5natural
151.0natural
160.0artificial
170.5artificial
181.0artificial

Here one can find another example of how to repeat design entries for multi-subject designs.


This page was generated using Literate.jl.