15.12.2012 Views

scipy tutorial - Baustatik-Info-Server

scipy tutorial - Baustatik-Info-Server

scipy tutorial - Baustatik-Info-Server

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

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

>>> np.random.seed(987654321) # set random seed to get the same result<br />

>>> kstest(’norm’,’’,N=100)<br />

(0.058352892479417884, 0.88531190944151261)<br />

is equivalent to this<br />

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

>>> kstest(stats.norm.rvs(size=100),’norm’)<br />

(0.058352892479417884, 0.88531190944151261)<br />

Test against one-sided alternative hypothesis:<br />

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

Shift distribution to larger values, so that cdf_dgp(x)< norm.cdf(x):<br />

>>> x = stats.norm.rvs(loc=0.2, size=100)<br />

>>> kstest(x,’norm’, alternative = ’less’)<br />

(0.12464329735846891, 0.040989164077641749)<br />

Reject equal distribution against alternative hypothesis: less<br />

>>> kstest(x,’norm’, alternative = ’greater’)<br />

(0.0072115233216311081, 0.98531158590396395)<br />

Don’t reject equal distribution against alternative hypothesis: greater<br />

>>> kstest(x,’norm’, mode=’asymp’)<br />

(0.12464329735846891, 0.08944488871182088)<br />

Testing t distributed random variables against normal distribution:<br />

With 100 degrees of freedom the t distribution looks close to the normal distribution, and the kstest does not<br />

reject the hypothesis that the sample came from the normal distribution<br />

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

>>> stats.kstest(stats.t.rvs(100,size=100),’norm’)<br />

(0.072018929165471257, 0.67630062862479168)<br />

With 3 degrees of freedom the t distribution looks sufficiently different from the normal distribution, that we<br />

can reject the hypothesis that the sample came from the normal distribution at a alpha=10% level<br />

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

>>> stats.kstest(stats.t.rvs(3,size=100),’norm’)<br />

(0.131016895759829, 0.058826222555312224)<br />

chisquare(f_obs, f_exp=None, ddof=0)<br />

Calculates a one-way chi square test.<br />

The chi square test tests the null hypothesis that the categorical data has the given frequencies.<br />

Parameters<br />

f_obs : array<br />

observed frequencies in each category<br />

f_exp : array, optional<br />

3.18. Statistical functions (<strong>scipy</strong>.stats) 659

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

Saved successfully!

Ooh no, something went wrong!