diff --git a/dev/.documenter-siteinfo.json b/dev/.documenter-siteinfo.json index 5972daf..e3c8e92 100644 --- a/dev/.documenter-siteinfo.json +++ b/dev/.documenter-siteinfo.json @@ -1 +1 @@ -{"documenter":{"julia_version":"1.10.1","generation_timestamp":"2024-02-16T16:55:25","documenter_version":"1.2.1"}} \ No newline at end of file +{"documenter":{"julia_version":"1.10.1","generation_timestamp":"2024-02-19T15:07:34","documenter_version":"1.2.1"}} \ No newline at end of file diff --git a/dev/api/index.html b/dev/api/index.html index 4927822..1ffacca 100644 --- a/dev/api/index.html +++ b/dev/api/index.html @@ -5,26 +5,26 @@ β = [1.,2.], contrasts=Dict(:cond=>EffectsCoding()) ) -source
UnfoldSim.MixedModelComponentType

A component that adds a hierarchical relation between parameters according to a LMM defined via MixedModels.jl

  • basis: an object, if accessed, provides a 'basis-function', e.g. hanning(40), this defines the response at a single event. It will be weighted by the model-prediction
  • formula: Formula-Object in the style of MixedModels.jl e.g. @formula 0~1+cond + (1|subject) - left-handside is ignored
  • β Vector of betas, must fit the formula
  • σs Dict of random effect variances, e.g. Dict(:subject=>[0.5,0.4]) or to specify correlationmatrix Dict(:subject=>[0.5,0.4,I(2,2)],...). Technically, this will be passed to MixedModels.jl create_re function, which creates the θ matrices.
  • contrasts: Dict in the style of MixedModels.jl. Default is empty.

All arguments can be named, in that case contrasts is optional

Works best with MultiSubjectDesign

MixedModelComponent(;
+
source
UnfoldSim.MixedModelComponentType

A component that adds a hierarchical relation between parameters according to a LMM defined via MixedModels.jl

  • basis: an object, if accessed, provides a 'basis-function', e.g. hanning(40), this defines the response at a single event. It will be weighted by the model-prediction
  • formula: Formula-Object in the style of MixedModels.jl e.g. @formula 0~1+cond + (1|subject) - left-handside is ignored
  • β Vector of betas, must fit the formula
  • σs Dict of random effect variances, e.g. Dict(:subject=>[0.5,0.4]) or to specify correlationmatrix Dict(:subject=>[0.5,0.4,I(2,2)],...). Technically, this will be passed to MixedModels.jl create_re function, which creates the θ matrices.
  • contrasts: Dict in the style of MixedModels.jl. Default is empty.

All arguments can be named, in that case contrasts is optional

Works best with MultiSubjectDesign

MixedModelComponent(;
     basis=hanning(40),
     formula=@formula(0~1+cond+(1+cond|subject)),
     β = [1.,2.],
     σs= Dict(:subject=>[0.5,0.4]),
     contrasts=Dict(:cond=>EffectsCoding())
 )
-
source
UnfoldSim.MultiSubjectDesignType
  • n_subjects::Int -> number of subjects
  • n_items::Int -> number of items (sometimes ≈trials)
  • subjects_between = nothing -> effects between subjects, e.g. young vs old
  • items_between = nothing -> effects between items, e.g. natural vs artificial images, but shown to all subjects
  • both_within = nothing -> effects completly crossed
  • eventorderfunction = x->x; # can be used to sort, or x->shuffle(MersenneTwister(42),x) - be sure to fix/update the rng accordingly!!

tipp: check the resulting dataframe using generate_events(design)

# declaring same condition both sub-between and item-between results in a full between subject/item design
+
source
UnfoldSim.MultiSubjectDesignType
  • n_subjects::Int -> number of subjects
  • n_items::Int -> number of items (sometimes ≈trials)
  • subjects_between = nothing -> effects between subjects, e.g. young vs old
  • items_between = nothing -> effects between items, e.g. natural vs artificial images, but shown to all subjects
  • both_within = nothing -> effects completly crossed
  • eventorderfunction = x->x; # can be used to sort, or x->shuffle(MersenneTwister(42),x) - be sure to fix/update the rng accordingly!!

tipp: check the resulting dataframe using generate_events(design)

# declaring same condition both sub-between and item-between results in a full between subject/item design
 design = MultiSubjectDesign(;
 		n_items = 10,
 		n_subjects = 30,
 		subjects_between = Dict(:cond => ["levelA", "levelB"]),
 		items_between = Dict(:cond => ["levelA", "levelB"]),
-		);
source
UnfoldSim.MultichannelComponentType

Wrapper for an AbstractComponent to project it to multiple target-channels via projection. optional adds noise to the source prior to projection.

source
UnfoldSim.RepeatDesignType

repeat a design DataFrame multiple times to mimick repeatedly recorded trials

designOnce = MultiSubjectDesign(;
+		);
source
UnfoldSim.MultichannelComponentType

Wrapper for an AbstractComponent to project it to multiple target-channels via projection. optional adds noise to the source prior to projection.

source
UnfoldSim.RepeatDesignType

repeat a design DataFrame multiple times to mimick repeatedly recorded trials

designOnce = MultiSubjectDesign(;
 		n_items=2,
 		n_subjects = 2,
 		subjects_between =Dict(:cond=>["levelA","levelB"]),
 		items_between =Dict(:cond=>["levelA","levelB"]),
 		);
 
-design = RepeatDesign(designOnce,4);
source
UnfoldSim.SingleSubjectDesignType
  • conditions = Dict of conditions, e.g. Dict(:A=>["a_small","a_big"],:B=>["b_tiny","b_large"])
  • eventorderfunction = x->x; # can be used to sort, or x->shuffle(MersenneTwister(42),x) - be sure to fix/update the rng accordingly!!

Number of trials / rows in generate_events(design) depend on the full factorial of your conditions.

To increase the number of repetitions simply use RepeatDesign(SingleSubjectDesign(...),5)

If conditions are omitted (or set to nothing), a single trial is simulated with a column :dummy and content :dummy - this is for convenience.

tipp: check the resulting dataframe using generate_events(design)

source
Base.sizeMethod

Returns dimension of experiment design

source
DSP.Windows.hanningMethod

generate a hanning window

duration: in s offset: in s, defines hanning peak sfreq: sampling rate in Hz

source
UnfoldSim.add_noise!Method

Generate and add noise to the data-matrix

Assumes that the signal can be linearized, that is, that the noise is stationary

source
UnfoldSim.add_responses!Method

Helper function to add inplace the responses to the signal, but for both 2D (1 channel) and 3D (X channel case)

source
UnfoldSim.closest_srcMethod
closest_src(coords_list::AbstractVector{<:AbstractVector}, pos)
-closest_src(coords::Vector{<:Real}, pos)

Takes an array of 'm' target coordinate vector (size 3) (or vector of vectors) and a matrix (n-by-3) of all available positions, and returns an array of size 'm' containing the indices of the respective items in 'pos' that are nearest to each of the target coordinates.

source
UnfoldSim.closest_srcMethod
closest_src(head::Hartmut,label::String)

Returns src-ix of the Headmodel Hartmut which is closest to the average of the label.

Important

We use the average in eucledean space, but the cortex is a curved surface. In most cases they will not overlap. Ideally we would calculate the average on the surface, but this is a bit more complex to do (you'd need to calculate the vertices etc.)

hartmut = headmodel()
-pos = closest_src(hartmut=>"Left Middle Temporal Gyrus, posterior division")
source
UnfoldSim.convertMethod

Obsolete - # TODO: Transfer function to Unfold.jl

Function to convert output similar to unfold (data, events)

source
UnfoldSim.generate_eventsMethod

Generates full factorial Dataframe according to MixedModelsSim.jl 's simdatcrossed function Note: nitems = you can think of it as trials or better, as stimuli

Note: No condition can be named dv which is used internally in MixedModelsSim / MixedModels as a dummy left-side

Afterwards applies design.eventorderfunction. Could be used to duplicate trials, sort, subselect etc.

Finally it sorts by :subject

julia> d = MultiSubjectDesign(;nsubjects = 10,nitems=20,bothwithin= Dict(:A=>nlevels(5),:B=>nlevels(2))) julia> generateevents(d)

source
UnfoldSim.generate_eventsMethod

Generates full-factorial DataFrame of design.conditions

Afterwards applies design.eventorderfunction.

If conditions is nothing, a single trial is simulated with a column :dummy and content :dummy - this is for convenience.

julia> d = SingleSubjectDesign(;conditions= Dict(:A=>nlevels(5),:B=>nlevels(2))) julia> generate_events(d)

source
UnfoldSim.hartmut_citationMethod

Returns citation-string for HArtMuT

source
UnfoldSim.headmodelMethod

Load a headmodel, using Artifacts.jl automatically downloads the required files

Currently only type="hartmut" is implemented

source
UnfoldSim.hrfMethod

Generate a HRF kernel.

TR = 1/sfreq default parameters taken from SPM

Code adapted from Unfold.jl

source
UnfoldSim.leadfieldMethod

Returns the leadfield

source
UnfoldSim.magnitudeMethod

Extracts magnitude of the orientation-including leadfield.

By default uses the orientation specified in the headmodel

Fallback: along the third dimension using norm - the maximal projection

source
UnfoldSim.magnitudeMethod

Extract magnitude of 3-orientation-leadfield, type (default: "perpendicular") => uses the provided source-point orientations - otherwise falls back to norm

source
UnfoldSim.n_channelsMethod

Returns the number of channels. By default = 1

source
UnfoldSim.n_channelsMethod

for MultichannelComponent returns the length of the projection vector

source
UnfoldSim.pad_arrayMethod

Pads array with specified value, length pad_array(arr, len, val)

source
UnfoldSim.predef_2x2Method
predef_2x2(rng::AbstractRNG;kwargs...)

Most used kwargs is: return_epoched=true to ignore the overlap/onset bits and return already epoched data

design

  • n_items=100,
  • n_subjects=1,
  • conditions = Dict(:A=>["asmall","abig"],:B=>["btiny","blarge"]),
  • event_order_function = x->shuffle(deepcopy(rng),x),

component / signal

  • signalsize = 100, length of simulated hanning window
  • basis= hanning(signalsize), the actual "function",signalsize` is only used here
  • β = [1,-0.5,.5,+1], the parameters
  • σs = Dict(:subject=>[1,0.5,0.5,0.5],:item=>[1]), - only in n_subjects>=2 case, specifies the random effects
  • contrasts = Dict(:A=>EffectsCoding(),:B=>EffectsCoding()) - effect coding by default
  • formula = n_subjects==1 ? @formula(0~1+AB) : @formula(dv~1+AB+(A*B|subject)+(1|item)),

noise

  • noiselevel = 0.2,
  • noise = PinkNoise(;noiselevel=noiselevel),

onset

  • overlap = (0.5,0.2),
  • onset=UniformOnset(;offset=signalsizeoverlap[1],width=signalsizeoverlap[2]), #put offset to 1 for no overlap. put width to 0 for no jitter

Careful if you modify nitems with nsubjects = 1, n_items has to be a multiple of 4 (or your equivalent conditions factorial, e.g. all combinations length)

source
UnfoldSim.predef_eegMethod

predefeeg(;kwargs...) predefeeg(rng;kwargs...) predefeeg(rng,nsubjects;kwargs...)

Gene rates a P1/N1/P3 complex. In case n_subjects is defined - MixedModelComponentsare generated, elseLinearModelComponents`

Most used kwargs is: return_epoched=true to ignore the overlap/onset bits and return already epoched data

Default params:

. n_repeats=100

  • eventorderfunction = x->shuffle(deepcopy(rng),x # random trial order
  • conditions = Dict(...),

component / signal

  • sfreq = 100,
  • p1 = (p100(;sfreq=sfreq), @formula(0~1),[5],Dict()), # P1 amp 5, no effects
  • n1 = (n170(;sfreq=sfreq), @formula(0~1+condition),[5,-3],Dict()), # N1 amp 5, dummycoded condition effect (levels "car", "face") of -3
  • p3 = (p300(;sfreq=sfreq), @formula(0~1+continuous),[5,1],Dict()), # P3 amp 5, continuous effect range [-5,5] with slope 1

noise

  • noiselevel = 0.2,
  • noise = PinkNoise(;noiselevel=noiselevel),

onset

  • overlap = (0.5,0.2), # offset + width/length of Uniform noise. put offset to 1 for no overlap. put width to 0 for no jitter
  • onset=UniformOnset(;offset=sfreq0.5overlap[1],width=sfreq0.5overlap[2]),
source
UnfoldSim.simulate_componentMethod

by default call simulate with ::Abstractcomponent,::AbstractDesign`, but allow for custom types

making use of other information in simulation

source
UnfoldSim.simulate_componentMethod

simulate a linearModel

julia> c = UnfoldSim.LinearModelComponent([0,1,1,0],@formula(0~1+cond),[1,2],Dict()) julia> design = MultiSubjectDesign(;nsubjects=2,nitems=50,itembetween=(;:cond=>["A","B"])) julia> simulatecomponent(StableRNG(1),c,design)

source
UnfoldSim.simulate_componentMethod

simulate MixedModelComponent

julia> design = MultiSubjectDesign(;nsubjects=2,nitems=50,item_between=(;:cond=>["A","B"])) julia> c = UnfoldSim.MixedModelComponent([0.,1,1,0],@formula(0~1+cond+(1|subject)),[1,2],Dict(:subject=>[2],),Dict()) julia> simulate(StableRNG(1),c,design)

source
UnfoldSim.simulate_noiseMethod
simulate_noise(t::RealisticNoise, n::Int)

Generate noise of a given type t and length n

source
UnfoldSim.simulate_noiseMethod
simulate_noise(t::Union{PinkNoise, RedNoise}, n::Int)

Generate noise of a given type t and length n

source
UnfoldSim.simulate_noiseMethod
simulate_noise(t::WhiteNoise, n::Int)

Generate noise of a given type t and length n

source
UnfoldSim.simulate_responsesMethod

Simulates multiple component responses and accumulates them on a per-event basis

source
UnfoldSim.weight_σsMethod

Weights a σs Dict for MixedModels.jl by a Float64

Finally sales it by σ_lmm, as a trick to simulate noise-free LMMs

I anticipate a function function weight_σs(σs::Dict,b_σs::Dict,σ_lmm::Float64) where each σs entry can be weighted individually

source
+design = RepeatDesign(designOnce,4);source
UnfoldSim.SingleSubjectDesignType
  • conditions = Dict of conditions, e.g. Dict(:A=>["a_small","a_big"],:B=>["b_tiny","b_large"])
  • eventorderfunction = x->x; # can be used to sort, or x->shuffle(MersenneTwister(42),x) - be sure to fix/update the rng accordingly!!

Number of trials / rows in generate_events(design) depend on the full factorial of your conditions.

To increase the number of repetitions simply use RepeatDesign(SingleSubjectDesign(...),5)

If conditions are omitted (or set to nothing), a single trial is simulated with a column :dummy and content :dummy - this is for convenience.

tipp: check the resulting dataframe using generate_events(design)

source
Base.sizeMethod

Returns dimension of experiment design

source
DSP.Windows.hanningMethod

generate a hanning window

duration: in s offset: in s, defines hanning peak sfreq: sampling rate in Hz

source
UnfoldSim.add_noise!Method

Generate and add noise to the data-matrix

Assumes that the signal can be linearized, that is, that the noise is stationary

source
UnfoldSim.add_responses!Method

Helper function to add inplace the responses to the signal, but for both 2D (1 channel) and 3D (X channel case)

source
UnfoldSim.closest_srcMethod
closest_src(coords_list::AbstractVector{<:AbstractVector}, pos)
+closest_src(coords::Vector{<:Real}, pos)

Takes an array of 'm' target coordinate vector (size 3) (or vector of vectors) and a matrix (n-by-3) of all available positions, and returns an array of size 'm' containing the indices of the respective items in 'pos' that are nearest to each of the target coordinates.

source
UnfoldSim.closest_srcMethod
closest_src(head::Hartmut,label::String)

Returns src-ix of the Headmodel Hartmut which is closest to the average of the label.

Important

We use the average in eucledean space, but the cortex is a curved surface. In most cases they will not overlap. Ideally we would calculate the average on the surface, but this is a bit more complex to do (you'd need to calculate the vertices etc.)

hartmut = headmodel()
+pos = closest_src(hartmut=>"Left Middle Temporal Gyrus, posterior division")
source
UnfoldSim.convertMethod

Obsolete - # TODO: Transfer function to Unfold.jl

Function to convert output similar to unfold (data, events)

source
UnfoldSim.generate_eventsMethod

Generates full factorial Dataframe according to MixedModelsSim.jl 's simdatcrossed function Note: nitems = you can think of it as trials or better, as stimuli

Note: No condition can be named dv which is used internally in MixedModelsSim / MixedModels as a dummy left-side

Afterwards applies design.eventorderfunction. Could be used to duplicate trials, sort, subselect etc.

Finally it sorts by :subject

julia> d = MultiSubjectDesign(;nsubjects = 10,nitems=20,bothwithin= Dict(:A=>nlevels(5),:B=>nlevels(2))) julia> generateevents(d)

source
UnfoldSim.generate_eventsMethod

Generates full-factorial DataFrame of design.conditions

Afterwards applies design.eventorderfunction.

If conditions is nothing, a single trial is simulated with a column :dummy and content :dummy - this is for convenience.

julia> d = SingleSubjectDesign(;conditions= Dict(:A=>nlevels(5),:B=>nlevels(2))) julia> generate_events(d)

source
UnfoldSim.hartmut_citationMethod

Returns citation-string for HArtMuT

source
UnfoldSim.headmodelMethod

Load a headmodel, using Artifacts.jl automatically downloads the required files

Currently only type="hartmut" is implemented

source
UnfoldSim.hrfMethod

Generate a HRF kernel.

TR = 1/sfreq default parameters taken from SPM

Code adapted from Unfold.jl

source
UnfoldSim.leadfieldMethod

Returns the leadfield

source
UnfoldSim.magnitudeMethod

Extracts magnitude of the orientation-including leadfield.

By default uses the orientation specified in the headmodel

Fallback: along the third dimension using norm - the maximal projection

source
UnfoldSim.magnitudeMethod

Extract magnitude of 3-orientation-leadfield, type (default: "perpendicular") => uses the provided source-point orientations - otherwise falls back to norm

source
UnfoldSim.n_channelsMethod

Returns the number of channels. By default = 1

source
UnfoldSim.n_channelsMethod

for MultichannelComponent returns the length of the projection vector

source
UnfoldSim.pad_arrayMethod

Pads array with specified value, length pad_array(arr, len, val)

source
UnfoldSim.predef_2x2Method
predef_2x2(rng::AbstractRNG;kwargs...)

Most used kwargs is: return_epoched=true to ignore the overlap/onset bits and return already epoched data

design

  • n_items=100,
  • n_subjects=1,
  • conditions = Dict(:A=>["asmall","abig"],:B=>["btiny","blarge"]),
  • event_order_function = x->shuffle(deepcopy(rng),x),

component / signal

  • signalsize = 100, length of simulated hanning window
  • basis= hanning(signalsize), the actual "function",signalsize` is only used here
  • β = [1,-0.5,.5,+1], the parameters
  • σs = Dict(:subject=>[1,0.5,0.5,0.5],:item=>[1]), - only in n_subjects>=2 case, specifies the random effects
  • contrasts = Dict(:A=>EffectsCoding(),:B=>EffectsCoding()) - effect coding by default
  • formula = n_subjects==1 ? @formula(0~1+AB) : @formula(dv~1+AB+(A*B|subject)+(1|item)),

noise

  • noiselevel = 0.2,
  • noise = PinkNoise(;noiselevel=noiselevel),

onset

  • overlap = (0.5,0.2),
  • onset=UniformOnset(;offset=signalsizeoverlap[1],width=signalsizeoverlap[2]), #put offset to 1 for no overlap. put width to 0 for no jitter

Careful if you modify nitems with nsubjects = 1, n_items has to be a multiple of 4 (or your equivalent conditions factorial, e.g. all combinations length)

source
UnfoldSim.predef_eegMethod

predefeeg(;kwargs...) predefeeg(rng;kwargs...) predefeeg(rng,nsubjects;kwargs...)

Gene rates a P1/N1/P3 complex. In case n_subjects is defined - MixedModelComponentsare generated, elseLinearModelComponents`

Most used kwargs is: return_epoched=true to ignore the overlap/onset bits and return already epoched data

Default params:

. n_repeats=100

  • eventorderfunction = x->shuffle(deepcopy(rng),x # random trial order
  • conditions = Dict(...),

component / signal

  • sfreq = 100,
  • p1 = (p100(;sfreq=sfreq), @formula(0~1),[5],Dict()), # P1 amp 5, no effects
  • n1 = (n170(;sfreq=sfreq), @formula(0~1+condition),[5,-3],Dict()), # N1 amp 5, dummycoded condition effect (levels "car", "face") of -3
  • p3 = (p300(;sfreq=sfreq), @formula(0~1+continuous),[5,1],Dict()), # P3 amp 5, continuous effect range [-5,5] with slope 1

noise

  • noiselevel = 0.2,
  • noise = PinkNoise(;noiselevel=noiselevel),

onset

  • overlap = (0.5,0.2), # offset + width/length of Uniform noise. put offset to 1 for no overlap. put width to 0 for no jitter
  • onset=UniformOnset(;offset=sfreq0.5overlap[1],width=sfreq0.5overlap[2]),
source
UnfoldSim.simulate_componentMethod

by default call simulate with ::Abstractcomponent,::AbstractDesign`, but allow for custom types

making use of other information in simulation

source
UnfoldSim.simulate_componentMethod

simulate a linearModel

julia> c = UnfoldSim.LinearModelComponent([0,1,1,0],@formula(0~1+cond),[1,2],Dict()) julia> design = MultiSubjectDesign(;nsubjects=2,nitems=50,itembetween=(;:cond=>["A","B"])) julia> simulatecomponent(StableRNG(1),c,design)

source
UnfoldSim.simulate_componentMethod

simulate MixedModelComponent

julia> design = MultiSubjectDesign(;nsubjects=2,nitems=50,item_between=(;:cond=>["A","B"])) julia> c = UnfoldSim.MixedModelComponent([0.,1,1,0],@formula(0~1+cond+(1|subject)),[1,2],Dict(:subject=>[2],),Dict()) julia> simulate(StableRNG(1),c,design)

source
UnfoldSim.simulate_noiseMethod
simulate_noise(t::RealisticNoise, n::Int)

Generate noise of a given type t and length n

source
UnfoldSim.simulate_noiseMethod
simulate_noise(t::Union{PinkNoise, RedNoise}, n::Int)

Generate noise of a given type t and length n

source
UnfoldSim.simulate_noiseMethod
simulate_noise(t::WhiteNoise, n::Int)

Generate noise of a given type t and length n

source
UnfoldSim.simulate_responsesMethod

Simulates multiple component responses and accumulates them on a per-event basis

source
UnfoldSim.weight_σsMethod

Weights a σs Dict for MixedModels.jl by a Float64

Finally sales it by σ_lmm, as a trick to simulate noise-free LMMs

I anticipate a function function weight_σs(σs::Dict,b_σs::Dict,σ_lmm::Float64) where each σs entry can be weighted individually

source
diff --git a/dev/generated/HowTo/multichannel/index.html b/dev/generated/HowTo/multichannel/index.html index 8aa1ee6..bd785dd 100644 --- a/dev/generated/HowTo/multichannel/index.html +++ b/dev/generated/HowTo/multichannel/index.html @@ -42,4 +42,4 @@ visual = (; enlarge = 0.5, label_scatter = false), axis = (; limits = ((0, 1), (0, 0.9))), ) -fExample block output

This page was generated using Literate.jl.

+fExample block output

This page was generated using Literate.jl.

diff --git a/dev/generated/HowTo/newComponent/5c72689e.png b/dev/generated/HowTo/newComponent/5c72689e.png deleted file mode 100644 index eab93c8..0000000 Binary files a/dev/generated/HowTo/newComponent/5c72689e.png and /dev/null differ diff --git a/dev/generated/HowTo/newComponent/5ef1e9bd.png b/dev/generated/HowTo/newComponent/5ef1e9bd.png new file mode 100644 index 0000000..d3976af Binary files /dev/null and b/dev/generated/HowTo/newComponent/5ef1e9bd.png differ diff --git a/dev/generated/HowTo/newComponent/index.html b/dev/generated/HowTo/newComponent/index.html index 1b64192..20fc55b 100644 --- a/dev/generated/HowTo/newComponent/index.html +++ b/dev/generated/HowTo/newComponent/index.html @@ -41,4 +41,4 @@ TimeVaryingComponent(basis_shiftduration, 50), design, ) -plot_erpimage(hcat(erp...), sortvalues = generate_events(design).shift)Example block output

This page was generated using Literate.jl.

+plot_erpimage(hcat(erp...), sortvalues = generate_events(design).shift)Example block output

This page was generated using Literate.jl.

diff --git a/dev/generated/HowTo/newDesign/index.html b/dev/generated/HowTo/newDesign/index.html index 788dafe..cd9180b 100644 --- a/dev/generated/HowTo/newDesign/index.html +++ b/dev/generated/HowTo/newDesign/index.html @@ -13,4 +13,4 @@ levels = vcat(repeat(["levelA"], nA), repeat(["levelB"], nB)) return DataFrame(Dict(:condition => levels)) end;

Finally, we can test the function and see whether it returns a Design-DataFrame as we requested

design = ImbalanceSubjectDesign(; nTrials = 6, balance = 0.2)
-generate_events(design)
6×1 DataFrame
Rowcondition
String
1levelA
2levelB
3levelB
4levelB
5levelB
6levelB
Important

It is the users task to ensure that each run is reproducible. So if you have a random process (e.g. shuffling), be sure to safe a RNG object in your struct and use it in your generate function.


This page was generated using Literate.jl.

+generate_events(design)
6×1 DataFrame
Rowcondition
String
1levelA
2levelB
3levelB
4levelB
5levelB
6levelB
Important

It is the users task to ensure that each run is reproducible. So if you have a random process (e.g. shuffling), be sure to safe a RNG object in your struct and use it in your generate function.


This page was generated using Literate.jl.

diff --git a/dev/generated/HowTo/predefinedData/index.html b/dev/generated/HowTo/predefinedData/index.html index e5e3ef1..43cf3b9 100644 --- a/dev/generated/HowTo/predefinedData/index.html +++ b/dev/generated/HowTo/predefinedData/index.html @@ -21,4 +21,4 @@ generate_events(simulation.design).latency
Hint

This is a bit of a trick, it relies that MyManualOnset is always used in combination with MyManualDesign. You could of course repeat the structure from MyManualDesign also for MyManualOnset and have an explicit field in the structure containing the onsets.

And that's it

data, events = simulate(MersenneTwister(1), mydesign, signal, MyManualOnset())
 lines(data) # plotting
 vlines!(my_events.latency, linestyle = :dash)
-current_figure()
Example block output

now everything matches, lovely!


This page was generated using Literate.jl.

+current_figure()Example block output

now everything matches, lovely!


This page was generated using Literate.jl.

diff --git a/dev/generated/HowTo/repeatTrials/index.html b/dev/generated/HowTo/repeatTrials/index.html index ed38bcf..5b2bad9 100644 --- a/dev/generated/HowTo/repeatTrials/index.html +++ b/dev/generated/HowTo/repeatTrials/index.html @@ -7,4 +7,4 @@ ); design = RepeatDesign(designOnce, 4); -generate_events(design)
8×3 DataFrame
Rowsubjectconditem
StringStringString
1S1levelAI1
2S1levelAI1
3S1levelAI1
4S1levelAI1
5S2levelBI2
6S2levelBI2
7S2levelBI2
8S2levelBI2

As you can see, the design was simply repeated.

Note

If you implemented your own AbstractDesign, you need to define the size function accordingly. E.g.: Base.size(design::RepeatDesign{SingleSubjectDesign}) = size(design.design).*design.repeat


This page was generated using Literate.jl.

+generate_events(design)
8×3 DataFrame
Rowsubjectconditem
StringStringString
1S1levelAI1
2S1levelAI1
3S1levelAI1
4S1levelAI1
5S2levelBI2
6S2levelBI2
7S2levelBI2
8S2levelBI2

As you can see, the design was simply repeated.

Note

If you implemented your own AbstractDesign, you need to define the size function accordingly. E.g.: Base.size(design::RepeatDesign{SingleSubjectDesign}) = size(design.design).*design.repeat


This page was generated using Literate.jl.

diff --git a/dev/generated/reference/basistypes/index.html b/dev/generated/reference/basistypes/index.html index 6875f6d..f48cace 100644 --- a/dev/generated/reference/basistypes/index.html +++ b/dev/generated/reference/basistypes/index.html @@ -44,4 +44,4 @@ axislegend(string(cfg[1]); merge = true) end -fExample block output

This page was generated using Literate.jl.

+fExample block output

This page was generated using Literate.jl.

diff --git a/dev/generated/reference/noisetypes/index.html b/dev/generated/reference/noisetypes/index.html index f1e1925..1e8d4ec 100644 --- a/dev/generated/reference/noisetypes/index.html +++ b/dev/generated/reference/noisetypes/index.html @@ -41,4 +41,4 @@ end f[1, 4] = Legend(f, ax_sig, "Noise type", tellheight = true) -fExample block output
Hint

We recommed for smaller signals the ExponentialNoise, maybe with a removed DC offset or a HighPass filter. For long signals, this Noise requires lots of memory though. maybe Pinknoise is a better choice then.


This page was generated using Literate.jl.

+fExample block output
Hint

We recommed for smaller signals the ExponentialNoise, maybe with a removed DC offset or a HighPass filter. For long signals, this Noise requires lots of memory though. maybe Pinknoise is a better choice then.


This page was generated using Literate.jl.

diff --git a/dev/generated/reference/onsettypes/index.html b/dev/generated/reference/onsettypes/index.html index 2e2175d..d504bc2 100644 --- a/dev/generated/reference/onsettypes/index.html +++ b/dev/generated/reference/onsettypes/index.html @@ -109,4 +109,4 @@ end axes_list[end].xlabel = "Time between events [samples]" linkyaxes!(axes_list...) -end

Overlap of subsequent events

Note

The overlap of subsequent events can be indirectly controlled by setting the offset parameter relative to the length of the component basis. Assuming that signal is a component e.g. LinearModelComponent,


This page was generated using Literate.jl.

+end

Overlap of subsequent events

Note

The overlap of subsequent events can be indirectly controlled by setting the offset parameter relative to the length of the component basis. Assuming that signal is a component e.g. LinearModelComponent,


This page was generated using Literate.jl.

diff --git a/dev/generated/reference/overview/index.html b/dev/generated/reference/overview/index.html index bc80edc..5a9974a 100644 --- a/dev/generated/reference/overview/index.html +++ b/dev/generated/reference/overview/index.html @@ -16,4 +16,4 @@ RedNoise UnfoldSim.AutoRegressiveNoise UnfoldSim.RealisticNoise - WhiteNoise

This page was generated using Literate.jl.

+ WhiteNoise

This page was generated using Literate.jl.

diff --git a/dev/generated/tutorials/poweranalysis/index.html b/dev/generated/tutorials/poweranalysis/index.html index 7493983..803f798 100644 --- a/dev/generated/tutorials/poweranalysis/index.html +++ b/dev/generated/tutorials/poweranalysis/index.html @@ -25,4 +25,4 @@ # calculate a one-sided t-test pvals[seed] = pvalue(OneSampleTTest(y_big, y_small)) -end
 12.987251 seconds (21.85 M allocations: 3.359 GiB, 4.91% gc time, 89.31% compilation time: 8% of which was recompilation)

let's calculate the power

power = mean(pvals .< 0.05) * 100
70.0

This page was generated using Literate.jl.

+end
 13.635715 seconds (21.95 M allocations: 3.366 GiB, 5.19% gc time, 89.02% compilation time: 9% of which was recompilation)

let's calculate the power

power = mean(pvals .< 0.05) * 100
70.0

This page was generated using Literate.jl.

diff --git a/dev/generated/tutorials/quickstart/index.html b/dev/generated/tutorials/quickstart/index.html index cf315fb..eba3085 100644 --- a/dev/generated/tutorials/quickstart/index.html +++ b/dev/generated/tutorials/quickstart/index.html @@ -9,4 +9,4 @@ β = [1, 0.5], );

Onsets and Noise

We will start with a uniform (but overlapping, offset < length(signal.basis)) onset-distribution

onset = UniformOnset(; width = 20, offset = 4);

And we will use some noise

noise = PinkNoise(; noiselevel = 0.2);

Combine & Generate

We will put it all together in one Simulation type

simulation = Simulation(design, signal, onset, noise);

finally, we will simulate some data

data, events = simulate(MersenneTwister(1), simulation);

Data is a n-sample Vector (but could be a Matrix for e.g. MultiSubjectDesign).

events is a DataFrame that contains a column latency with the onsets of events.

Plot them!

lines(data; color = "black")
 vlines!(events.latency; color = ["orange", "teal"][1 .+ (events.condA.=="levelB")])
-current_figure()
Example block output

This page was generated using Literate.jl.

+current_figure()Example block output

This page was generated using Literate.jl.

diff --git a/dev/generated/tutorials/simulateERP/index.html b/dev/generated/tutorials/simulateERP/index.html index 90ede7d..d617fa9 100644 --- a/dev/generated/tutorials/simulateERP/index.html +++ b/dev/generated/tutorials/simulateERP/index.html @@ -56,4 +56,4 @@ # Workaround to separate legend and colorbar (will be fixed in a future UnfoldMakie version) legend = f.content[2] f[:, 1] = legend -current_figure()Example block output

This page was generated using Literate.jl.

+current_figure()Example block output

This page was generated using Literate.jl.

diff --git a/dev/index.html b/dev/index.html index 64692b7..6a15179 100644 --- a/dev/index.html +++ b/dev/index.html @@ -7,4 +7,4 @@ vlines!(evts.latency;color=["orange","teal"][1 .+ (evts.condition .=="car")]) current_figure()Example block output

Or simulate epoched data directly

data,evts = UnfoldSim.predef_eeg(;n_repeats=20,noiselevel=0.8,return_epoched=true)
-heatmap(data[:,sortperm(evts,[:condition,:continuous])])
Example block output +heatmap(data[:,sortperm(evts,[:condition,:continuous])])Example block output