Example #1
0
    def __init__(self,
                 y,
                 x,
                 c1=None,
                 c0=None,
                 match=None,
                 sub=None,
                 ds=None,
                 tail=0):
        ct = Celltable(y, x, match, sub, cat=(c1, c0), ds=ds, coercion=asvar)
        c1, c0 = ct.cat

        n = len(ct.y)
        if n <= 2:
            raise ValueError("Not enough observations for t-test (n=%i)" % n)

        self._y = dataobj_repr(ct.y)
        self._x = dataobj_repr(ct.x)
        self.df = n - 2
        groups = ct.x == c1
        groups.dtype = np.int8
        self.t = stats.t_ind(ct.y.x[:, None], groups)[0]
        self.p = stats.ttest_p(self.t, self.df, tail)
        self.tail = tail
        self._c1 = c1
        self._c0 = c0
Example #2
0
    def __init__(
        self,
        y: VarArg,
        x: CategorialArg,
        c1: CellArg = None,
        c0: CellArg = None,
        match: CategorialArg = None,
        sub: IndexArg = None,
        ds: Dataset = None,
        tail: int = 0,
    ):
        y, y1, y0, c1, c0, match, x_name, c1_name, c0_name = _independent_measures_args(
            y, x, c1, c0, match, ds, sub)

        n1 = len(y1)
        n = len(y)
        df = n - 2
        groups = np.arange(n) < n1
        groups.dtype = np.int8
        t = stats.t_ind(y.x[:, None], groups)[0]

        self._y = dataobj_repr(y)
        self._x = x_name
        TTest.__init__(self, t, df, tail)
        self._c1 = c1_name
        self._c0 = c0_name
        self._two_y = c1 is None
Example #3
0
def test_t_ind():
    "Test independent samples t-test"
    ds = datasets.get_uts(True)
    y = ds.eval("utsnd.x")
    n_cases = len(y)
    n = n_cases / 2

    t = stats.t_ind(y, n, n)
    p = stats.ttest_p(t, n_cases - 2)
    t_sp, p_sp = scipy.stats.ttest_ind(y[:n], y[n:])
    assert_equal(t, t_sp)
    assert_equal(p, p_sp)
    assert_allclose(stats.ttest_t(p, n_cases - 2), np.abs(t))

    # permutation
    y_perm = np.empty_like(y)
    for perm in permute_order(n_cases, 2):
        stats.t_ind(y, n, n, out=t, perm=perm)
        y_perm[perm] = y
        t_sp, _ = scipy.stats.ttest_ind(y_perm[:n], y_perm[n:])
        assert_allclose(t, t_sp)
def test_t_ind():
    "Test independent samples t-test"
    ds = datasets.get_uts(True)
    y = ds.eval("utsnd.x")
    n_cases = len(y)
    n = n_cases / 2

    t = stats.t_ind(y, n, n)
    p = stats.ttest_p(t, n_cases - 2)
    t_sp, p_sp = scipy.stats.ttest_ind(y[:n], y[n:])
    assert_equal(t, t_sp)
    assert_equal(p, p_sp)
    assert_allclose(stats.ttest_t(p, n_cases - 2), np.abs(t))

    # permutation
    y_perm = np.empty_like(y)
    for perm in permute_order(n_cases, 2):
        stats.t_ind(y, n, n, out=t, perm=perm)
        y_perm[perm] = y
        t_sp, _ = scipy.stats.ttest_ind(y_perm[:n], y_perm[n:])
        assert_allclose(t, t_sp)
Example #5
0
    def __init__(self, y, x, c1=None, c0=None, match=None, sub=None, ds=None,
                 tail=0):
        ct = Celltable(y, x, match, sub, cat=(c1, c0), ds=ds, coercion=asvar)
        c1, c0 = ct.cat

        n = len(ct.y)
        if n <= 2:
            raise ValueError("Not enough observations for t-test (n=%i)" % n)

        self._y = dataobj_repr(ct.y)
        self._x = dataobj_repr(ct.x)
        groups = ct.x == c1
        groups.dtype = np.int8
        t = stats.t_ind(ct.y.x[:, None], groups)[0]
        TTest.__init__(self, t, n - 2, tail)
        self._c1 = c1
        self._c0 = c0