0% found this document useful (0 votes)
13 views8 pages

lab5

Uploaded by

ngocthanh2821
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views8 pages

lab5

Uploaded by

ngocthanh2821
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

APPLIED STATISTICS

LAB
COURSE CODE: ENEE1020IU

Lab-works
Applications of Python
Part 5 – Hypothesis tests
(1 credit: 0 is for lecture, 1 is for lab-work)
Instructor: TRAN THANH TU
Email: [email protected]

[email protected] 117
Hypothesis tests with Python
Review
Parameter Hypothesis Distribution table
Population mean: Normal distribution
σ-known α

Population mean: T-distribution


σ-unknown α, df: n-1

Population proportion: Similar as Population mean: σ-known Normal distribution


α

[email protected] 118
Hypothesis tests with Python
Review
Parameter Hypothesis Distribution table
Paired t-Test for assessing the average T-distribution
of differences α, df: n-1

Independent t-Test for assessing the Normal distribution


difference of two averages: σ-known α/2

Margin of error
Independent t-Test for assessing the Similar as Population mean: σ-known T-distribution
difference of two averages: α/2, df:
σ-unknown t

or
or
α/2, df: n1+n2−2
(p1=p2=p)
Hypothesis tests about the difference Normal distribution
between the proportions of two α/2
populations

[email protected] 119
Hypothesis tests with Python
Tests whether the means of two paired
Paired t-test samples are significantly different.
from scipy.stats import ttest_rel
data1 = [0.873, 2.817, 0.121, -0.945, -0.055, -1.436, 0.360, -1.478, -1.637,
-1.869]
data2 = [1.142, -0.432, -0.938, -0.729, -0.846, -0.157, 0.500, 1.183, -1.075,
-0.169]
stat, p = ttest_rel(data1, data2) H0: the means of the samples are
equal.
print('stat=%.3f, p=%.3f' % (stat, p)) H1/Ha: the means of the samples
if p > 0.05: are unequal.
print('Probably the same distribution') In [1]: print('Slope: %.3f' % 1.123)
Slope: 1.123
else:
In [2]: print('Slope: %.3f' % 1.12345)
print('Probably different distributions') Slope: 1.123
In [3]: print('Slope: %.3f' % 1.1)
Slope: 1.100
In [4]: print('Slope: %.3f' % 1.1237)
Slope: 1.124 120
[email protected]
Hypothesis tests with Python
Tests whether two categorical variables
Chi-squared test are related or independent.

from scipy.stats import chi2_contingency


table = [[10, 20, 30],[6, 9, 17]]
stat, p, dof, expected = chi2_contingency(table)
print('stat=%.3f, p=%.3f' % (stat, p))
H0: the two samples are
if p > 0.05:
independent.
print('Probably independent') H1/Ha: there is a dependency
else: between the samples.
print('Probably dependent')

[email protected] 121
Hypothesis tests with Python
Tests whether the means of two
Independent t-test independent samples are significantly
different.
from scipy.stats import ttest_ind
data1 = [0.873, 2.817, 0.121, -0.945, -0.055, -1.436, 0.360, -1.478, -1.637,
-1.869]
data2 = [1.142, -0.432, -0.938, -0.729, -0.846, -0.157, 0.500, 1.183, -1.075,
-0.169]
stat, p = ttest_ind(data1, data2) H0: the means of the samples are
equal.
print('stat=%.3f, p=%.3f' % (stat, p)) H1/Ha: the means of the samples
if p > 0.05: are unequal.
print('Probably the same distribution')
else:
print('Probably different distributions')

[email protected] 122
Hypothesis tests with Python
Tests whether the means of two or more
ANOVA independent samples are significantly
different.
from scipy.stats import f_oneway
data1 = [0.873, 2.817, 0.121, -0.945, -0.055, -1.436, 0.360, -1.478, -1.637,
-1.869]
data2 = [1.142, -0.432, -0.938, -0.729, -0.846, -0.157, 0.500, 1.183, -1.075,
-0.169]
data3 = [-0.208, 0.696, 0.928, -1.148, -0.213, 0.229, 0.137, 0.269, -0.870, -
1.204]
stat, p = f_oneway(data1, data2, data3)
•H0: the means of the samples
print('stat=%.3f, p=%.3f' % (stat, p)) are equal.
if p > 0.05: •H1/Ha: one or more of the
means of the samples are
print('Probably the same distribution')
unequal.
else:
print('Probably different distributions')
[email protected] 123
Hypothesis tests with Python

Others:
https://docs.scipy.org/doc/scipy-0.14.0/reference/stats.html

[email protected] 124

You might also like