-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sequence #83
Open
behinger
wants to merge
40
commits into
main
Choose a base branch
from
sequence
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
sequence #83
Changes from all commits
Commits
Show all changes
40 commits
Select commit
Hold shift + click to select a range
8405a1a
FormulaOnsets
behinger afc69d7
initial sequence tryout
behinger 49db0ba
fix bug in predef_eeg
behinger 8e6de75
merge
behinger cd489c4
forgot the end
behinger 6c35f3c
half way through to success for sequence designs or something
behinger 809dc2e
everythinig except sequencelength seems to be working now
behinger 31c69e6
added string sequence tests
behinger 54e9334
small doc update
behinger 7114cd6
added jitter to the '_' trial divisor
behinger 85f037b
Improve documentation especially quickstart, home and power analysis
jschepers 2c65a7f
adapted the order of reference overviews and adapted titles
jschepers ee9e00a
Updated quickstart page
jschepers ac0d3bd
minor changes
jschepers 373e535
fixed docstrings for predef_eeg and predef_2x2
jschepers b073526
added draft of design types reference page
jschepers 89c09a1
Update quickstart.jl
behinger 1e2694f
Add UnfoldSim logo to the documentation
jschepers 9ab04aa
Finished experimental design reference page
jschepers 5671e2e
Replace logo file
jschepers 10c77a3
Update logo file
jschepers ea25ddc
Delete docs/src/assets/logo.svg
jschepers e0c2310
Add logo as png file
jschepers 34ce887
Added intro paragraph for Simulate ERP tutorial
jschepers b5a60bf
Improved docstrings for single- and multi-subject design
jschepers b81b605
Fixed simulate docstring
jschepers 369faff
Added cross references in docstrings
jschepers 541cf67
Added intro sentences, matched titles and sidebar, reordered pages an…
jschepers f449083
Update noise.jl
behinger fe00ec2
Update src/noise.jl
behinger f93a3c1
Update src/noise.jl
behinger aca3fd2
Update src/noise.jl
jschepers e868a14
add empty line for formatting reasons
jschepers 43dd57c
Update docs/literate/reference/noisetypes.jl
jschepers 68ce722
Update docs/literate/reference/overview.jl
jschepers 2dfd44b
Update docs/literate/reference/overview.jl
jschepers 2c34e5e
Update docs/literate/reference/noisetypes.jl
jschepers 8848209
Merge branch 'main' into sequence
behinger 9749685
merge joss doc changes
behinger 3a3bd3d
added docstring
behinger File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
using Base: add_sum | ||
using UnfoldSim | ||
using CairoMakie | ||
using StableRNGs | ||
|
||
# ## Stimulus - Response design | ||
|
||
# Let's say we want to simulate a stimulus response, followed by a button press response. | ||
# | ||
# First we generate the minimal design of the experiment by specifying our conditins (a one-condition-two-levels design in our case) | ||
design = SingleSubjectDesign(conditions = Dict(:condition => ["one", "two"])) | ||
generate_events(design) | ||
# Next we use the `SequenceDesign` and nest our initial design in it. "`SR_`" is code for an "`S`" event and an "`R`" event - only single letter events are supported! The "`_`" is a signal for the Onset generator to generate a bigger pause - no overlap between adjacend "`SR`" pairs | ||
design = SequenceDesign(design, "SR_", StableRNG(1)) | ||
generate_events(design) | ||
# The main thing that happened is that the design was repeated for every event (each 'letter') of the sequence, and an `eventtype` column was added. | ||
# !!! hint | ||
# more advaned sequences are possible as well, like "SR{1,3}", or "A[BC]". Infinite sequences are **not** possible like "AB*" | ||
|
||
# Finally, let's repeat the current design 4 times | ||
design = RepeatDesign(design, 4) | ||
generate_events(design) | ||
|
||
#design = UnfoldSim.AddSaccadeAmplitudeDesign4(design,:rt,Normal(0,1),MersenneTwister(1)) | ||
#generate_events(design) | ||
|
||
|
||
# This results in 16 trials that nicely follow our sequence | ||
|
||
# Next we have to specify for both events `S` and `R` what the responses should look like. | ||
p1 = LinearModelComponent(; | ||
basis = p100(), | ||
formula = @formula(0 ~ 1 + condition), | ||
β = [1, 0.5], | ||
) | ||
|
||
n1 = LinearModelComponent(; | ||
basis = n170(), | ||
formula = @formula(0 ~ 1 + condition), | ||
β = [1, 0.5], | ||
) | ||
|
||
p3 = LinearModelComponent(; | ||
basis = UnfoldSim.hanning(Int(0.5 * 100)), # sfreq = 100 for the other bases | ||
formula = @formula(0 ~ 1 + condition), | ||
β = [1, 0], | ||
) | ||
|
||
resp = LinearModelComponent(; | ||
basis = UnfoldSim.hanning(Int(0.5 * 100)), # sfreq = 100 for the other bases | ||
formula = @formula(0 ~ 1 + condition), | ||
β = [1, 2], | ||
offset = -10, | ||
) | ||
nothing ## hide | ||
|
||
|
||
# We combine them into a dictionary with a sequence-`Char` as key and simulate | ||
components = Dict('S' => [p1, n1, p3], 'R' => [resp]) | ||
|
||
data, evts = simulate( | ||
StableRNG(1), | ||
design, | ||
components, | ||
UniformOnset(offset = 40, width = 10), | ||
NoNoise(), | ||
) | ||
nothing ## hide | ||
|
||
# Finally we can plot the results | ||
lines(data) | ||
vlines!(evts.latency[evts.event.=='S'], color = (:darkblue, 0.5)) | ||
vlines!(evts.latency[evts.event.=='R'], color = (:darkred, 0.5)) | ||
xlims!(0, 500) | ||
current_figure() | ||
|
||
# As visible, the `R` response always follows the `S` response. Due to the "`_`" we have large breaks between the individual sequences. | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
# # 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 | ||
# ```@raw html | ||
# <details> | ||
# <summary>Click to expand</summary> | ||
# ``` | ||
## Load required packages | ||
using UnfoldSim | ||
using Random | ||
# ```@raw html | ||
# </details > | ||
# ``` | ||
|
||
# ## 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) | ||
|
||
# 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 = x -> shuffle(MersenneTwister(42), x), | ||
); | ||
# ```@raw html | ||
# <details> | ||
# <summary>Click to expand event table </summary> | ||
# ``` | ||
generate_events(design_single_shuffled) | ||
# ```@raw html | ||
# </details > | ||
# ``` | ||
|
||
# ## 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](https://github.com/RePsychLing/MixedModelsSim.jl). | ||
# 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)), | ||
); | ||
|
||
# ```@raw html | ||
# <details> | ||
# <summary>Click to expand event table </summary> | ||
# ``` | ||
generate_events(design_multi) | ||
# ```@raw html | ||
# </details > | ||
# <br /> | ||
# ``` | ||
|
||
# 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: | ||
# ```@raw html | ||
# <details> | ||
# <summary>Click to expand event table </summary> | ||
# ``` | ||
generate_events(design_single) | ||
# ```@raw html | ||
# </details > | ||
# <br /> | ||
# ``` | ||
|
||
|
||
# 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) | ||
|
||
# [Here](@ref howto_repeat_design) one can find another example of how to repeat design entries for multi-subject designs. |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[JuliaFormatter] reported by reviewdog 🐶