27

Pythonで作成したモデルに関する統計を生成したいと思っています。その上でt検定を生成したいのですが、numpy/scipyでこれを行う簡単な方法があるかどうか疑問に思いました。周りに良い説明はありますか?

たとえば、次のような3つの関連データセットがあります。

[55.0, 55.0, 47.0, 47.0, 55.0, 55.0, 55.0, 63.0]

それでは、スチューデントのt検定を行いたいと思います。

4

3 に答える 3

29

scipy.statsパッケージにはいくつかの関数がありttest_...ます。ここから例を参照してください:

>>> print 't-statistic = %6.3f pvalue = %6.4f' %  stats.ttest_1samp(x, m)
t-statistic =  0.391 pvalue = 0.6955
于 2010-02-24T08:10:17.423 に答える
-4

t 値を取得したら、それを確率として解釈する方法を疑問に思うかもしれませんが、私はそうしました。これを支援するために私が書いた関数があります。

これは、 http: //www.vassarstats.net/rsig.htmlおよびhttp://en.wikipedia.org/wiki/Student%27s_t_distributionから収集した情報に基づいています。

# Given (possibly random) variables, X and Y, and a correlation direction,
# returns:
#  (r, p),
# where r is the Pearson correlation coefficient, and p is the probability
# of getting the observed values if there is actually no correlation in the given
# direction.
#
# direction:
#  if positive, p is the probability of getting the observed result when there is no
#     positive correlation in the normally distributed full populations sampled by X
#     and Y
#  if negative, p is the probability of getting the observed result, when there is no
#     negative correlation
#  if 0, p is the probability of getting your result, if your hypothesis is true that
#    there is no correlation in either direction
def probabilityOfResult(X, Y, direction=0):
    x = len(X)
    if x != len(Y):
        raise ValueError("variables not same len: " + str(x) + ", and " + \
                         str(len(Y)))
    if x < 6:
        raise ValueError("must have at least 6 samples, but have " + str(x))
    (corr, prb_2_tail) = stats.pearsonr(X, Y)

    if not direction:
        return (corr, prb_2_tail)

    prb_1_tail = prb_2_tail / 2
    if corr * direction > 0:
        return (corr, prb_1_tail)

    return (corr, 1 - prb_1_tail)
于 2013-01-09T02:15:08.413 に答える