NeuroAnalyzer tutorials: Statistics: Bootstrapping
Initialize NeuroAnalyzer
using NeuroAnalyzer
using Plots
using Statistics
eeg = load("files/eeg.hdf")
e10 = epoch(eeg, ep_len=10)
delete_epoch!(e10, ep=1:10);Calculate and plot CI using bootstrapping
Get the first 2 seconds of the channel 1 of epochs 1:10 and calculate its 95%CI:
s = e10.data[1, 1:512, 1:10]
t = e10.epoch_time[1:512]
s_avg, s_l, s_u = bootstrap_ci(s, cl=0.95)(s_avg = [11.659300281192465, 10.267416842024419, 11.982210796098316, 12.633272561174595, 11.574590513319876, 11.545503015764897, 10.547236039222913, 10.538442595517484, 10.428070967561805, 10.747234389826788 … -14.947999572996457, -17.49806253030125, -16.394520781528968, -12.147031307974233, -9.684243826578012, -12.314498061380473, -15.23403828747199, -15.212713925487574, -12.856349899754504, -11.02106059836681],
s_ci_l = [10.832015791592202, 9.425955184854137, 11.113173319624332, 11.655034156537877, 10.670701358751547, 10.662448915206648, 9.678479041456328, 9.769467078606432, 9.567759547887205, 9.855897809182952 … -17.191546471900878, -20.275959660861844, -19.094147147668767, -14.231077682935002, -11.498618960564453, -14.548026289259298, -17.991393034019794, -17.924602552610367, -15.010052229831853, -12.922218878394549],
s_ci_h = [12.507459320826188, 11.134337864508433, 12.881451210821625, 13.63029221910113, 12.500960097313936, 12.473436756802954, 11.437148045689197, 11.353501323071535, 11.343948770430805, 11.694571928671545 … -12.856892172501105, -14.892851740964339, -13.824024518626823, -10.13576466727993, -7.915514309518437, -10.189946272576654, -12.612162419520475, -12.650293236138118, -10.792592966626925, -9.187550954945998],)
Plot CI:
plot_ci(s_avg, s_l, s_u, t)Calculate statistic using bootstrapping
Any statistical function may be calculated using bootstrapping method. The function must be provided as f="function_name(obj)", obj will be replaced with the signal data, e.g. f="mean(obj)".
s = e10.data[1, :, 1:10]
s_stat = mean(s)
s_dist = bootstrap_stat(s, f="mean(obj)")3000-element Vector{Float64}:
0.005161853605707733
-0.03585747533203385
0.15995404814361916
0.08269136350010058
0.11693123097306657
-0.057481567153723746
0.09996914964729013
0.2512558627746825
0.21215424722436368
0.07628844706772409
0.1921110686558194
0.07281927963930865
0.07271812863405688
⋮
0.16344561232525195
0.06386297452225129
0.15517305104924634
-0.009586425558272538
-0.013604292655014127
0.03397578181076675
0.22080657633693876
0.13258182707720811
0.2266256048958903
-0.01567515394520047
0.009050636357872044
0.13110245120866698
plot_histogram(s_dist,
s_stat,
draw_median=false,
draw_mean=true)