kingjr / meg_expectation_p3

GNU General Public License v3.0
0 stars 0 forks source link

EHN: definition of all contrasts #6

Open kingjr opened 9 years ago

kingjr commented 9 years ago

@gmeade

gmeade commented 9 years ago

Hey! I have (I think) all of the contrasts defined. Once you push the changes that you have made, I will add them and double check that they're working (to avoid both changing the same files and having merge issues). Let me know if you still need something from me file-wise...

Thanks, G

gmeade commented 9 years ago

How would you define middle SOA trials? This is what I did (I couldn't find one command to do both greater than and less than): exclude=dict(soa=min(soas), soa=max(soas),present=False))

But it isn't happy, saying "SyntaxError: keyword argument repeated"...

kingjr commented 9 years ago

I think exclude=dict(soa=[min(soas), max(soas)]), should work. Although I would go for the include=dict(soa=[soa2, soa3... if it works, as it's more explicit.

gmeade commented 9 years ago

OK so I pushed the changes I made. There probably is a more efficient way to do this, so feel free to change them as you see fit.

There is also currently one that is commented out because I couldn't figure out how to do the SOAs like you did the PAS and a couple of notes about what to include/not to include. If you could help with the PAS x SOA, that would also be great.

There are no other syntax errors, but I thought I would send them to you first to see what you think/to have a final list and then I will run them all the way through.

kingjr commented 9 years ago

Ok. Try to simplify the code by

e.g.

# Global block context, SOA (middle SOAs only)
contrast_block_soa = list()
for idx, soa in enumerate([33, 50, 67]):
    contrast = dict(
        name = 'vis' +str(soa) + '-invis' + str(soa), 
        operator=evoked_subtract, conditions=[
            dict(name='vis_' + str(soa), include=dict(block='visible',soa=soa)),
            dict(name='invis_' + str(33), include=dict(block='invisible',soa=soa))])
    contrast_block_soa.append(contrast)

If you could help with the PAS x SOA, that would also be great

What are you trying to define? Whether the ERF vary as a function of PAS for each SOA? If so, it should be something like this?

regress_pas_soa = list()
for idx, soa in enumerate([17, 33, 50, 67, 83]):
    regress = dict(
        name = 'pas_regress_soa' +str(soa), 
        operator=evoked_subtract, conditions=[
            dict(name='pas' + str(pas) + '_soa' + str(soa),
                   include=dict(pas=pas,soa=soa), exclude=absent)
            for pas in range(4)])
    regress_pas_soa.append(regress)
gmeade commented 9 years ago

But if you do this, then you don’t define the operator for the outer contrast, right? e.g., here each of the inner comparisons is binary, but then we have to define that we want to do a regression over the three SOAs, right?

Also, regarding the SOA x PAS, I guess so? I got that from the list that we made, but I interpreted it the same way as you. What is idx in the code that you wrote below? Maybe we could quickly go over the syntax tomorrow?

On 18 May 2015, at 20:07, J-R King notifications@github.com wrote:

Ok. Try to simplify the code by

putting the contrasts definition in loops. e.g.

Global block context, SOA (middle SOAs only)

contrast_block_soa = list() for idx, soa in enumerate([33, 50, 67]): contrast = dict( name = 'vis' +str(soa) + '-invis' + str(soa), operator=evokedsubtract, conditions=[ dict(name='vis' + str(soa), include=dict(block='visible',soa=soa)), dict(name='invis_' + str(33), include=dict(block='invisible',soa=soa))]) contrast_block_soa.append(contrast) creating condition variables (e.g. absent, mid_soas, seen), so that you don't have to redefine them every time. Ideally, there shouldn't be any duplicates in your code. If you could help with the PAS x SOA, that would also be great

What are you trying to define? Whether the ERF vary as a function of PAS for each SOA? If so, it should be something like this?

regress_pas_soa = list() for idx, soa in enumerate([17, 33, 50, 67, 83]): regress = dict( name = 'pas_regress_soa' +str(soa), operator=evoked_subtract, conditions=[ dict(name='pas' + str(pas) + '_soa' + str(soa), include=dict(pas=pas,soa=soa), exclude=absent) for pas in range(4)]) regress_pas_soa.append(regress) — Reply to this email directly or view it on GitHub.

kingjr commented 9 years ago

This is to check the effect of visibility at trial t-N onto trial t:


fig, ax = plt.subplots(1)
for previous_seen, color in zip(['previous_seen', 'previous_unseen'], ['r', 'b']):
   decision = np.nan * np.zeros((n_subjects, 8))
   for c, soa in enumerate(soas):
       for subject, events in enumerate(events_list):
           sel = np.where((events['previous_motor_seen'] == previous_seen) &
                          (events['stim_active'] == 1) &
                          (events['stim_soa'] == soa))[0]
           decision[subject, c] = np.nanmean(events['motor_seen'][sel])
       ax = plot_soas(1 - decision, ax=ax, linecolor=color)
ax.set_xlabel('SOAs')
ax.set_ylabel('Proportion of seen response at trial t')
ax.set_title('Effect of trial t-1 onto seen response at t')
ax.set_ylim([0, 1])
ax.set_yticks([0., 1.])

# Effect of n previous decision on current decision
n_back = 20
decision = np.nan * np.zeros((n_subjects, n_back))
for subject, events in enumerate(events_list):
    for t in range(n_back):
        current_choices = np.array(events['motor_seen'][t:])
        previous_choices = np.array(events['motor_seen'][:-t])
        sel0 = np.where(previous_choices == 0)[0]
        sel1 = np.where(previous_choices == 1)[0]
        n0 = np.nanmean(current_choices[sel0])
        n1 = np.nanmean(current_choices[sel1])
        decision[subject, t] = n0 / (n0 + n1)

fig, ax = plt.subplots(1, figsize=[3., 3.])
ax = plot_sem(-np.arange(n_back), 1 - decision, color='k', ax=ax)
ax.axhline(.5, color='k', linestyle='--')
ax.set_xlabel('Trial distance')
ax.set_ylabel('Letter Response')
ax.set_xlim([-n_back + 1, -1])
ax.set_ylim([.49, .55])
ax.set_yticks([.49, .55])

from scipy.stats import wilcoxon
from mne.stats import fdr_correction
p_value = np.nan * np.zeros(n_back,)
for t in range(n_back):
    _, p_value[t] = wilcoxon(decision[:, t] - .5)

h, p_fdr = fdr_correction(p_value, alpha=0.05, method='indep')
ax.fill_between(-np.arange(n_back), .5 * np.ones(n_back,),
                0.5 + h * (np.nanmean(1 - decision, axis=0) - .5),
                color='yellow', alpha=.5, linewidth=0, label='p < .05',
                zorder=-1)
kingjr commented 9 years ago

I. visibility prior

II. target content prior

III. interaction between the two types of priors The model predicts that :

kingjr commented 9 years ago

start again the contrast definition ;)