Built with blockbuilder.org
forked from anonymous's block: nate central limit theorem demo
license: mit |
Built with blockbuilder.org
forked from anonymous's block: nate central limit theorem demo
<!DOCTYPE html> | |
<head> | |
<!-- trying to demo what they did here with Java: http://onlinestatbook.com/2/sampling_distributions/clt_demo.html Except without Java --> | |
<meta charset="utf-8"><!-- Load c3.css --> | |
<link href="http://c3js.org/css/c3-b03125fa.css" rel="stylesheet" type="text/css"> | |
<!-- Load d3.js and c3.js --> | |
<script src="https://d3js.org/d3.v3.min.js"></script> | |
<script src="http://c3js.org/js/c3.min-4c5bef8f.js"></script> | |
<script src="https://d3js.org/d3-random.v1.min.js"></script> | |
<script src="https://d3js.org/d3-array.v1.min.js"></script> | |
</head> | |
<body> | |
<div id="chart"><div> | |
<script> | |
function getRandomSubarray(arr, size) { | |
var shuffled = arr.slice(0), i = arr.length, min = i - size, temp, index; | |
while (i-- > min) { | |
index = Math.floor((i + 1) * Math.random()); | |
temp = shuffled[index]; | |
shuffled[index] = shuffled[i]; | |
shuffled[i] = temp; | |
} | |
return shuffled.slice(min); | |
} | |
var t = 90; | |
var r = 100000; | |
var mu = 0; | |
var sigma = 0.5; | |
var pop=d3.range(r).map(d3.randomLogNormal(mu, sigma)); | |
var pop_dist = d3.histogram().thresholds(40)(pop).map(function(d){return d.length}); | |
var s_dist = [2, 1, 9, 31, 64, 173, 243, 339, 483, 608, 700, 774, 774, 754, 757, 735, 621, 566, 447, 403, 289, 247, 234, 166, 141, 104, 95, 65, 38, 36, 23, 27, 25, 11, 7, 4, 7, 7, 6, 3, 1, 2, 0, 2, 0, 0, 0, 1]; | |
var s_dist_2 = [1, 0, 3, 10, 19, 23, 32, 35, 56, 68, 89, 63, 75, 70, 74, 63, 77, 47, 50, 28, 24, 26, 14, 9, 10, 6, 9, 5, 3, 5, 1, 1, 0, 0, 0, 1, 3]; | |
var chart = c3.generate({ | |
data: { | |
columns: [ | |
['data1'].concat(pop_dist), | |
//['data2', 130, 100, 140, 200, 150, 50] | |
], | |
type: 'bar' | |
}, | |
bar: { | |
width: { | |
ratio: 0.90 // this makes bar width 50% of length between ticks | |
} | |
// or | |
//width: 100 // this makes bar width 100px | |
} | |
}); | |
</script> | |
</body> |