Ejemplo n.º 1
0
def effect_se(dm, start=0, end=None):

    """
	desc:
		Gets the standard error of the differencein pupil size between dark and
		bright trials during a time window.

	arguments:
		dm:
			type: DataMatrix

	keywords:
		start:	The start time.
		end:	The end time, or None for trace end.

	returns:
		type:
			ndarrray
	"""

    dm_bright = dm.type == "light"
    dm_dark = dm.type == "dark"
    bright = series.reduce_(series.window(dm_bright.pupil, start=start, end=end))
    dark = series.reduce_(series.window(dm_dark.pupil, start=start, end=end))
    diff = dark.mean - bright.mean
    se = ((bright.std ** 2 / len(bright)) + (dark.std ** 2 / len(dark))) ** 0.5
    return diff, se
Ejemplo n.º 2
0
def lmer_series(dm, formula, winlen=1):

	col = formula.split()[0]
	depth = dm[col].depth
	rm = None
	for i in range(0, depth, winlen):
		wm = dm[:]
		wm[col] = series.reduce_(
			series.window(wm[col], start=i, end=i+winlen))
		lm = lmer(wm, formula)
		print('Sample %d' % i)
		print(lm)
		if rm is None:
			rm = DataMatrix(length=len(lm))
			rm.effect = list(lm.effect)
			rm.p = SeriesColumn(depth=depth)
			rm.t = SeriesColumn(depth=depth)
			rm.est = SeriesColumn(depth=depth)
			rm.se = SeriesColumn(depth=depth)
		for lmrow, rmrow in zip(lm, rm):
			rmrow.p[i:i+winlen] = lmrow.p
			rmrow.t[i:i+winlen] = lmrow.t
			rmrow.est[i:i+winlen] = lmrow.est
			rmrow.se[i:i+winlen] = lmrow.se
	return rm
Ejemplo n.º 3
0
def glmer_series(dm, formula, family, winlen=1):

    col = formula.split()[0]
    depth = dm[col].depth
    rm = None
    for i in range(0, depth, winlen):
        wm = dm[:]
        wm[col] = series.reduce_(
            series.window(wm[col], start=i, end=i + winlen))
        lm = glmer(wm, formula, family=family)
        print('Sample %d' % i)
        print(lm)
        if rm is None:
            rm = DataMatrix(length=len(lm))
            rm.effect = list(lm.effect)
            rm.p = SeriesColumn(depth=depth)
            rm.z = SeriesColumn(depth=depth)
            rm.est = SeriesColumn(depth=depth)
            rm.se = SeriesColumn(depth=depth)
        for lmrow, rmrow in zip(lm, rm):
            rmrow.p[i:i + winlen] = lmrow.p
            rmrow.z[i:i + winlen] = lmrow.z
            rmrow.est[i:i + winlen] = lmrow.est
            rmrow.se[i:i + winlen] = lmrow.se
    return rm
def test_window():

    dm = DataMatrix(length=2)
    dm.series = SeriesColumn(depth=4)
    dm.series[0] = 0, 1, 1, 0
    dm.series[1] = 0, 2, 2, 0
    dm.window = series.window(dm.series, 1, 3)
    check_series(dm.window, [[1, 1], [2, 2]])
    check_integrity(dm)
Ejemplo n.º 5
0
def size(dm, start=0, end=None):

    """
	desc:
		Gets the mean pupil size during a time window.

	arguments:
		dm:
			type: DataMatrix

	keywords:
		start:	The start time.
		end:	The end time, or None for trace end.

	returns:
		type:
			ndarrray
	"""

    return series.reduce_(series.window(dm.pupil, start=start, end=end)).mean
Ejemplo n.º 6
0
def size_se(dm, start=0, end=None):

    """
	desc:
		Gets the pupil-size standard error during a time window.

	arguments:
		dm:
			type: DataMatrix

	keywords:
		start:	The start time.
		end:	The end time, or None for trace end.

	returns:
		type:
			ndarrray
	"""

    s = series.reduce_(series.window(dm.pupil, start=start, end=end))
    return s.mean, s.std / len(s) ** 0.5
def interactiontest(dm):

    dm.bl = baseline.baseline(dm)
    dm.test = srs.reduce_(srs.window(dm.y, start=-50, end=-1))

    lmdata = DataMatrix(length=len(dm) * 2)
    lmdata.pupil = -1
    lmdata.time = -1
    lmdata.condition = -1
    lmdata.trialid = -1
    for i, row in enumerate(dm):
        lmdata.pupil[2 * i] = row.bl
        lmdata.time[2 * i] = 0
        lmdata.condition[2 * i] = row.c
        lmdata.trialid[2 * i] = i
        lmdata.pupil[2 * i + 1] = row.test
        lmdata.time[2 * i + 1] = 1
        lmdata.condition[2 * i + 1] = row.c
        lmdata.trialid[2 * i + 1] = i
    lm = lme4.lmer(lmdata, 'pupil ~ condition*time + (1|trialid)')
    print(lm.p[3])
    return lm.p[3] < ALPHA
Ejemplo n.º 8
0
def ttest(dm, col):

    a1 = srs.reduce_(srs.window((dm.c == 1)[col], start=-50, end=-1))
    b1 = srs.reduce_(srs.window((dm.c == 2)[col], start=-50, end=-1))
    t, p = stats.ttest_ind(a1, b1)
    return p < ALPHA and t < 0, p < ALPHA and t > 0
Ejemplo n.º 9
0
def baseline(dm):

    return srs.reduce_(srs.window(dm.y, start=BASELINE[0], end=BASELINE[1]),
                       operation=REDUCEFNC)