-
Notifications
You must be signed in to change notification settings - Fork 0
/
Schwartze_Figure4b_regress_results_StatsFinal.m
156 lines (115 loc) · 5.52 KB
/
Schwartze_Figure4b_regress_results_StatsFinal.m
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
%%
% Load data
clear variables
monkey = 'Q';
load(['\\kumc.edu\data\Research\SOM RSCH\RouseLab\DataFiles\Project_Data\20160504_COT_precision\data_analyses\COT_Direction_Regress\' monkey '_regress_results_StatsFinal'])
All_signif_units = squeeze(cat(3,signif_units{:}));
All_pref_dir_init = cat(2,pref_dir_init{:});
All_pref_dir_cor = cat(2,pref_dir_cor{:});
for i = 1:12
if i == 1
All_pref_dir_init1= squeeze(pref_dir_init1{i});
else
All_pref_dir_init1 = [All_pref_dir_init1;squeeze(pref_dir_init1{i})];
end
end
for i = 1:12
if i == 1
All_pref_dir_init2= squeeze(pref_dir_init2{i});
else
All_pref_dir_init2 = [All_pref_dir_init2;squeeze(pref_dir_init2{i})];
end
end
for i = 1:12
if i == 1
All_pref_dir_cor1= squeeze(pref_dir_cor1{i});
else
All_pref_dir_cor1 = [All_pref_dir_cor1;squeeze(pref_dir_cor1{i})];
end
end
for i = 1:12
if i == 1
All_pref_dir_cor2= squeeze(pref_dir_cor2{i});
else
All_pref_dir_cor2 = [All_pref_dir_cor2;squeeze(pref_dir_cor2{i})];
end
end
PrefDirDiff=abs(wrapTo180(All_pref_dir_init-All_pref_dir_cor));
perc_neurons_lt_45deg = 100*(sum(PrefDirDiff(All_signif_units)<45)/sum(All_signif_units));
disp([num2str(100-perc_neurons_lt_45deg) '% Pref Dir > 45 degrees'])
%Bootstrapping
num_iter = 10000;
PrefDirData = PrefDirDiff(All_signif_units);
n_units = length(PrefDirData);
bootstrap_perc_neurons_lt_45deg = NaN(1,num_iter);
for k = 1:num_iter
rand_samp = randi(n_units, size(PrefDirData));
bootstrap_perc_neurons_lt_45deg(k) = 100*(sum(PrefDirData(rand_samp)<45)/sum(All_signif_units));
bootstrap_median_pd(k) = median(PrefDirData(rand_samp));
end
CI_perc_neurons_lt_45deg = prctile(bootstrap_perc_neurons_lt_45deg, [2.5,97.5]);
disp([num2str(100-CI_perc_neurons_lt_45deg(2)) '-' num2str(100-CI_perc_neurons_lt_45deg(1)) '% Pref Dir > 45 degrees'])
%% 42.4899% Pref Dir > 45 degrees
%% 38.9716-46.0081% Pref Dir > 45 degrees
CI_bootstrap_median_pd = prctile(bootstrap_median_pd, [2.5,97.5]);
disp([num2str(CI_bootstrap_median_pd(2)) '-' num2str(CI_bootstrap_median_pd(1)) '% Pref Dir > 45 degrees'])
disp(median(PrefDirDiff(All_signif_units)));
median_PrefDirDiff = median(PrefDirDiff(All_signif_units));
%Null Hypothesis 1: Neurons do not change PD at all
%initial submovements
initPrefDirDiff = abs(wrapTo180(All_pref_dir_init1(All_signif_units,:)-All_pref_dir_init2(All_signif_units,:)));
median_initPrefDirDiff = median(initPrefDirDiff(:));
CI_median_initPrefDirDiff = prctile(initPrefDirDiff(:), [2.5,97.5]);
disp([num2str(CI_median_initPrefDirDiff(1)) '-' num2str(CI_median_initPrefDirDiff(2)) ' Degrees by 95% CI'])
median_median_initPrefDirDiff = median(median_initPrefDirDiff);
%corrective submovements
corPrefDirDiff = abs(wrapTo180(All_pref_dir_cor1(All_signif_units,:)-All_pref_dir_cor2(All_signif_units,:)));
median_corPrefDirDiff = median(corPrefDirDiff(:));
CI_median_corPrefDirDiff = prctile(corPrefDirDiff(:), [2.5,97.5]);
disp([num2str(CI_median_corPrefDirDiff(1)) '-' num2str(CI_median_corPrefDirDiff(2)) ' Degrees by 95% CI'])
median_median_corPrefDirDiff = median(median_corPrefDirDiff);
%Null Hypothesis 2: Randomizing corrective to match with initial submovements, all about the same
% Bootstrapping
num_iter = 1000;
for k = 1:num_iter
rand_All_pref_dir_cor=randperm(length(All_pref_dir_cor));
rand_PrefDirDiff = abs(wrapTo180(All_pref_dir_init-All_pref_dir_cor(rand_All_pref_dir_cor)));
median_bootstrap_null(k,:) = median(rand_PrefDirDiff);
end
CI_median_bootstrap_null = prctile(median_bootstrap_null, [2.5,97.5]);
disp([num2str(CI_median_bootstrap_null(1)) '-' num2str(CI_median_bootstrap_null(2)) ' Degrees by 95% CI'])
median_median_bootstrap_null = median(median_bootstrap_null);
figure
histogram(PrefDirDiff(All_signif_units), 0:15:180, 'FaceColor', [0.3,0.3,0.3])
hold on
ha = gca;
patch([CI_bootstrap_median_pd(1) CI_bootstrap_median_pd(1) CI_bootstrap_median_pd(2) CI_bootstrap_median_pd(2)], [min(ylim) max(ylim+20) max(ylim+20) min(ylim)], [0.8 0.8 0.8], 'edgecolor', 'none');
histogram(PrefDirDiff(All_signif_units), 0:15:180, 'FaceColor', [0.3,0.3,0.3])
xline(median_PrefDirDiff, 'LineStyle', '-', 'LineWidth', 2, 'Color', 'k')
xline([median_median_bootstrap_null], 'LineStyle', '--', 'LineWidth', 2, 'Color', '#7E2F8E');
xline([median_median_initPrefDirDiff], 'LineStyle', '--', 'LineWidth', 2, 'Color', 'b');
xline([median_median_corPrefDirDiff], 'LineStyle', '--', 'LineWidth', 2, 'Color', 'r');
set(gca, 'XTick', 0:30:180)
xlabel('Preferred Direction Difference (degrees)')
ylabel('Number of units')
set(gca, 'FontSize', 14)
% set(gcf,'Position',[0 0 900 600]);
title(['Monkey ' monkey])
figName = 'Figure4B';
% print(figName, '-dtiff')
% print(figName, '-dpdf', '-painters' )
% fig2svg('./figure_graphics/figure4b.svg', gcf)
SpikeSettings.samp_rate = 100;
start_samples_peakVel = -50; %500 ms before movement peak speeds
end_samples_peakVel = 30; %300 ms after movement peak speeds
mid_samples_peakVel = -start_samples_peakVel+1;
time_array = 1000*(start_samples_peakVel:end_samples_peakVel)/SpikeSettings.samp_rate; %Time array in ms
All_best_init_t = squeeze(cat(3,best_init_t{:}));
All_best_cor_t = squeeze(cat(3,best_cor_t{:}));
%Note, regerssion only performed from -300ms to 100 ms around peak speeds
All_best_init_t = All_best_init_t+20;
All_best_cor_t = All_best_cor_t+20;
mean(time_array(All_best_init_t(All_signif_units)))
mean(time_array(All_best_cor_t(All_signif_units)))
std(time_array(All_best_init_t(All_signif_units)))
std(time_array(All_best_cor_t(All_signif_units)))