Skip to content

Commit

Permalink
bug in significance
Browse files Browse the repository at this point in the history
  • Loading branch information
vladdez committed Jan 14, 2025
1 parent 03659de commit 35742b1
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/plot_erp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ function plot_erp!(
categorical_group = nothing,
stderror = false, # XXX if it exists, should be plotted
significance = nothing,
sign_type = :line,
mapping = (;),
kwargs...,
)
Expand Down Expand Up @@ -141,9 +142,8 @@ function plot_erp!(

# add the p-values
if !isnothing(significance)
basic = basic + add_significance(plot_data, significance, config)
basic = basic + add_significance(plot_data, significance, config, sign_type)
end

plot_equation = basic * mapp

f_grid = f[1, 1] = GridLayout()
Expand Down Expand Up @@ -176,7 +176,7 @@ function plot_erp!(
return f
end

function add_significance(plot_data, significance, config)
function add_significance(plot_data, significance, config, sign_type)
p = deepcopy(significance)

# for now, add them to the fixed effect
Expand All @@ -194,23 +194,24 @@ function add_significance(plot_data, significance, config)
if :color keys(config.mapping)
c = config.mapping.color isa Pair ? config.mapping.color[1] : config.mapping.color
un = unique(p[!, c])
p[!, :sigindex] .= [findfirst(un .== x) for x in p.coefname]
p[!, :signindex] .= [findfirst(un .== x) for x in p.coefname]
else
p[!, :signindex] .= 1
end
# define an index to dodge the lines vertically

scaleY = [minimum(plot_data.estimate), maximum(plot_data.estimate)]
stepY = scaleY[2] - scaleY[1]
stepY = scaleY[2] - scaleY[1] # gap between significance rectangles
posY = stepY * -0.05 + scaleY[1]
Δt = diff(plot_data.time[1:2])[1]
Δy = 0.01
Δt = diff(plot_data.time[1:2])[1] # added length of significance polygone

p[!, :segments] = [
Makie.Rect(
Makie.Vec(x, posY + stepY * (Δy * (n - 1))),
Makie.Vec(y - x + Δt, 0.5 * Δy * stepY),
) for (x, y, n) in zip(p.from, p.to, p.sigindex)
) for (x, y, n) in zip(p.from, p.to, p.signindex)
]

res = data(p) * mapping(:segments) * visual(Poly)
return (res)
end

0 comments on commit 35742b1

Please sign in to comment.