Published
Edited
Aug 29, 2022
1 fork
Importers
9 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
simulation = {
let N = 5e3;
let c = d3.cumsum(p_vals);

// initialize my counts to zero
let bin_overflows = d3.range(N_cats).map(x => 0);
let any_overflows = 0;

// perform the very simple simulation
for(let ii=0; ii<N; ii++){
let sim_bins = d3.range(N_samples).map(x => d3.randomUniform()()).map(r => N_cats-d3.sum(c.map(cc => r<cc?1:0)))
let sim_bin_count_map = d3.rollups(sim_bins, v => v.length, d => d).map(x => {return({bin: x[0], count: x[1]})})
let sim_bin_overflow = sim_bin_count_map.filter(x => x.count>=N_overflow);
if(sim_bin_overflow.length>0){
any_overflows+=1;
sim_bin_overflow.forEach(x => bin_overflows[x.bin]+=1)
}
}
// return the results
return({bin_overflows:bin_overflows.map(x => x/N),
any_overflows:any_overflows/N})
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
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