JSXGraph logo
JSXGraph
JSXGraph share

Share

Binomial distribution
QR code
<iframe
src="http://jsxgraph.uni-bayreuth.de/share/iframe/binomial-distribution"
style="border: 1px solid black; overflow: hidden; width: 550px; aspect-ratio: 55 / 65;"
name="JSXGraph example: Binomial distribution"
allowfullscreen
></iframe>
This code has to
<div id="board-0-wrapper" class="jxgbox-wrapper " style="width: 100%; ">
<div id="board-0" class="jxgbox" style="aspect-ratio: 4 / 1; width: 100%;" data-ar="4 / 1"></div>
</div>
<div id="board-1-wrapper" class="jxgbox-wrapper " style="width: 100%; ">
<div id="board-1" class="jxgbox" style="aspect-ratio: 1 / 1; width: 100%;" data-ar="1 / 1"></div>
</div>
<script type = "text/javascript">
/*
This example is licensed under a
Creative Commons Attribution 4.0 International License.
https://creativecommons.org/licenses/by/4.0/
Please note you have to mention
The Center of Mobile Learning with Digital Technology
in the credits.
*/
const BOARDID0 = 'board-0';
const BOARDID1 = 'board-1';
const BOARDID = BOARDID0;
const board1 = JXG.JSXGraph.initBoard(BOARDID0, {
boundingbox: [-0.3, 0, 1.3, -4],
axis: false
});
var prob = board1.create('slider', [
[0, -2],
[1, -2],
[0, .5, 1]
], {
name: 'p'
});
const board = JXG.JSXGraph.initBoard(BOARDID1, {
boundingbox: [-1, 1.1, 21, -.1],
axis: true,
showCopyright: false
});
board1.addChild(board);
for (let i = 0; i <= 20; i++) {
board.create('point', [i, () => binomial(20, i, prob.Value())], {
name: ''
});
}
var f = board.create('functiongraph', [function(x) {
var n, dist = 0;
for (n = 0; n < 20 + 1; n++) {
if (x < n) {
return dist;
}
dist = dist + binomial(20, n, prob.Value());
}
return dist;
}]);
function binomial(n, k, p) {
var x, p1 = 1,
p2 = 1,
coeff = 1;
for (x = n - k + 1; x < n + 1; x++) {
coeff *= x;
}
for (x = 1; x < k + 1; x++) {
coeff /= x;
}
for (x = 0; x < k; x++) {
p1 *= p;
}
for (x = 0; x < n - k; x++) {
p2 *= (1 - p);
}
return coeff * p1 * p2;
}
</script>
/*
This example is licensed under a
Creative Commons Attribution 4.0 International License.
https://creativecommons.org/licenses/by/4.0/
Please note you have to mention
The Center of Mobile Learning with Digital Technology
in the credits.
*/
const BOARDID0 = 'your_div_id_0'; // Insert your 1st board id here!
const BOARDID1 = 'your_div_id_1'; // Insert your 2nd board id here!
const board1 = JXG.JSXGraph.initBoard(BOARDID0, {
boundingbox: [-0.3, 0, 1.3, -4],
axis: false
});
var prob = board1.create('slider', [
[0, -2],
[1, -2],
[0, .5, 1]
], {
name: 'p'
});
const board = JXG.JSXGraph.initBoard(BOARDID1, {
boundingbox: [-1, 1.1, 21, -.1],
axis: true,
showCopyright: false
});
board1.addChild(board);
for (let i = 0; i <= 20; i++) {
board.create('point', [i, () => binomial(20, i, prob.Value())], {
name: ''
});
}
var f = board.create('functiongraph', [function(x) {
var n, dist = 0;
for (n = 0; n < 20 + 1; n++) {
if (x < n) {
return dist;
}
dist = dist + binomial(20, n, prob.Value());
}
return dist;
}]);
function binomial(n, k, p) {
var x, p1 = 1,
p2 = 1,
coeff = 1;
for (x = n - k + 1; x < n + 1; x++) {
coeff *= x;
}
for (x = 1; x < k + 1; x++) {
coeff /= x;
}
for (x = 0; x < k; x++) {
p1 *= p;
}
for (x = 0; x < n - k; x++) {
p2 *= (1 - p);
}
return coeff * p1 * p2;
}
<jsxgraph width="100%, 100%" aspect-ratio="4 / 1, 1 / 1" numberOfBoards="2" title="Binomial distribution" description="This construction was copied from JSXGraph examples database: BTW HERE SHOULD BE A GENERATED LINKuseGlobalJS="false">
/*
This example is licensed under a
Creative Commons Attribution 4.0 International License.
https://creativecommons.org/licenses/by/4.0/
Please note you have to mention
The Center of Mobile Learning with Digital Technology
in the credits.
*/
const board1 = JXG.JSXGraph.initBoard(BOARDID0, {
boundingbox: [-0.3, 0, 1.3, -4],
axis: false
});
var prob = board1.create('slider', [
[0, -2],
[1, -2],
[0, .5, 1]
], {
name: 'p'
});
const board = JXG.JSXGraph.initBoard(BOARDID1, {
boundingbox: [-1, 1.1, 21, -.1],
axis: true,
showCopyright: false
});
board1.addChild(board);
for (let i = 0; i <= 20; i++) {
board.create('point', [i, () => binomial(20, i, prob.Value())], {
name: ''
});
}
var f = board.create('functiongraph', [function(x) {
var n, dist = 0;
for (n = 0; n < 20 + 1; n++) {
if (x < n) {
return dist;
}
dist = dist + binomial(20, n, prob.Value());
}
return dist;
}]);
function binomial(n, k, p) {
var x, p1 = 1,
p2 = 1,
coeff = 1;
for (x = n - k + 1; x < n + 1; x++) {
coeff *= x;
}
for (x = 1; x < k + 1; x++) {
coeff /= x;
}
for (x = 0; x < k; x++) {
p1 *= p;
}
for (x = 0; x < n - k; x++) {
p2 *= (1 - p);
}
return coeff * p1 * p2;
}
</jsxgraph>

Binomial distribution

In general, if the random variable XXX follows the binomial distribution with parameters n∈Nn \in \mathbb{N}n∈N and p∈[0,1]p \in [0,1]p∈[0,1], we write $X \simeq B(n, p)$. The probability of getting exactly kkk successes in n independent Bernoulli trials is given by the probability mass function:

Pr(X=k)=(nk)pk(1−p)n−k for k=0,1,…nk=0,1, \ldots nk=0,1,…n and 000 else.

From a technical point of view, this example uses two boards which are connected by board1.addChild(board).

JSXGraph v1.11.1 Copyright (C) see https://jsxgraph.org
0,0
–o+←↓↑→
p = 0.50
24681012141618200.10.20.30.40.50.60.70.80.91
0,0
–o+←↓↑→
// Define the ids of your boards in BOARDID0, BOARDID1,...
const board1 = JXG.JSXGraph.initBoard(BOARDID0, {
boundingbox: [-0.3, 0, 1.3, -4],
axis: false
});
var prob = board1.create('slider', [
[0, -2],
[1, -2],
[0, .5, 1]
], {
name: 'p'
});
const board = JXG.JSXGraph.initBoard(BOARDID1, {
boundingbox: [-1, 1.1, 21, -.1],
axis: true,
showCopyright: false
});
board1.addChild(board);
for (let i = 0; i <= 20; i++) {
board.create('point', [i, () => binomial(20, i, prob.Value())], {
name: ''
});
}
var f = board.create('functiongraph', [function(x) {
var n, dist = 0;
for (n = 0; n < 20 + 1; n++) {
if (x < n) {
return dist;
}
dist = dist + binomial(20, n, prob.Value());
}
return dist;
}]);
function binomial(n, k, p) {
var x, p1 = 1,
p2 = 1,
coeff = 1;
for (x = n - k + 1; x < n + 1; x++) {
coeff *= x;
}
for (x = 1; x < k + 1; x++) {
coeff /= x;
}
for (x = 0; x < k; x++) {
p1 *= p;
}
for (x = 0; x < n - k; x++) {
p2 *= (1 - p);
}
return coeff * p1 * p2;
}

license

This example is licensed under a Creative Commons Attribution 4.0 International License.
Please note you have to mention The Center of Mobile Learning with Digital Technology in the credits.