def group_connectivity(timeseries, subject_list, atlas_name, kind, save=True, save_path=root_folder):
    '\n        timeseries   : list of timeseries tables for subjects (timepoints x regions)\n        subject_list : the subject short IDs list\n        atlas_name   : name of the atlas used\n        kind         : the kind of connectivity to be used, e.g. lasso, partial correlation, correlation\n        save         : save the connectivity matrix to a file\n        save_path    : specify path to save the matrix if different from subject folder\n\n    returns:\n        connectivity : connectivity matrix (regions x regions)\n    '
    if (kind == 'lasso'):
        covariance_estimator = GraphLassoCV(verbose=1)
        connectivity_matrices = []
        for (i, ts) in enumerate(timeseries):
            covariance_estimator.fit(ts)
            connectivity = covariance_estimator.covariance_
            connectivity_matrices.append(connectivity)
            print('Covariance matrix has shape {0}.'.format(connectivity.shape))
    elif (kind in ['tangent', 'partial correlation', 'correlation']):
        conn_measure = connectome.ConnectivityMeasure(kind=kind)
        connectivity_matrices = conn_measure.fit_transform(timeseries)
    if save:
        for (i, subject) in enumerate(subject_list):
            subject_file = os.path.join(save_path, subject_list[i], (((((subject_list[i] + '_') + atlas_name) + '_') + kind.replace(' ', '_')) + '.mat'))
            sio.savemat(subject_file, {'connectivity': connectivity_matrices[i]})
            print(('Saving connectivity matrix to %s' % subject_file))
    return connectivity_matrices
timeseries   : list of timeseries tables for subjects (timepoints x regions)
    subject_list : the subject short IDs list
    atlas_name   : name of the atlas used
    kind         : the kind of connectivity to be used, e.g. lasso, partial correlation, correlation
    save         : save the connectivity matrix to a file
    save_path    : specify path to save the matrix if different from subject folder

returns:
    connectivity : connectivity matrix (regions x regions)
def group_connectivity(timeseries, subject_list, atlas_name, kind, save=True, save_path=root_folder):
    '\n        timeseries   : list of timeseries tables for subjects (timepoints x regions)\n        subject_list : the subject short IDs list\n        atlas_name   : name of the atlas used\n        kind         : the kind of connectivity to be used, e.g. lasso, partial correlation, correlation\n        save         : save the connectivity matrix to a file\n        save_path    : specify path to save the matrix if different from subject folder\n\n    returns:\n        connectivity : connectivity matrix (regions x regions)\n    '
    if (kind == 'lasso'):
        covariance_estimator = GraphLassoCV(verbose=1)
        connectivity_matrices = []
        for (i, ts) in enumerate(timeseries):
            covariance_estimator.fit(ts)
            connectivity = covariance_estimator.covariance_
            connectivity_matrices.append(connectivity)
            print('Covariance matrix has shape {0}.'.format(connectivity.shape))
    elif (kind in ['tangent', 'partial correlation', 'correlation']):
        conn_measure = connectome.ConnectivityMeasure(kind=kind)
        connectivity_matrices = conn_measure.fit_transform(timeseries)
    if save:
        for (i, subject) in enumerate(subject_list):
            subject_file = os.path.join(save_path, subject_list[i], (((((subject_list[i] + '_') + atlas_name) + '_') + kind.replace(' ', '_')) + '.mat'))
            sio.savemat(subject_file, {'connectivity': connectivity_matrices[i]})
            print(('Saving connectivity matrix to %s' % subject_file))
    return connectivity_matrices