In [1]:
%matplotlib inline
import numpy as np
from matplotlib import pyplot as plt
np.random.seednp.random.choice,np.random.shufflenp.random.normal,np.random.binomial,np.random.uniform,np.random.poissonplt.hist
In [2]:
x = np.arange(-10,10,0.2)
y = np.cos(x)
noisy_y = y + np.random.normal(0,0.3,len(y))
plt.plot(x,y)
plt.plot(x,noisy_y)
Out[2]:
You are measuring the length of microtubule bundles in S. pombe yeast.
Assuming your expectation is right, will you be able to tell that the mutant had any effect?
In [3]:
wildtype = np.random.normal(5,1.4,5)
mutant = np.random.normal(5.5,1.4,5)
print(wildtype)
print(mutant)
In [4]:
import scipy.stats
Figure out how to use scipy.stats.ttest_ind.
In [5]:
d = scipy.stats.ttest_ind(mutant,wildtype)
d.pvalue
Out[5]:
In [6]:
n_list = [5,10,50,100,500,1000]
p_list = []
for n in n_list:
wildtype = np.random.normal(5,1.4,n)
mutant = np.random.normal(5.5,1.4,n)
d = scipy.stats.ttest_ind(mutant,wildtype)
p_list.append(d.pvalue)
plt.plot(n_list,p_list,"-")
Out[6]:
In [7]:
d = scipy.stats.norm()
x = np.arange(-5,5,0.01)
prob_density = d.pdf(x)
cum_density = d.cdf(x)
In [8]:
def plot_distrib(d,x,name):
"""
Function that plots the probability density and cumulative density
functions of a distribution over the range defined in x.
"""
fig, ax = plt.subplots(1,2,figsize=(12,5))
ax[0].plot(x,d.pdf(x),"k-")
ax[0].set_title("Probability Density Function ({})".format(name))
ax[0].set_xlabel("x")
ax[0].set_ylabel("P(X == x)")
ax[1].plot(x,d.cdf(x),"k-")
ax[1].set_title("Cumulative Density Function ({})".format(name))
ax[1].set_xlabel("x")
ax[1].set_ylabel("P(X $\geq$ x)")
bottom = np.arange(np.min(x),d.interval(0.95)[0],0.01)
top = np.arange(d.interval(0.95)[1],np.max(x),0.01)
ax[0].fill_between(bottom,d.pdf(bottom),color="gray")
ax[0].fill_between(top,d.pdf(top),color="gray")
In [9]:
plot_distrib(d,x,"Normal $\mu = 0$, $\sigma = 1$")
In [10]:
pareto = scipy.stats.pareto(1)
x = range(1,50)
plot_distrib(pareto,x,"Pareto c = 1")
In [ ]: