15.12.2012 Views

scipy tutorial - Baustatik-Info-Server

scipy tutorial - Baustatik-Info-Server

scipy tutorial - Baustatik-Info-Server

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

SciPy Reference Guide, Release 0.8.dev<br />

Examples<br />

>>> from <strong>scipy</strong> import stats<br />

>>> import numpy as np<br />

>>> #fix seed to get the same result<br />

>>> np.random.seed(7654567)<br />

>>> rvs = stats.norm.rvs(loc=5,scale=10,size=(50,2))<br />

test if mean of random sample is equal to true mean, and different mean. We reject the null hypothesis in the<br />

second case and don’t reject it in the first case<br />

>>> stats.ttest_1samp(rvs,5.0)<br />

(array([-0.68014479, -0.04323899]), array([ 0.49961383, 0.96568674]))<br />

>>> stats.ttest_1samp(rvs,0.0)<br />

(array([ 2.77025808, 4.11038784]), array([ 0.00789095, 0.00014999]))<br />

examples using axis and non-scalar dimension for population mean<br />

>>> stats.ttest_1samp(rvs,[5.0,0.0])<br />

(array([-0.68014479, 4.11038784]), array([ 4.99613833e-01, 1.49986458e-04]))<br />

>>> stats.ttest_1samp(rvs.T,[5.0,0.0],axis=1)<br />

(array([-0.68014479, 4.11038784]), array([ 4.99613833e-01, 1.49986458e-04]))<br />

>>> stats.ttest_1samp(rvs,[[5.0],[0.0]])<br />

(array([[-0.68014479, -0.04323899],<br />

[ 2.77025808, 4.11038784]]), array([[ 4.99613833e-01, 9.65686743e-01],<br />

[ 7.89094663e-03, 1.49986458e-04]]))<br />

ttest_rel(a, b, axis=None)<br />

Calculates the T-test on TWO RELATED samples of scores, a and b.<br />

This is a two-sided test for the null hypothesis that 2 related or repeated samples have identical average (expected)<br />

values.<br />

Notes<br />

Parameters<br />

a, b : sequence of ndarrays<br />

The arrays must have the same shape.<br />

axis : int, optional, (default axis=0)<br />

Axis can equal None (ravel array first), or an integer (the axis over which to operate<br />

on a and b).<br />

Returns<br />

t : float or array<br />

t-statistic<br />

prob : float or array<br />

two-tailed p-value<br />

Examples for the use are scores of the same set of student in different exams, or repeated sampling from the<br />

same units. The test measures whether the average score differs significantly across samples (e.g. exams). If<br />

we observe a large p-value, for example greater than 0.05 or 0.1 then we cannot reject the null hypothesis of<br />

identical average scores. If the p-value is smaller than the threshold, e.g. 1%, 5% or 10%, then we reject the<br />

null hypothesis of equal averages. Small p-values are associated with large t-statistics.<br />

694 Chapter 3. Reference

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!