Esempio n. 1
0
def test_create_second_level_design():
    subjects_label = ['02', '01']  # change order to test right output order
    regressors = [['01', 0.1], ['02', 0.75]]
    regressors = pd.DataFrame(regressors, columns=['subject_label', 'f1'])
    design = make_second_level_design_matrix(subjects_label, regressors)
    expected_design = np.array([[0.75, 1], [0.1, 1]])
    assert_array_equal(design, expected_design)
    assert_true(len(design.columns) == 2)
    assert_true(len(design) == 2)
Esempio n. 2
0
# We want to get the group result of a contrast for 20 subjects.
n_subjects = 20
subjects_label = ['sub-%02d' % i for i in range(1, n_subjects + 1)]

##############################################################################
# Next, we specify extra information about the subjects to create confounders.
# Without confounders the design matrix would correspond to a one sample test.
import pandas as pd
extra_info_subjects = pd.DataFrame({
    'subject_label': subjects_label,
    'age': range(15, 15 + n_subjects),
    'sex': [0, 1] * int(n_subjects / 2)
})

#########################################################################
# Create a second level design matrix
# -----------------------------------
# With that information we can create the second level design matrix.
from nistats.design_matrix import make_second_level_design_matrix
design_matrix = make_second_level_design_matrix(subjects_label,
                                                extra_info_subjects)

#########################################################################
# Let's plot it.
from nistats.reporting import plot_design_matrix
ax = plot_design_matrix(design_matrix)
ax.set_title('Second level design matrix', fontsize=12)
ax.set_ylabel('maps')
plt.tight_layout()
plt.show()
#########################################################################
# Create a simple experimental paradigm
# --------------------------------------
# We want to get the group result of a contrast for 20 subjects
n_subjects = 20
subjects_label = ['sub-%02d' % i for i in range(1, n_subjects + 1)]

##############################################################################
# Specify extra information about the subjects to create confounders
# Without confounders the design matrix would correspond to a one sample test
import pandas as pd
extra_info_subjects = pd.DataFrame({'subject_label': subjects_label,
                                    'age': range(15, 15 + n_subjects),
                                    'sex': [0, 1] * int(n_subjects / 2)})

#########################################################################
# Create a second level design matrix
# -----------------------------------
from nistats.design_matrix import make_second_level_design_matrix
design_matrix = make_second_level_design_matrix(subjects_label, extra_info_subjects)

#########################################################################
# plot the results
from nistats.reporting import plot_design_matrix
ax = plot_design_matrix(design_matrix)
ax.set_title('Second level design matrix', fontsize=12)
ax.set_ylabel('maps')
plt.tight_layout()
plt.show()