Skip to content
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

plot_predict( ) function #233

Open
ReneSkukies opened this issue Aug 19, 2024 · 1 comment
Open

plot_predict( ) function #233

ReneSkukies opened this issue Aug 19, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@ReneSkukies
Copy link
Member

Since we now have a predict() function, it would be nice to have a function that easily plots the predicted data. Maybe overlayed/ subplotted with the actual data. I achieved it in the following way:

using Unfold, CairoMakie

# Predict the data from model m
pred_data_stim = predict(
    m,
    Unfold.formulas(m),
    Unfold.events(m);
    overlap = true,
    keep_basis = [Unfold.basisname(Unfold.formulas(m))[2]]
)

pred_data_resp = predict(
    m,
    Unfold.formulas(m),
    Unfold.events(m);
    overlap = true,
    keep_basis = [Unfold.basisname(Unfold.formulas(m))[1]]
)

fig = Figure()
ax1 = Axis(fig[1], width=Relative(1), height=Relative(0.5), halign=0.0, valign=1)
ax2 = Axis(fig[1], width=Relative(1), height=Relative(0.5), halign=0.0, valign=0.0)
l = (500, 1500) # limits of the plot

# Plot continuous data
lines!(ax1, data, color = :black)

# Plot non-overlapping data
lines!(ax2, pred_data_stim[1,:], color = (:blue, 0.5))
lines!(ax2, pred_data_resp[1,:], color = (:red, 0.5))


# Set limits and hide stuff
axes = [ax1, ax2]
for a in axes; xlims!(a, l...); hidedecorations!(a); hidespines!(a); end

# Stimulus marker
colors = [:blue, :green]
for (i,c) in enumerate(unique(evts.condition))
vlines!(Axis(fig[pos...]),@rsubset(evts, :condition .== c, :event .== 'S').latency, color = (colors[i], 0.5))
xlims!(l...)
hidedecorations!(current_axis())
hidespines!(current_axis())
end

# Response marker
vlines!(Axis(fig[pos...]),@rsubset(evts,:event .== 'R').latency, color = (:red, 0.5))
xlims!(l...)
hidedecorations!(current_axis())
hidespines!(current_axis())

current_figure()

In this case it looks like this for me (but it's specific for my figure, thus no decorations)
image

This way one could visually inspect how much of the data is explained by the model (when plotting predicted data with overlap), how much overlap is in the data, etc.
Additionally, this could be nice for future figures and presentations.

@behinger
Copy link
Member

behinger commented Sep 2, 2024

I like it. One issue I see, which I also see with the DesignMatrix, is that if we have a long dataset, we don't really know where (or "when in time") to plot, and plotting everything is maybe a bit much (even though possible outside CairoMakie+SVG).

Maybe it is time time to implement a datascroll after all (similar to https://github.com/JuliaHealth/NeuroAnalyzer.jl)

@vladdez vladdez added the enhancement New feature or request label Sep 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants