Normals Script

Overview

The example generates the Normal Distribution density function and plots it in an area chart. The normal distribution is provided by the normal library and is imported as in the following.

let nm = await import('/lib/statistics/distributions/normal/v1.0.0/normal.mjs');


Next, the library is used to generate the set of points in the chart. The following code utilizes the $from utility create a set of 101 points from -3 to 3, and then calculating the normal density at that point.

let series = $from(-3, 3, 101).map(p=>({ x:p, normal:nm.density(p, 0, 1), }));


As a final step, we tie the mean value of one of the distributions to the value of the slider by calling the $val utility.

$val('slider')

Script

(async ()=>{ let nm = await import('/code/normal/v1.0.0/normal.mjs'); let series = $from(-3, 3, 101).map(p=>({ x:p, normal:nm.density(p, 0, 1), })); let series2 = $from(-3, 3, 101).map(p=>({ x:p, normal:nm.density(p, (parseInt($val('slider'))-50)/20, 0.5), })); $val.set('data', series); $val.set('data2', series2); })();