Professional Documents
Culture Documents
July 3, 2017
In [36]: # libraries
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import scipy.stats as stats
import pylab
# colors
green = '#7fc97f'
purple = '#beaed4'
organe = '#fdc086'
yellow = '#ffff99'
blue = '#386cb0'
df = pd.read_csv('data/human_body_temperature.csv')
In [16]: df.head()
1
plt.show()
plt.clf()
According to the histogram we can see that the distribution is very normal except slightly
skewed to the right. We can also further test this using qqplot.
2
According to the qqplot, it is evident that the distribution is very normal.
Out[47]: 130
Since the sample = 130 > 30, we conclude that it is large enough.
The observations are independent.
3
In [104]: p_value = stats.ttest_1samp(df.temperature, popmean = 98.6)
p_value
Since p-value < 0.05, we reject the null hypothesis and conclude that the true population cannot
be 98.6.
1.0.5 5. Is there a significant difference between males and females in normal temperature?
We can test this using: * Overlap * Probability of superiority * Pooled variance
4
Overlap
In [79]: threshold = (female_mean * n1 + male_mean * n2)/(n1 + n2) # need need to w
threshold
Out[79]: 98.24923076923076
Out[88]: 0.42307692307692313
The misclassification rate is really high, which mean there is not much difference between 2
distribution.
Probability of Superiority
In [96]: new_female_temp = np.random.choice(female_temp, n1, replace=True)
new_male_temp = np.random.choice(male_temp, n2, replace=True)
sum(x > y for x,y in zip(new_female_temp, new_male_temp))/n1
Out[96]: 0.53846153846153844
Since the probability of superiority is not really high (close to 90%), we cannot tell there is a
difference between body temperature of female and male. However, we still need pooled variance
to prove rigorously.
5
Pooled Variance H0 : The difference between 2 distribution is 0.
Out[114]: 0.40089173785982207
Since 0.40 is too big for the default significant level 0.05, we conclude that there NO difference
between the body temperature of female and male.