-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDataAnalysis.jl
208 lines (172 loc) · 5.69 KB
/
DataAnalysis.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
### A Pluto.jl notebook ###
# v0.15.1
using Markdown
using InteractiveUtils
# ╔═╡ 46cec8f0-d30f-49aa-9501-685aab02f23d
let
using Pkg;
Pkg.activate(".") #pluto doesn't activate the env by default
end
# ╔═╡ 04ddbcb7-5c2b-4c3b-8cf5-a5b294af8d64
using Unfold, StatsModels
# ╔═╡ 6eb82b93-d1b8-4c5a-beaf-892f40560fd8
begin
using CairoMakie
CairoMakie.activate!()
end
# ╔═╡ 4493bf65-5fec-4be3-bff2-491c2562ce78
include("src/utils.jl")
# ╔═╡ 369e1538-3855-4d0b-9b17-6f7dd32e9cc9
md"""
# Encoding and Decoding Analysis using Back-to-Back regression
"""
# ╔═╡ bf87faea-f9b3-4403-867a-422a57034d31
md"""
## Introduction
"""
# ╔═╡ 7f6c9361-dbf2-4fed-88f6-71c2add543aa
md"""
### load data and events
"""
# ╔═╡ 24e747ea-792c-41d1-9fba-eb7117ccce3a
function load_data(sub = "sub-48")
path = "data/$(sub)/eeg/$(sub)_task-WLFO_eeg.set"
!isfile(path) && (path = "/store/data/WLFO/derivatives/preproc_agert/$(sub)/eeg/$(sub)_task-WLFO_eeg.set")
data, events = read_eeglab(path, 128)
return (data, events)
end
# ╔═╡ 469f905a-4e65-4252-a142-3ad8bcd47854
md"""
Filter events types to include only *Fixations*
"""
# ╔═╡ 1a2bdc3f-3faa-48db-9247-98b30b4da23e
begin
data, events = load_data("sub-48")
events = events[events.type .== "fixation",:]
end
# ╔═╡ f6cf5ad3-5aad-449b-b563-e7f1a1db7c43
begin
beta, times = Unfold.epoch(data=data, tbl=events, τ=(-0.3, 0.5), sfreq=128)
beta[:,:,isnan.(events.sac_vmax)] .= missing # to run with sac_vmax
beta[:,:,isnan.(events.fix_avgpos_x)] .= missing # to run with sac_vmax
end
# ╔═╡ cd36c14d-fc59-4327-b807-776f007b1f10
function get_gamma(f, events, beta, times)
se_solver = solver = (x, y) -> Unfold.solver_b2b(x, y,cross_val_reps = 5)
model, results_expanded = Unfold.fit(UnfoldLinearModel, f, events, beta, times, solver=se_solver)
return(model, results_expanded)
end
# ╔═╡ c6c154d4-0a74-4fa9-b0ad-5c52b9377c2d
md"""
## Observations
"""
# ╔═╡ 62f9cb36-1732-4b59-9013-eda6b3f8237e
md"""
### Ground truth data
"""
# ╔═╡ 0b361dee-8e1e-4ddc-807d-789de6d5e498
md"""
we plot the gamma of Intercept and Saccades amplitude.\
$y = \beta_0 + \beta_1 * sacc\_amp$
"""
# ╔═╡ 5524c3fe-0c6d-48df-80dc-98ddf5172515
begin
f_amp = @formula 0~1 + sac_amplitude;
m, res_amp = get_gamma(f_amp, events, beta, times);
pt_amp = plot_results(res_amp,layout_x=:basisname);
end
# ╔═╡ 044c89eb-9b08-41ab-a4f6-06dd63f35df2
md"""
we plot the gamma of Intercept and Saccades Velocity.\
$y = \beta_0 + \beta_1 * sacc\_vmax$
"""
# ╔═╡ 7ad9d3d7-d77b-483b-8e26-bed435345ffd
begin
f_vmax = @formula 0~1 + sac_vmax
_, res_vmax = get_gamma(f_vmax, events, beta, times);
pt_vmax = plot_results(res_vmax,layout_x=:basisname)
end
# ╔═╡ 8b79b4e0-8f0f-49ba-b29b-6f5556897847
md"""
we plot the gamma of Intercept, Saccades amplitude and Saccades Velocity.\
$y = \beta_0 + \beta_1 * sacc\_amp + \beta_2 * sacc\_vmax$
"""
# ╔═╡ 31811918-12b5-4540-b6c7-b18ce88e111d
begin
f_amp_vmax = @formula 0~1 + sac_amplitude + sac_vmax
_, res_amp_vmax = get_gamma(f_amp_vmax, events, beta, times);
pt_amp_vmax = plot_results(res_amp_vmax,layout_x=:basisname)
end
# ╔═╡ 54a02c16-48f4-4bdc-ba06-3d6af0a971d7
md"""
we plot the gamma of Intercept, human face, saccades amplitude and saccades velocity.\
$y = \beta_0 + \beta_1 * cat(human\_face) + \beta_2 * sac\_amplitude + \beta_3 * sac\_vmax$
"""
# ╔═╡ c5dc110c-240c-423e-a660-42644f5c7fcb
begin
f_amp_vmax_hf = @formula 0~1 + sac_amplitude + sac_vmax + humanface
_, res_amp_vmax_hf = get_gamma(f_amp_vmax_hf, events, beta, times);
pt_amp_vmax_hf = plot_results(res_amp_vmax_hf,layout_x=:basisname)
end
# ╔═╡ 61695ced-5892-47bf-9cde-af3453658211
begin
scene = vbox(pt_amp, pt_vmax)
scene
end
# ╔═╡ ae0d9783-726d-4b07-a616-c4980935b3f9
md"""
# Playground
"""
# ╔═╡ c6020209-bb67-4b6d-b813-ac0c24d973b4
md"""
## Using B2BRegression Module
"""
# ╔═╡ 5d25d703-f49b-4975-baee-d71cf80203fa
function get_path(sub)
path = "data/$(sub)/eeg/$(sub)_task-WLFO_eeg.set"
if !isfile(path)
path = "/store/data/WLFO/derivatives/preproc_agert/$(sub)/eeg/$(sub)_task-WLFO_eeg.set"
end
return path
end
# ╔═╡ 9bb9ae0d-5149-492d-af64-e33c7f4707fe
path = get_path("sub-45")
# ╔═╡ 0ada22b0-fa5f-4d77-a806-96039e72fb10
B2BRegression.plot_massunivariate_gamma(
path,
(@formula 0~1 + sac_amplitude),
τ = (-0.3, 0.5),
event_types = ["fixation"],
sfreq = 128,
cross_val_reps = 5,
mixed = false
)
# ╔═╡ Cell order:
# ╟─369e1538-3855-4d0b-9b17-6f7dd32e9cc9
# ╟─bf87faea-f9b3-4403-867a-422a57034d31
# ╠═46cec8f0-d30f-49aa-9501-685aab02f23d
# ╠═04ddbcb7-5c2b-4c3b-8cf5-a5b294af8d64
# ╠═6eb82b93-d1b8-4c5a-beaf-892f40560fd8
# ╠═4493bf65-5fec-4be3-bff2-491c2562ce78
# ╟─7f6c9361-dbf2-4fed-88f6-71c2add543aa
# ╠═24e747ea-792c-41d1-9fba-eb7117ccce3a
# ╟─469f905a-4e65-4252-a142-3ad8bcd47854
# ╠═1a2bdc3f-3faa-48db-9247-98b30b4da23e
# ╠═f6cf5ad3-5aad-449b-b563-e7f1a1db7c43
# ╠═cd36c14d-fc59-4327-b807-776f007b1f10
# ╟─c6c154d4-0a74-4fa9-b0ad-5c52b9377c2d
# ╟─62f9cb36-1732-4b59-9013-eda6b3f8237e
# ╟─0b361dee-8e1e-4ddc-807d-789de6d5e498
# ╠═5524c3fe-0c6d-48df-80dc-98ddf5172515
# ╟─044c89eb-9b08-41ab-a4f6-06dd63f35df2
# ╠═7ad9d3d7-d77b-483b-8e26-bed435345ffd
# ╟─8b79b4e0-8f0f-49ba-b29b-6f5556897847
# ╠═31811918-12b5-4540-b6c7-b18ce88e111d
# ╟─54a02c16-48f4-4bdc-ba06-3d6af0a971d7
# ╠═c5dc110c-240c-423e-a660-42644f5c7fcb
# ╠═61695ced-5892-47bf-9cde-af3453658211
# ╟─ae0d9783-726d-4b07-a616-c4980935b3f9
# ╠═c6020209-bb67-4b6d-b813-ac0c24d973b4
# ╠═5d25d703-f49b-4975-baee-d71cf80203fa
# ╟─9bb9ae0d-5149-492d-af64-e33c7f4707fe
# ╠═0ada22b0-fa5f-4d77-a806-96039e72fb10