def test_dprime():
    """Test dprime and dprime_2afc accuracy."""
    assert_raises(TypeError, ea.dprime, 'foo', 0, 0, 0)
    with warnings.catch_warnings(record=True) as w:
        warnings.simplefilter('always')
        ea.dprime((1.1, 0, 0, 0))
    assert_equal(len(w), 1)
    for resp, want in (
            ((1, 1, 1, 1), [0, 0]),
            ((1, 0, 0, 1), [1.34898, 0.]),
            ((0, 1, 0, 1), [0, 0.67449]),
            ((0, 0, 1, 1), [0, 0]),
            ((1, 0, 1, 0), [0, -0.67449]),
            ((0, 1, 1, 0), [-1.34898, 0.]),
            ((0, 1, 1, 0), [-1.34898, 0.])):
        assert_allclose(ea.dprime(resp, return_bias=True),
                        want, atol=1e-5)
    assert_allclose([np.inf, -np.inf], ea.dprime((1, 0, 2, 1), False, True))
    assert_equal(ea.dprime((5, 0, 1, 0)), ea.dprime_2afc((5, 1)))
    assert_raises(ValueError, ea.dprime, np.ones((5, 4, 3)))
    assert_raises(ValueError, ea.dprime, (1, 2, 3))
    assert_raises(ValueError, ea.dprime_2afc, (1, 2, 3))
    assert_equal(np.sum(ea.dprime_2afc([[5, 1], [1, 5]])), 0)
    # test simple larger dimensionality support
    assert_equal(ea.dprime((5, 0, 1, 0)), ea.dprime([[[5, 0, 1, 0]]])[0][0])
def test_dprime():
    """Test dprime and dprime_2afc accuracy
    """
    assert_raises(TypeError, ea.dprime, 'foo', 0, 0, 0)
    with warnings.catch_warnings(record=True) as w:
        warnings.simplefilter('always')
        ea.dprime((1.1, 0, 0, 0))
    assert_equal(len(w), 1)
    assert_equal(0, ea.dprime((1, 0, 1, 0)))
    assert_equal(np.inf, ea.dprime((1, 0, 2, 1), False))
    assert_equal(ea.dprime((5, 0, 1, 0)), ea.dprime_2afc((5, 1)))
    assert_raises(ValueError, ea.dprime, np.ones((5, 4, 3)))
    assert_raises(ValueError, ea.dprime, (1, 2, 3))
    assert_raises(ValueError, ea.dprime_2afc, (1, 2, 3))
    assert_equal(np.sum(ea.dprime_2afc([[5, 1], [1, 5]])), 0)
Example #3
0
def test_dprime():
    """Test dprime and dprime_2afc accuracy."""
    assert_raises(TypeError, ea.dprime, 'foo', 0, 0, 0)
    with warnings.catch_warnings(record=True) as w:
        warnings.simplefilter('always')
        ea.dprime((1.1, 0, 0, 0))
    assert_equal(len(w), 1)
    assert_equal(0, ea.dprime((1, 0, 1, 0)))
    assert_equal(np.inf, ea.dprime((1, 0, 2, 1), False))
    assert_equal(ea.dprime((5, 0, 1, 0)), ea.dprime_2afc((5, 1)))
    assert_raises(ValueError, ea.dprime, np.ones((5, 4, 3)))
    assert_raises(ValueError, ea.dprime, (1, 2, 3))
    assert_raises(ValueError, ea.dprime_2afc, (1, 2, 3))
    assert_equal(np.sum(ea.dprime_2afc([[5, 1], [1, 5]])), 0)
    # test simple larger dimensionality support
    assert_equal(ea.dprime((5, 0, 1, 0)), ea.dprime([[[5, 0, 1, 0]]])[0][0])
Example #4
0
def test_dprime():
    """Test dprime and dprime_2afc accuracy."""
    assert_raises(TypeError, ea.dprime, 'foo', 0, 0, 0)
    with warnings.catch_warnings(record=True) as w:
        warnings.simplefilter('always')
        ea.dprime((1.1, 0, 0, 0))
    assert_equal(len(w), 1)
    for resp, want in (((1, 1, 1, 1), [0, 0]), ((1, 0, 0, 1), [1.34898, 0.]),
                       ((0, 1, 0, 1), [0, 0.67449]), ((0, 0, 1, 1), [0, 0]),
                       ((1, 0, 1, 0), [0, -0.67449]),
                       ((0, 1, 1, 0), [-1.34898,
                                       0.]), ((0, 1, 1, 0), [-1.34898, 0.])):
        assert_allclose(ea.dprime(resp, return_bias=True), want, atol=1e-5)
    assert_allclose([np.inf, -np.inf], ea.dprime((1, 0, 2, 1), False, True))
    assert_equal(ea.dprime((5, 0, 1, 0)), ea.dprime_2afc((5, 1)))
    assert_raises(ValueError, ea.dprime, np.ones((5, 4, 3)))
    assert_raises(ValueError, ea.dprime, (1, 2, 3))
    assert_raises(ValueError, ea.dprime_2afc, (1, 2, 3))
    assert_equal(np.sum(ea.dprime_2afc([[5, 1], [1, 5]])), 0)
    # test simple larger dimensionality support
    assert_equal(ea.dprime((5, 0, 1, 0)), ea.dprime([[[5, 0, 1, 0]]])[0][0])
Example #5
0
import matplotlib.pyplot as plt
import expyfun.analyze as ea

# simulate some 2AFC data
trials = 100
c_prob = 0.9
t_prob = 0.6
subjs = ['a', 'b', 'c', 'd', 'e']
ctrl = np.random.binomial(trials, c_prob, len(subjs))
test = np.random.binomial(trials, t_prob, len(subjs))
ctrl_miss = trials - ctrl
test_miss = trials - test
data = pd.DataFrame(dict(ctrl_hit=ctrl, ctrl_miss=ctrl_miss,
                         test_hit=test, test_miss=test_miss), index=subjs)
# calculate dprimes
ctrl_dprime = ea.dprime_2afc(data[['ctrl_hit', 'ctrl_miss']])
test_dprime = ea.dprime_2afc(data[['test_hit', 'test_miss']])
results = pd.DataFrame(dict(ctrl=ctrl_dprime, test=test_dprime))
# plot
plt.ion()
subplt, barplt = ea.barplot(results, axis=0, err_bars='sd', lines=True,
                            brackets=[(0, 1)], bracket_text=[r'$p < 10^{-9}$'])
subplt.yaxis.set_label_text('d-prime +/- 1 s.d.')
subplt.set_title('Each line represents a different subject')

# significance brackets example
trials_per_cond = 100
conds = ['ctrl', 'test']
diffs = ['easy', 'hard']
colnames = ['-'.join([x, y]) for x, y in zip(conds * 2,
            np.tile(diffs, (2, 1)).T.ravel().tolist())]
Example #6
0
print(__doc__)

# simulate some 2AFC data
trials = 100
c_prob = 0.9
t_prob = 0.6
subjs = ['a', 'b', 'c', 'd', 'e']
ctrl = np.random.binomial(trials, c_prob, len(subjs))
test = np.random.binomial(trials, t_prob, len(subjs))
ctrl_miss = trials - ctrl
test_miss = trials - test
data = pd.DataFrame(dict(ctrl_hit=ctrl, ctrl_miss=ctrl_miss,
                         test_hit=test, test_miss=test_miss), index=subjs)
# calculate dprimes
ctrl_dprime = ea.dprime_2afc(data[['ctrl_hit', 'ctrl_miss']])
test_dprime = ea.dprime_2afc(data[['test_hit', 'test_miss']])
results = pd.DataFrame(dict(ctrl=ctrl_dprime, test=test_dprime))
# plot
plt.ion()
subplt, barplt = ea.barplot(results, axis=0, err_bars='sd', lines=True,
                            brackets=[(0, 1)], bracket_text=[r'$p < 10^{-9}$'])
subplt.yaxis.set_label_text('d-prime +/- 1 s.d.')
subplt.set_title('Each line represents a different subject')

# significance brackets example
trials_per_cond = 100
conds = ['ctrl', 'test']
diffs = ['easy', 'hard']
colnames = ['-'.join([x, y]) for x, y in zip(conds * 2,
            np.tile(diffs, (2, 1)).T.ravel().tolist())]
Example #7
0
# License: BSD (3-clause)

print(__doc__)

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import expyfun.analyze as ea

# simulate some 2AFC data
trials = 100
c_prob = 0.9
t_prob = 0.6
subjs = ['a', 'b', 'c', 'd', 'e']
ctrl = np.random.binomial(trials, c_prob, len(subjs))
test = np.random.binomial(trials, t_prob, len(subjs))
ctrl_miss = trials - ctrl
test_miss = trials - test
data = pd.DataFrame(dict(ctrl_hit=ctrl, ctrl_miss=ctrl_miss,
                         test_hit=test, test_miss=test_miss), index=subjs)
# calculate dprimes
ctrl_dprime = ea.dprime_2afc(data[['ctrl_hit', 'ctrl_miss']])
test_dprime = ea.dprime_2afc(data[['test_hit', 'test_miss']])
results = pd.DataFrame(dict(ctrl=ctrl_dprime, test=test_dprime))
# plot
plt.ion()
subplt, barplt = ea.barplot(results, axis=0, err_bars='sd', lines=True,
                            brackets=[(0, 1)], bracket_text=[r'$p < 10^{-9}$'])
subplt.yaxis.set_label(u'd-prime ± 1 s.d.')
subplt.set_title('Each line represents a different subject')