Skip to content

Commit 49c4626

Browse files
committed
added possibility to deactivate warnings for simulations, fixed literate move
1 parent c5bed2c commit 49c4626

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

docs/make.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@ makedocs(;
2626
pages=[
2727
"Home" => "index.md",
2828
"Tutorials" => [
29-
"An EEG Example" => "tutorials/generated/eeg.md",
30-
"EEG Example - Multichannel data" => "tutorials/generated/eeg-multichannel.md",
29+
"An EEG Example" => "generated/tutorials/eeg.md",
30+
"EEG Example - Multichannel data" => "generated/tutorials/eeg-multichannel.md",
3131
],
3232
"HowTo" => [
3333
"R: Between groups" => "howto/R_betweengroups.md",
3434
],
3535
"Reference" => [
36-
"Clusterdepth FWER" => "reference/generated/type1.md",
37-
"Troendle FWER" => "reference/generated/type1_troendle.md",
36+
"Clusterdepth FWER" => "generated/reference/type1.md",
37+
"Troendle FWER" => "generated/reference/type1_troendle.md",
3838
],
3939
],
4040
)

docs/src/reference/type1.jl

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ signal = MixedModelComponent(;
3737
# Let's move the actual simulation into a function, so we can call it many times.
3838
# Note that we use (`RedNoise`)[https://unfoldtoolbox.github.io/UnfoldSim.jl/dev/literate/reference/noisetypes/] which has lot's of Autocorrelation between timepoints. nice!
3939
function run_fun(r)
40-
data, events = simulate(
40+
data, evts = simulate(
4141
MersenneTwister(r),
4242
design,
4343
signal,
@@ -46,10 +46,10 @@ function run_fun(r)
4646
return_epoched=true,
4747
)
4848
data = reshape(data, size(data, 1), :)
49-
data = data[:, events.condition.=="small"] .- data[:, events.condition.=="large"]
49+
data = data[:, evts.condition.=="small"] .- data[:, evts.condition.=="large"]
5050

5151
return data,
52-
clusterdepth(data'; τ=quantile(TDist(n_subjects - 1), 0.95), nperm=1000)
52+
clusterdepth(data'; τ=quantile(TDist(n_subjects - 1), 0.975), nperm=1000, show_warnings=false)
5353
end;
5454

5555
# ## Understanding the simulation
@@ -68,7 +68,6 @@ sig = pval_uncorrected .<= 0.025;
6868
# For the uncorrected p-values based on the t-distribution, we get a type1 error over "time":
6969
mean(sig)
7070

71-
# this is the type 1 error of 5% we expected.
7271

7372
# !!! note
7473
# Type-I error is not the FWER (family wise error rate). FWER is the property of a set of tests (in this case tests per time-point), we can calculate it by repeating such tests,
@@ -97,7 +96,7 @@ reps = 500
9796
res = fill(NaN, reps, 2)
9897
Threads.@threads for r = 1:reps
9998
data, pvals = run_fun(r)
100-
res[r, 1] = mean(pvals .<= 0.05)
99+
res[r, 1] = mean(pvals .<= 0.05 / 2)
101100
res[r, 2] =
102101
mean(abs.(ClusterDepth.studentt(data)) .>= quantile(TDist(n_subjects - 1), 0.975))
103102
end;

src/cluster.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Optional
1818
- `statfun` / `statfun!` a function that either takes one or two arguments and aggregates over last dimension. in the two argument case we expect the first argument to be modified inplace and provide a suitable Vector/Matrix.
1919
- `sidefun`: default `abs`. Provide a function to be applied on each element of the output of `statfun`.
2020
- `permfun` function to permute the data, should accept an RNG-object and the data. can be inplace, the data is copied, but the same array is shared between permutations
21-
21+
- `show_warnings`: default `true` - function to suppress warnings, useful for simulations
2222
"""
2323
clusterdepth(data::AbstractArray, args...; kwargs...) =
2424
clusterdepth(MersenneTwister(1), data, args...; kwargs...)
@@ -34,6 +34,7 @@ function clusterdepth(
3434
(statfun!)=nothing,
3535
statfun=nothing,
3636
permfun=nothing,
37+
show_warnings=false,
3738
)
3839
if stat_type == :onesample_ttest && isnothing(statfun!) && isnothing(statfun)
3940
statfun! = studentt!
@@ -57,7 +58,7 @@ function clusterdepth(
5758
end
5859
data_obs = sidefun.(statfun(data))
5960

60-
if any(data_obs[:, 1] .> τ) || any(data_obs[:, end] .> τ)
61+
if show_warnings && (any(data_obs[:, 1] .> τ) || any(data_obs[:, end] .> τ))
6162
@warn "Your data shows a cluster that starts before the first sample, or ends after the last sample. There exists a fundamental limit in the ClusterDepth method, that the clusterdepth for such a cluster cannot be determined. Maybe you can extend the epoch to include more samples?"
6263
end
6364
cdmTuple = perm_clusterdepths_both(

0 commit comments

Comments
 (0)