Y = Ke-(X-M)2/(2σ2)
X,Y | are the curve's x,y coordinates (used for plotting, etc.) |
K | is the maximum Y coordinate; used to scale the Y coordinates
(height in Y units) |
M | is the curve's mathematical mean (X coordinate of the mean) |
σ | is the curve's standard deviation;
determines how fat or skinny the curve is (width in X units) |
e | is Euler's number; is a constant; is an irrational number (defined in the Python numpy module and other libraries) |
With this equation the user can:
# ------------------------------------------------------------------- # ---- return the bell curve's y coordinate for a given x coordinate # ---- x bell curve x coordinate # ---- ymax bell curve data arithmetic mean (y coordinate) # ---- mean bell curve data arithmetic mean (x coordinate) # ---- sd bell curve data standard deviation # ------------------------------------------------------------------- import numpy as np def BellCurveValue(x,ymax,mean,sd): y = ymax * pow(np.e,-pow(x-mean,2.0)/(2.0*sd*sd)) return y
# ------------------------------------------------------------------ # ---- return a list of random samples from a population list # ---- poplst - population data list # ---- samsiz - size of sample # ------------------------------------------------------------------ import numpy as np import random def RandomSample(poplst,samsiz): poplen = len(poplst) # ---- collect samsiz samples sam = [] # list of samples for _ in range(samsiz): i = random.randint(0,poplen-1) sam.append(poplst[i]) # ---- calculate mean and standard deviation avg = np.mean(sam) # average (mean) std = np.std(sam) # standard deviation return (sam,avg,std)
Formula for the Normal Distribution or Bell Curve
Note: This has a slightly different version of the equation.
Read the article for more information.
Standard Deviation (Wikipedia)
Normal Distribution (Wikipedia)