Skip to content

Instantly share code, notes, and snippets.

@bryan-lunt
Created May 8, 2014 22:22
Show Gist options
  • Save bryan-lunt/9071f6edd4da946fc8b9 to your computer and use it in GitHub Desktop.
Save bryan-lunt/9071f6edd4da946fc8b9 to your computer and use it in GitHub Desktop.
Calculate and graph the probabilities of only N (or fewer) female speakers at a conference of M, at various compositions of female/male for the field.
#!/usr/bin/env python
import scipy as S
import scipy.misc as MISC
import pylab
ticks=100
KP = 26
F = 1
def prob(k,n,p):
return MISC.comb(n,k)*S.power(p,k)*(S.power(1.0-p, (n-k)))
def integrate(k,n,p):
return sum([prob(j,n,p) for j in range(k+1)])
axis = S.linspace(0.05,0.5,ticks)
values = [prob(F,KP,myp) for myp in axis]
values_int = [integrate(F, KP, myp) for myp in axis]
pylab.plot(axis,values, label="prob(F==1)")
pylab.plot(axis,values_int, label="prob(F<=1)")
pylab.legend()
pylab.suptitle("Probabilities for NP=26 with varying P(F)")
pylab.xlabel("P(F) (probability of a female in random draw.)")
pylab.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment