You are trying to measure a difference in the $K_{D}$ of two proteins binding to a ligand. From previous experiments, you know that the values of replicate measurements of $K_{D}$ follow a normal distribution with $\sigma = 2\ \mu M$. How many measurements would you need to make to confidently tell the difference between two proteins with $K_{D} = 10 \mu M$ and $K_{D} = 12 \mu M$?
In [1]:
%matplotlib inline
from matplotlib import pyplot as plt
import numpy as np
from scipy import stats
replicates = range(2,50)
p_values = []
for i in replicates:
measure_one = np.random.normal(10,2,i)
measure_two = np.random.normal(12,2,i)
p_values.append(stats.ttest_ind(measure_one,measure_two)[1])
plt.plot(replicates,p_values)
Out[1]:
In [2]:
%matplotlib inline
import numpy as np
from matplotlib import pyplot as plt
In [3]:
# best solution
tosses = np.random.choice([0,1],1000)
In [4]:
# okay solution
tosses = []
for i in range(1000):
tosses.append(np.random.choice([0,1]))
In [5]:
numbers = np.random.random(100000)
plt.hist(numbers)
Out[5]:
In [6]:
def simple_psuedo_random(current_value,
multiplier=13110243,
divisor=13132):
return current_value*multiplier % divisor
In [7]:
seed = 10218888
out = []
current = seed
for i in range(1000):
current = simple_psuedo_random(current)
out.append(current)
plt.hist(out)
Out[7]:
In [8]:
seed = 1021888
out = []
current = seed
for i in range(1000):
current = simple_psuedo_random(current)
out.append(current)
In [9]:
s1 = np.random.random(10)
print(s1)
In [10]:
np.random.seed(5235412)
s1 = np.random.random(10)
print(s1)
In [11]:
numbers = np.random.normal(size=10000)
counts, bins, junk = plt.hist(numbers,
range(-10,10))
In [12]:
np.random.normal
# returns number(s) drawn from normal distribution.
# arguments of interest: loc (mean), scale (std deviation), size (number of samples)
np.random.binomial
# returns number(s) drawn from binomial distribution.
# arguments of interest: n, p (parameters for binomial), size (number of samples)
np.random.uniform
# returns number(s) drawn from uniform distribution.
# arguments of interest: low (lowest possible number), high (highest possible number), size (number of samples)
np.random.poisson
# returns number(s) drawn from a poission distribution
# arguments of interest: lam (lambda), size (number of samples)
np.random.choice
# chooses a random number from a list or array
# arguments of interest: a (array), size (number to draw), replace (whether or not to draw with replacement), p (weighted probability of each entry in array)
np.random.shuffle
# shuffle the order of entries in an array
# it does not return anything, just changes the array in place. This means:
# a = np.array([1,2,3])
# np.random.shuffle(a)
# print(a) --> [3,1,2]
Out[12]:
In [13]:
x = np.random.normal(5,2,size=1000)
counts, edges, _ = plt.hist(x,bins=range(-15,15))
for i in range(len(counts)):
print(edges[i],counts[i])
In [ ]: