Published
Edited
Dec 7, 2018
4 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
stdlib = require( "https://unpkg.com/@stdlib/stdlib@0.0.32/dist/stdlib-flat.min.js" )
Insert cell
Insert cell
stdlib.base.dists.beta.pdf( 0.25, 5.0, 1.0 )
Insert cell
Insert cell
x = stdlib.linspace( 0.00001, 0.99999, 500 )
Insert cell
Insert cell
Insert cell
function pdf( /* [out,] x, alpha, beta */ ) {
var alpha;
var beta;
var out;
var x;
var i;
// Argument juggling...
if ( arguments.length < 4 ) {
x = arguments[ 0 ];
alpha = arguments[ 1 ];
beta = arguments[ 2 ];
out = new Array( x.length );
} else {
out = arguments[ 0 ];
x = arguments[ 1 ];
alpha = arguments[ 2 ];
beta = arguments[ 3 ];
}
// Evaluate the pdf for each value in `x`...
for ( i = 0; i < x.length; i++ ) {
out[ i ] = stdlib.base.dists.beta.pdf( x[ i ], alpha, beta );
}
return out;
}
Insert cell
Insert cell
y = pdf( x, 5.0, 1.0 )
Insert cell
Insert cell
plt1 = stdlib.plot( [x], [y] )
Insert cell
Insert cell
plt1_config = {
plt1.title = 'Beta Distribution Probability Density Function';
plt1.yLabel = 'pdf';
}
Insert cell
Insert cell
out = plt1.render()
Insert cell
Insert cell
vdom2html = require( "https://wzrd.in/standalone/vdom-to-html@2.1" )
Insert cell
Insert cell
Insert cell
str = vdom2html( plt1.render() )
Insert cell
Insert cell
html`${str}`
Insert cell
Insert cell
Insert cell
pdfs = {
var y1 = pdf( x, 0.5, 0.5 );
var y2 = pdf( x, 5.0, 1.0 );
var y3 = pdf( x, 1.0, 3.0 );
var y4 = pdf( x, 2.0, 2.0 );
var y5 = pdf( x, 2.0, 5.0 );
return [ y1, y2, y3, y4, y5 ];
}
Insert cell
Insert cell
plt2 = stdlib.plot( [x,x,x,x,x], pdfs )
Insert cell
Insert cell
plt2_config = {
plt2.title = 'Beta Distribution Probability Density Function';
plt2.description = 'Plot overlaying evaluated beta distribution probability density functions (pdfs).';
plt2.labels = [
'α = β = 0.5',
'α = 5, β = 1',
'α = 1, β = 3',
'α = 2, β = 2',
'α = 2, β = 5'
];
plt2.colors = [
'#d62728', // red
'#1f77b4', // blue
'#2ca02c', // green
'#9467bd', // purple
'#ff7f0e' // orange
];
plt2.yLabel = 'pdf';
plt2.yMax = 2.5;
}
Insert cell
Insert cell
html`${ vdom2html( plt2.render() ) }`
Insert cell
Insert cell
Insert cell
y_i = new Array( x.length )
Insert cell
Insert cell
y_out = pdf( y_i, x, α, β )
Insert cell
Insert cell
plt3 = stdlib.plot()
Insert cell
Insert cell
plt3_config = {
plt3.title = 'Beta Distribution Probability Density Function';
plt3.yMax = 20.0;
plt3.xMin = 0.0;
plt3.xMax = 1.0;
plt3.colors = [
'#ff7f0e' // orange
];
}
Insert cell
Insert cell
plt3.x = [ x ]
Insert cell
Insert cell
Insert cell
plt3_vdom = {
plt3.y = [ y_out ];
return plt3.render();
}
Insert cell
Insert cell
html`${ vdom2html( plt3_vdom ) }`
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more