Skip to content

Commit a464560

Browse files
authored
Merge pull request #17 from s-ccs/fix-sparseInit
fix docs simulation, had overlap where it shouldnt have had any, also sometimes sparse matrix was a bit too short
2 parents 49c4626 + 73e4f24 commit a464560

File tree

3 files changed

+20
-7
lines changed

3 files changed

+20
-7
lines changed

docs/src/reference/type1.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,20 +41,20 @@ function run_fun(r)
4141
MersenneTwister(r),
4242
design,
4343
signal,
44-
UniformOnset(; offset=5, width=4),
44+
NoOnset(),
4545
RedNoise(noiselevel=1);
4646
return_epoched=true,
4747
)
4848
data = reshape(data, size(data, 1), :)
49-
data = data[:, evts.condition.=="small"] .- data[:, evts.condition.=="large"]
49+
data_diff = data[:, evts.condition.=="small"] .- data[:, evts.condition.=="large"]
5050

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

5555
# ## Understanding the simulation
5656
# let's have a look at the actual data by running it once, plotting condition wise trials, the ERP and histograms of uncorrected and corrected p-values
57-
data, pval = run_fun(5)
57+
data, pval = run_fun(1)
5858
conditionSmall = data[:, 1:2:end]
5959
conditionLarge = data[:, 2:2:end]
6060
pval_uncorrected =
@@ -96,7 +96,7 @@ reps = 500
9696
res = fill(NaN, reps, 2)
9797
Threads.@threads for r = 1:reps
9898
data, pvals = run_fun(r)
99-
res[r, 1] = mean(pvals .<= 0.05 / 2)
99+
res[r, 1] = mean(pvals .<= 0.05)
100100
res[r, 2] =
101101
mean(abs.(ClusterDepth.studentt(data)) .>= quantile(TDist(n_subjects - 1), 0.975))
102102
end;

src/cluster.jl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,11 @@ function perm_clusterdepths_both(
105105
end
106106
#@debug size(d0)
107107
#@debug size(data_perm)
108+
#data_perm .-= mean(data_perm, dims=length(size(data_perm)))
108109
for i = 1:nₚ
109110
# permute
110111
d_perm = permfun(rng, data_perm)
112+
111113
if isnothing(statfun!)
112114
d0 = statfun(d_perm)
113115
else
@@ -136,8 +138,8 @@ function perm_clusterdepths_both(
136138
end
137139
end
138140

139-
Jₖ_head = sparse(rows_h, cols_h, vals_h)#SparseMatrixCSC(nₚ,maximum(rows_h), cols_h,rows_h,vals_h)
140-
Jₖ_tail = sparse(rows_t, cols_t, vals_t)#SparseMatrixCSC(nₚ,maximum(rows_t), cols_t,rows_t,vals_t)
141+
Jₖ_head = sparse(rows_h, cols_h, vals_h, maximum(rows_h), nₚ)#SparseMatrixCSC(nₚ,maximum(rows_h), cols_h,rows_h,vals_h)
142+
Jₖ_tail = sparse(rows_t, cols_t, vals_t, maximum(rows_t), nₚ)#SparseMatrixCSC(nₚ,maximum(rows_t), cols_t,rows_t,vals_t)
141143
return ClusterDepthMatrix((Jₖ_head)), ClusterDepthMatrix((Jₖ_tail))
142144
end
143145

@@ -264,3 +266,4 @@ function cluster(data::BitVector)
264266
end
265267
return start, len
266268
end
269+
show_warnings

test/cluster.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
2+
13
@testset "cluster" begin
24
s, l = ClusterDepth.cluster(
35
[4.0, 0.0, 10.0, 0.0, 3.0, 4.0, 0, 4.0, 4.0, 0.0, 0.0, 5.0] .> 0.9,
@@ -64,4 +66,12 @@ end
6466
data[23, :] .-= 3
6567
@test_warn x -> occursin("Your data shows a cluster", x) ClusterDepth.clusterdepth(data; τ=0.4, nperm=5)
6668

69+
end
70+
71+
@testset "sparse matrix size" begin
72+
data = rand(StableRNG(42), 5, 10) .- 0.5
73+
data[2, :] .+= 1
74+
data[3, :] .+= 3
75+
cdmTuple = ClusterDepth.perm_clusterdepths_both(StableRNG(1), data, (ClusterDepth.sign_permute!), 1.5; nₚ=1000, (statfun!)=(ClusterDepth.studentt!), sidefun=abs)
76+
@test size(cdmTuple[1].J, 2) == 1000 # sparse matrix has to have the size of n-perms
6777
end

0 commit comments

Comments
 (0)