def setUp(self, n_subjects=25, TR=1.5):

        self.TR = TR
        self.log = logging.getLogger('hb_test')

        self.data, self.onsets, self.parameters = (simulate_fmri_experiment(
            [{
                'name': 'Condition A',
                'mu_group': 5,
                'std_group': 3
            }, {
                'name': 'Condition B',
                'mu_group': 10,
                'std_group': 3
            }],
            n_subjects=n_subjects,
            run_duration=60,
            n_trials=10,
            TR=TR))

        self.hfit = HierarchicalBayesianModel()

        df = []

        for subject, d in self.data.reset_index().groupby(['subject']):
            fitter = nideconv.ResponseFitter(d.signal.values, 1. / self.TR)

            fitter.add_event('Condition A',
                             self.onsets.loc[subject, 'Condition A'].onset,
                             interval=[0, 20])

            fitter.add_event('Condition B',
                             self.onsets.loc[subject, 'Condition B'].onset,
                             interval=[0, 20])

            self.hfit.add_run(fitter, subject)
Esempio n. 2
0
cue_pars = {'name':'cue',
            'mu_group':-.5, # Slight negative response for cue
            'std_group':0,
            'onsets':cue_onsets}

stim_pars = {'name':'stim',
             'mu_group':1, # Positive response for stimulus presentation
             'std_group':0,
             'onsets':stim_onsets}

conditions = [cue_pars,
              stim_pars]

data, onsets, parameters = simulate.simulate_fmri_experiment(conditions,
                                                             run_duration=60,
                                                             noise_level=0.05)

##############################################################################
# Underlying data-generating model
# --------------------------------
# Because we simulated the data, we know that the event-related responses should
# exactly follow the *canonical Hemodynamic Response Function* [1]_are
from nideconv.utils import double_gamma_with_d
import numpy as np

plt.figure(figsize=(8, 2.5))

t = np.linspace(0, 20, 100)
ax1 = plt.subplot(121)
plt.title('Ground truth cue-related response')
Esempio n. 3
0
# fit a model, and see how well our model fits the data

from nideconv import simulate
from nideconv import ResponseFitter

conditions = [{
    'name': 'Condition A',
    'mu_group': 5,
    'std_group': 1,
    'onsets': [0, 20]
}]

# Simulate data with very short run time and TR for illustrative purposes
data, onsets, pars = simulate.simulate_fmri_experiment(conditions,
                                                       TR=0.2,
                                                       run_duration=40,
                                                       noise_level=.2,
                                                       n_rois=1)

# Make ResponseFitter-object to fit these data
rf = ResponseFitter(input_signal=data,
                    sample_rate=5)  # Sample rate is inverse of TR (1/TR)
rf.add_event('Condition A',
             onsets.loc['Condition A'].onset,
             interval=[0, 20],
             basis_set='canonical_hrf')

rf.fit()

rf.plot_model_fit()
Esempio n. 4
0
"""
from nideconv import simulate
conditions = [{
    'name': 'Correct',
    'mu_group': .25,
    'std_group': .1,
    'n_trials': 16
}, {
    'name': 'Error',
    'mu_group': .5,
    'std_group': .1,
    'n_trials': (1, 6)
}]

data, onsets, pars = simulate.simulate_fmri_experiment(conditions,
                                                       n_subjects=9,
                                                       n_runs=1,
                                                       TR=1.5)

##############################################################################
# First, we fit this data using the traditional frequentist GLM with Fourier
# basis functions:
from nideconv import GroupResponseFitter
gmodel = GroupResponseFitter(data,
                             onsets,
                             input_sample_rate=1 / 1.5,
                             concatenate_runs=False)
gmodel.add_event('Correct',
                 basis_set='fourier',
                 n_regressors=9,
                 interval=[0, 21])
gmodel.add_event('Error',
Esempio n. 5
0
"""
Deconvolution on group of subjects
==================================

The `GroupResponseFitter`-object of `Nideconv` offers an easy way to fit the data of many subjects together
well-specified model
`nideconv.simulate` can simulate data from multiple subjects.
"""

from nideconv import simulate

data, onsets, pars = simulate.simulate_fmri_experiment(n_subjects=8,
                                                       n_rois=2,
                                                       n_runs=2)
##############################################################################
# Now we have an indexed Dataframe, `data`, that contains time series for every
# subject, run, and ROI:

print(data.head())

##############################################################################
#
print(data.tail())

##############################################################################
# We also have onsets for every subject and run:
print(onsets.head())
##############################################################################
#
##############################################################################
print(onsets.tail())