Used frequently to represent real-valued random variables whose distributions are not known.
Its importance is derived from the central limit theorem that states, under some conditions, the average of many samples of a random variable is itself a random variable that converges to a Gaussian distribution as it increases.
\(E[X] = \mu\)
\(Var[X] = \sigma^{2}\)
viewof mu = Inputs.range([-1,1], {step:0.1,value:0,label:tex`\mu`,width:200})viewof sigma = Inputs.range([0.1,2], {step:0.1,value:1,label:tex`\sigma`,width:200})// Generate points for the normal distribution curvepointsGaussian = {const x = d3.range(-5,5,0.1);return x.map(x => ({ x,y: (1/ (sigma *Math.sqrt(2*Math.PI))) *Math.exp(-0.5*Math.pow((x - mu) / sigma,2)) }));}Plot.plot({style:"overflow: visible; display: block; margin: 0 auto;",width:600,height:400,y: {grid:true,label:"Density" },x: {label:"x",domain: [-5,5] },marks: [ Plot.line(pointsGaussian, {x:"x",y:"y",stroke:"steelblue"}), Plot.ruleY([0]) ]})
viewof alpha = Inputs.range([0.1,10], {step:0.1,value:1,label:tex`\alpha`,width:200})viewof beta = Inputs.range([0.1,10], {step:0.1,value:1,label:tex`\beta`,width:200})// Gamma function approximation using Lanczos approximationfunctiongamma(z) {const p = [676.5203681218851,-1259.1392167224028,771.32342877765313,-176.61502916214059,12.507343278686905,-0.13857109526572012,9.9843695780195716e-6,1.5056327351493116e-7];if (z <0.5) {returnMath.PI/ (Math.sin(Math.PI* z) *gamma(1- z)); } z -=1;let x =0.99999999999980993;for (let i =0; i < p.length; i++) { x += p[i] / (z + i +1); }const t = z + p.length-0.5;returnMath.sqrt(2*Math.PI) *Math.pow(t, z +0.5) *Math.exp(-t) * x;}// Beta function using gamma functionfunctionbetaFunc(x, y) {return (gamma(x) *gamma(y)) /gamma(x + y);}// Beta probability density functionfunctionbetaPDF(x, a, b) {if (x <=0|| x >=1) return0;returnMath.pow(x, a -1) *Math.pow(1- x, b -1) /betaFunc(a, b);}// Generate points for the beta distribution curvepoints =Array.from({length:100}, (_, i) => {let x =0.001+ i *0.01;return { x,y:betaPDF(x, alpha, beta) };});Plot.plot({style:"overflow: visible; display: block; margin: 0 auto;",width:600,height:400,y: {grid:true,label:"Density" },x: {label:"x",domain: [0,1] },marks: [ Plot.line(points, {x:"x",y:"y",stroke:"steelblue"}), Plot.ruleY([0]) ]})