|
53 | 53 | # For the calculations, It uses |
54 | 54 | # previously calculated correlation coefficients between IT and all other areas in both, |
55 | 55 | # synaptic activity time-series and fMRI bold time-series. |
56 | | -# It also performs a two-tailed t-test for the comparison between the mean of each condition |
| 56 | +# It also performs a one-tailed paired t-test for the comparison between the mean of each condition |
57 | 57 | # (DMS vs CTL), and displays the t values. |
58 | 58 |
|
59 | 59 | import numpy as np |
|
68 | 68 |
|
69 | 69 | from scipy.stats import t |
70 | 70 |
|
| 71 | +from scipy import stats |
| 72 | + |
| 73 | +import math as m |
| 74 | + |
71 | 75 | # set matplot lib parameters to produce visually appealing plots |
72 | | -mpl.style.use('ggplot') |
| 76 | +#mpl.style.use('ggplot') |
73 | 77 |
|
74 | 78 | # construct array of indices of modules contained in an LSNM model, minus 1 |
75 | 79 | modules = np.arange(7) |
|
219 | 223 | fc_fmri_dms_mean = np.mean(fc_fmri_dms, axis=0) |
220 | 224 | fc_fmri_ctl_mean = np.mean(fc_fmri_ctl, axis=0) |
221 | 225 |
|
222 | | -# calculate the standard deviation of correlation coefficients across subjects |
| 226 | +# calculate the standard error of the mean of correlation coefficients across subjects |
223 | 227 | fc_syn_dms_std = np.std(fc_syn_dms, axis=0) |
224 | 228 | fc_syn_ctl_std = np.std(fc_syn_ctl, axis=0) |
225 | 229 | fc_fmri_dms_std = np.std(fc_fmri_dms, axis=0) |
|
232 | 236 | fc_fmri_ctl_var= np.var(fc_fmri_ctl, axis=0) |
233 | 237 |
|
234 | 238 | # now, convert back to from Z to R correlation coefficients, prior to plotting |
235 | | -fc_syn_dms_mean = np.tanh(fc_syn_dms_mean) |
236 | | -fc_syn_ctl_mean = np.tanh(fc_syn_ctl_mean) |
237 | | -fc_fmri_dms_mean = np.tanh(fc_fmri_dms_mean) |
238 | | -fc_fmri_ctl_mean = np.tanh(fc_fmri_ctl_mean) |
| 239 | +#fc_syn_dms_mean = np.tanh(fc_syn_dms_mean) |
| 240 | +#fc_syn_ctl_mean = np.tanh(fc_syn_ctl_mean) |
| 241 | +#fc_fmri_dms_mean = np.tanh(fc_fmri_dms_mean) |
| 242 | +#fc_fmri_ctl_mean = np.tanh(fc_fmri_ctl_mean) |
239 | 243 |
|
240 | | -fc_syn_dms_std = np.tanh(fc_syn_dms_std) |
241 | | -fc_syn_ctl_std = np.tanh(fc_syn_ctl_std) |
242 | | -fc_fmri_dms_std = np.tanh(fc_fmri_dms_std) |
243 | | -fc_fmri_ctl_std = np.tanh(fc_fmri_ctl_std) |
| 244 | +#fc_syn_dms_std = np.tanh(fc_syn_dms_std) |
| 245 | +#fc_syn_ctl_std = np.tanh(fc_syn_ctl_std) |
| 246 | +#fc_fmri_dms_std = np.tanh(fc_fmri_dms_std) |
| 247 | +#fc_fmri_ctl_std = np.tanh(fc_fmri_ctl_std) |
244 | 248 |
|
245 | | -fc_syn_dms_var = np.tanh(fc_syn_dms_var) |
246 | | -fc_syn_ctl_var = np.tanh(fc_syn_ctl_var) |
247 | | -fc_fmri_dms_var = np.tanh(fc_fmri_dms_var) |
248 | | -fc_fmri_ctl_var = np.tanh(fc_fmri_ctl_var) |
| 249 | +#fc_syn_dms_var = np.tanh(fc_syn_dms_var) |
| 250 | +#fc_syn_ctl_var = np.tanh(fc_syn_ctl_var) |
| 251 | +#fc_fmri_dms_var = np.tanh(fc_fmri_dms_var) |
| 252 | +#fc_fmri_ctl_var = np.tanh(fc_fmri_ctl_var) |
249 | 253 |
|
250 | 254 | # ... and save above values to output file |
251 | 255 | np.savetxt(fc_stats_FILE, [np.append(fc_syn_dms_mean, [fc_syn_ctl_mean, |
|
257 | 261 | fmt='%.4f', |
258 | 262 | header='Synaptic and BOLD correlation stats (DMS and CTL) grouped by module') |
259 | 263 |
|
260 | | -# Calculate the statistical significance by using a two-tailed t-test: |
261 | | -# We are going to have two groups: DMS group and control group (each sample size is 10 subjects) |
262 | | -# Our research hypothesis is: |
263 | | -# * The correlations in the DMS group are larger than the correlations in the CTL group. |
264 | | -# The NULL hypothesis is: |
265 | | -# * Correlations in the DMS group are not larger than Correlations in the CTL group. |
266 | | -# The value of alpha (p-threshold) will be 0.05 |
| 264 | +# Calculate the statistical significance by using a one-tailed paired t-test: |
| 265 | +# We are going to have one group of 10 subjects, doing both DMS and control task |
267 | 266 | # STEPS: |
268 | | -# (1) subtract the mean of control group from the mean of DMS group: |
269 | | -fc_syn_mean_diff = fc_syn_ctl_mean - fc_syn_dms_mean |
270 | | -fc_fmri_mean_diff= fc_fmri_ctl_mean- fc_fmri_dms_mean |
271 | | -# (2) Calculate, for both control and DMS, the variance divided by sample size minus 1: |
272 | | -fc_syn_ctl_a = fc_syn_ctl_var / 9.0 |
273 | | -fc_syn_dms_a = fc_syn_dms_var / 9.0 |
274 | | -fc_fmri_ctl_a= fc_fmri_ctl_var / 9.0 |
275 | | -fc_fmri_dms_a= fc_fmri_dms_var / 9.0 |
276 | | -# (3) Add results obtained for CTL and DMS in step (2) together: |
277 | | -fc_syn_a = fc_syn_ctl_a + fc_syn_dms_a |
278 | | -fc_fmri_a= fc_fmri_ctl_a+ fc_fmri_dms_a |
279 | | -# (4) Take the square root the results in step (3): |
280 | | -sqrt_fc_syn_a = np.sqrt(fc_syn_a) |
281 | | -sqrt_fc_fmri_a= np.sqrt(fc_fmri_a) |
282 | | -# (5) Divide the results of step (1) by the results of step (4) to obtain 't': |
283 | | -fc_syn_t = fc_syn_mean_diff / sqrt_fc_syn_a |
284 | | -fc_fmri_t= fc_fmri_mean_diff / sqrt_fc_fmri_a |
285 | | -# (6) Calculate the degrees of freedom (add up number of observations for each group |
286 | | -# minus number of groups): |
287 | | -dof = 10 + 10 - 2 |
288 | | -# (7) find the p-values for the above 't' and 'degrees of freedom': |
289 | | -fc_syn_p_values = t.sf(fc_syn_t, dof) |
290 | | -fc_fmri_p_values = t.sf(fc_fmri_t, dof) |
291 | | - |
292 | | -print 't-values for synaptic activity correlations: ', fc_syn_t |
293 | | -print 't-values for fmri time-series correlations: ', fc_fmri_t |
| 267 | +# (1) Set up hypotheses: |
| 268 | +# The NULL hypothesis is: |
| 269 | +# * The mean difference between paired observations (DMS and CTL) is zero |
| 270 | +# Our alternative hypothesis is: |
| 271 | +# * The mean difference between paired observations (DMS and CTL) is not zero |
| 272 | +# (2) Set a significance level: |
| 273 | +alpha = 0.05 |
| 274 | +# (3) What is the critical value and the rejection region? |
| 275 | +n = 10 - 1 # sample size minus 1 |
| 276 | +rejection_region = 1.833 # as found on t-test table for t and dof given, |
| 277 | + # values of t above rejection_region will be rejected |
| 278 | +# (4) compute the value of the test statistic |
| 279 | +# calculate differences between the pairs of data: |
| 280 | +d_syn = fc_syn_dms - fc_syn_ctl |
| 281 | +d_fmri = fc_fmri_dms- fc_fmri_ctl |
| 282 | +# calculate the mean of those differences |
| 283 | +d_syn_mean = np.mean(d_syn, axis=0) |
| 284 | +d_fmri_mean= np.mean(d_fmri, axis=0) |
| 285 | +# calculate the standard deviation of those differences |
| 286 | +d_syn_std = np.std(d_syn, axis=0) |
| 287 | +d_fmri_std = np.std(d_fmri, axis=0) |
| 288 | +# calculate square root of sample size |
| 289 | +sqrt_n = m.sqrt(n) |
| 290 | +# calculate standard error of the mean differences |
| 291 | +d_syn_sem = d_syn_std/sqrt_n |
| 292 | +d_fmri_sem= d_fmri_std/sqrt_n |
| 293 | +# calculate the t statistic: |
| 294 | +t_star_syn = d_syn_mean / d_syn_sem |
| 295 | +t_star_fmri= d_fmri_mean/ d_fmri_sem |
| 296 | + |
| 297 | +print 't-values for synaptic activity correlations: ', t_star_syn |
| 298 | +print 't-values for fmri time-series correlations: ', t_star_fmri |
| 299 | + |
| 300 | +print 'ISA Mean Differences (IT-V1, IT-V4, IT-FS, IT-D1, IT-D2, IT-FR): ', d_syn_mean |
| 301 | +print 'fMRI Mean Differences (IT-V1, IT-V4, IT-FS, IT-D1, IT-D2, IT-FR): ', d_fmri_mean |
| 302 | + |
| 303 | +print 'Dimensions of mean differences array', d_syn_mean.shape |
| 304 | +print 'Dimensions of std of differences array', d_syn_std.shape |
294 | 305 |
|
295 | 306 | # convert to Pandas dataframe, using the transpose to convert to a format where the names |
296 | 307 | # of the modules are the labels for each time-series |
297 | | -fc_mean = pd.DataFrame(np.array([fc_syn_dms_mean, fc_syn_ctl_mean, |
298 | | - fc_fmri_dms_mean, fc_fmri_ctl_mean]), |
| 308 | +d_mean = pd.DataFrame(np.array([d_syn_mean, |
| 309 | + d_fmri_mean]), |
299 | 310 | columns=np.array(['V1', 'V4', 'FS', 'D1', 'D2', 'FR', 'cIT']), |
300 | | - index=np.array(['DMS-syn', 'CTL-syn', 'DMS-fmri', 'CTL-fmri'])) |
301 | | -fc_std = pd.DataFrame(np.array([fc_syn_dms_std, fc_syn_ctl_std, |
302 | | - fc_fmri_dms_std, fc_fmri_ctl_std]), |
| 311 | + index=np.array(['ISA', 'fMRI'])) |
| 312 | +d_std = pd.DataFrame(np.array([d_syn_sem, |
| 313 | + d_fmri_sem]), |
303 | 314 | columns=np.array(['V1', 'V4', 'FS', 'D1', 'D2', 'FR', 'cIT']), |
304 | | - index=np.array(['DMS-syn', 'CTL-syn', 'DMS-fmri', 'CTL-fmri'])) |
| 315 | + index=np.array(['ISA', 'fMRI'])) |
305 | 316 |
|
306 | 317 | # now, plot means and std's using 'pandas framework... |
307 | 318 |
|
|
312 | 323 |
|
313 | 324 | ax = plt.gca() # get hold of the axes |
314 | 325 |
|
315 | | -bars=fc_mean.plot(yerr=fc_std, ax=ax, kind='bar', |
| 326 | +bars=d_mean.plot(yerr=d_std, ax=ax, kind='bar', |
316 | 327 | color=['yellow', 'green', 'orange', 'red', 'pink', 'purple', 'lightblue'], |
317 | | - ylim=[-0.1, 1.1]) |
| 328 | + ylim=[-0.5, 0.4]) |
318 | 329 |
|
319 | 330 | # change the location of the legend |
320 | | -ax.legend(bbox_to_anchor=(0., 1.02, 1., .102), loc=3, |
321 | | - ncol=7, mode="expand", borderaxespad=0.,prop={'size':30}) |
| 331 | +#ax.legend(bbox_to_anchor=(0., 1.02, 1., .102), loc=3, |
| 332 | +# ncol=7, mode="expand", borderaxespad=0.,prop={'size':30}) |
| 333 | + |
| 334 | +ax.set_xticklabels( ('ISA', 'fMRI'), rotation=0, ha='center') |
| 335 | + |
| 336 | +ax.set_ylabel('Functional connectivity differences') |
| 337 | + |
| 338 | +ax.grid(b=False) |
| 339 | +ax.yaxis.grid(True) |
| 340 | + |
| 341 | +#line_fig = plt.figure() |
| 342 | + |
| 343 | +#ax = plt.gca() |
322 | 344 |
|
323 | | -ax.set_xticklabels( ('DMS-syn', 'CTL-syn', 'DMS-fmri', 'CTL-fmri'), rotation=0, ha='center') |
| 345 | +#lines= |
324 | 346 |
|
325 | 347 | #plt.tight_layout() |
326 | 348 |
|
|
0 commit comments