Skip to content
This repository was archived by the owner on Jan 27, 2023. It is now read-only.

Commit 131b330

Browse files
author
Antonio Ulloa
committed
Ported netgen from C to Python and added it to simulation subdirectory
1 parent a907376 commit 131b330

File tree

139 files changed

+21835
-286
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

139 files changed

+21835
-286
lines changed

analysis/avg_func_conn_across_subjects.py

Lines changed: 81 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
# For the calculations, It uses
5454
# previously calculated correlation coefficients between IT and all other areas in both,
5555
# 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
5757
# (DMS vs CTL), and displays the t values.
5858

5959
import numpy as np
@@ -68,8 +68,12 @@
6868

6969
from scipy.stats import t
7070

71+
from scipy import stats
72+
73+
import math as m
74+
7175
# set matplot lib parameters to produce visually appealing plots
72-
mpl.style.use('ggplot')
76+
#mpl.style.use('ggplot')
7377

7478
# construct array of indices of modules contained in an LSNM model, minus 1
7579
modules = np.arange(7)
@@ -219,7 +223,7 @@
219223
fc_fmri_dms_mean = np.mean(fc_fmri_dms, axis=0)
220224
fc_fmri_ctl_mean = np.mean(fc_fmri_ctl, axis=0)
221225

222-
# calculate the standard deviation of correlation coefficients across subjects
226+
# calculate the standard error of the mean of correlation coefficients across subjects
223227
fc_syn_dms_std = np.std(fc_syn_dms, axis=0)
224228
fc_syn_ctl_std = np.std(fc_syn_ctl, axis=0)
225229
fc_fmri_dms_std = np.std(fc_fmri_dms, axis=0)
@@ -232,20 +236,20 @@
232236
fc_fmri_ctl_var= np.var(fc_fmri_ctl, axis=0)
233237

234238
# 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)
239243

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)
244248

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)
249253

250254
# ... and save above values to output file
251255
np.savetxt(fc_stats_FILE, [np.append(fc_syn_dms_mean, [fc_syn_ctl_mean,
@@ -257,51 +261,58 @@
257261
fmt='%.4f',
258262
header='Synaptic and BOLD correlation stats (DMS and CTL) grouped by module')
259263

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
267266
# 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
294305

295306
# convert to Pandas dataframe, using the transpose to convert to a format where the names
296307
# 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]),
299310
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]),
303314
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']))
305316

306317
# now, plot means and std's using 'pandas framework...
307318

@@ -312,15 +323,26 @@
312323

313324
ax = plt.gca() # get hold of the axes
314325

315-
bars=fc_mean.plot(yerr=fc_std, ax=ax, kind='bar',
326+
bars=d_mean.plot(yerr=d_std, ax=ax, kind='bar',
316327
color=['yellow', 'green', 'orange', 'red', 'pink', 'purple', 'lightblue'],
317-
ylim=[-0.1, 1.1])
328+
ylim=[-0.5, 0.4])
318329

319330
# 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()
322344

323-
ax.set_xticklabels( ('DMS-syn', 'CTL-syn', 'DMS-fmri', 'CTL-fmri'), rotation=0, ha='center')
345+
#lines=
324346

325347
#plt.tight_layout()
326348

0 commit comments

Comments
 (0)