Public
Edited
Apr 7, 2023
Insert cell
Insert cell
// inputs
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
For a population size of ${n_pop}, and ${n_samples} samples of ${sampleSize} each...
Insert cell
Insert cell
viewof meanInput = Inputs.range([-100, 100], {label: "Mean", step: 1})
Insert cell
viewof stddevInput = Inputs.range([-100, 100], {label: "Std. Dev.", step: 1})
Insert cell
data = filler(n_pop, distribution)
Insert cell
data[0]
Insert cell
// from https://observablehq.com/@amauboussin/exploring-the-limits-of-the-central-limit-theorem
means = new Array(n_samples*sampleSize).fill().map(() => d3.mean(d3.shuffle(data).slice(0, sampleSize)))
Insert cell
filler = (size, distType) => {
const empty = new Array(size);
// stddev_pop, min_pop, max_pop, loc_pop, scale_pop, p_pop, alpha_pop, beta_pop, pop_trials, lambda_pop, k_pop
switch(distType){
case "Gaussian":
return new Array(size).fill().map(
() => d3.randomNormal(pop.loc,pop.stddev)()
);
case "Uniform":
return new Array(size).fill().map(
() => d3.randomUniform(pop.min,pop.max)
);
case "Cauchy":
return new Array(size).fill().map(
() => d3.randomCauchy(pop.loc, pop.scale)
);
case "Bernoulli":
return new Array(size).fill().map(
() => d3.randomBernoulli(pop.p) // p probability [0,1]
);
case "Beta":
return new Array(size).fill().map(
() => d3.randomBeta(pop.alpha, pop.beta) // alpha and beta shapes, both positive
);
case "Binomial":
return new Array(size).fill().map(
() => d3.randomBinomial(pop.trials, pop.p) // trials>0
);
case "Exponential":
return new Array(size).fill().map(
() => d3.randomExponential(pop.lambda) // lambda rate
);
case "Pareto":
return new Array(size).fill().map(
() => d3.randomPareto(pop.alpha) // alpha shape (positive)
);
case "Poisson":
return new Array(size).fill().map(
() => d3.randomPoisson(pop.lambda)
);
case "Geometric":
return new Array(size).fill().map(
() => d3.randomGeometric(pop.p) // p probability
);
case "Generalized Extreme":
return new Array(size).fill().map(
() => d3.randomWeibull(pop.k, pop.loc, pop.scale) // k shape. If positive, Weibull. If zero, Gumbel. If negative, Frechet with -k.
);
case "Lévy":
return new Array(size).fill().map(
() => levy(pop.loc, pop.scale)
);
default:
console.log("No distribution selected.");
};
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
median = d3.median(data)
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
variance = d3.deviation(data)**2
Insert cell
Insert cell
stddev = d3.deviation(data)
Insert cell
Insert cell
// semivariance
// risk of observations falling below the mean (negative fluctuations)
semivariance = (1/n_below)*
Insert cell
tex`{Range}`
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
tex`{M-estimators}`
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
gaussian_manual = (xval) => {
return (1/(Math.sqrt(2*Math.PI))) * Math.E^((-xval^2)/2)
}
Insert cell
Insert cell
levy = (location,scale) => {
const random = d3.randomUniform(0,1)
//return (scale/(()^2))+location
}
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