Пример #1
0
def test_hotelling4():
#    Hotelling T^2 should just be like taking product with sphere.

    x = np.linspace(0.1,10,100)

    for dim in range(7):
        search = rft.IntrinsicVolumes([0]*(dim) + [1])
        for k in range(5, 10):
            p = rft.spherical_search(k)
            for dfd in [np.inf,40,50]:
                f = rft.FStat(dfd=dfd, dfn=1)(x, search=p*search)
                t = 2*rft.TStat(dfd=dfd)(np.sqrt(x), search=p*search)
                h2 = 2*rft.Hotelling(k=k, dfd=dfd).density(x, dim)
                h = 2*rft.Hotelling(k=k, dfd=dfd)(x, search=search)

                yield assert_almost_equal, h, t
                yield assert_almost_equal, h, f
                yield assert_almost_equal, h, h2
    search = rft.IntrinsicVolumes([3,4,5])
    for k in range(5, 10):
        p = rft.spherical_search(k)
        for dfd in [np.inf,40,50]:
            f = rft.FStat(dfd=dfd, dfn=1)(x, search=p*search)
            h = 2*rft.Hotelling(k=k, dfd=dfd)(x, search=search)

            h2 = 0
            for i in range(search.mu.shape[0]):
                h2 += 2*rft.Hotelling(k=k, dfd=dfd).density(x, i) * search.mu[i]
            yield assert_almost_equal, h, f
            yield assert_almost_equal, h, h2
Пример #2
0
def test_hotelling2():
    #     Marginally, Hotelling's T^2(k) with m degrees of freedom
    #     in the denominator satisfies

    #     (m-k+1)/(mk) T^2 \sim  F_{k,m-k+1}.

    x = np.linspace(0.1, 10, 100)
    for dfn in range(6, 10):

        h = rft.Hotelling(k=dfn)(x)
        chi = rft.ChiSquared(dfn=dfn)(x)
        assert_almost_equal(h, chi)
        chi2 = scipy.stats.chi2.sf(x, dfn)
        yield assert_almost_equal, h, chi2

        p = rft.spherical_search(dfn)
        for dfd in [40, 50]:
            fac = (dfd - dfn + 1.0) / (dfd * dfn)
            h = rft.Hotelling(dfd=dfd, k=dfn)(x)
            f = scipy.stats.f.sf(x * fac, dfn, dfd - dfn + 1)
            f2 = rft.FStat(dfd=dfd - dfn + 1, dfn=dfn)(x * fac)
            yield assert_almost_equal, f2, f
            yield assert_almost_equal, h, f