Public
Edited
Sep 2, 2024
Insert cell
Insert cell
Insert cell
Insert cell
// Going from match weight to probability
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
// Going from probability to match weight
Insert cell
Insert cell
Insert cell
Insert cell
viewof prior_probabability = Inputs.range([0, 1], {
label: "Prior probability"
})
Insert cell
viewof max_match_weight = Inputs.range([5, 40], {
label: "Max match weight",
step: 5,
value: 10 // Default value
})
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
// https://observablehq.com/@visnup/vega-lite-data-out?collection=@visnup/visualization
// https://observablehq.com/@robinl/m-and-u-probabilities
Insert cell
function probToBayesFactor(prob) {
return prob !== 1 ? prob / (1 - prob) : Infinity;
}
Insert cell
function probToMatchWeight(prob) {
return Math.log2(probToBayesFactor(prob));
}
Insert cell
function matchWeightToBayesFactor(weight) {
return Math.pow(2, weight);
}
Insert cell
function bayesFactorToProb(bf) {
return bf / (1 + bf);
}
Insert cell
function formatBf(bf, mw) {
if (bf >= 1000) {
return bf.toLocaleString(undefined, { maximumFractionDigits: 0 });
} else if (bf >= 100) {
return bf.toLocaleString(undefined, { maximumFractionDigits: 1 });
} else if (bf >= 10) {
return bf.toLocaleString(undefined, { maximumFractionDigits: 2 });
} else if (bf >= 1) {
return bf
.toLocaleString(undefined, { maximumFractionDigits: 3 })
.replace(/\.?0+$/, "");
} else {
// Apply similar formatting logic as prob_fmt for bf < 1
const absMw = Math.abs(mw);
const additionalDigits = Math.floor(absMw / 5);
const minFractionDigits = 4 + additionalDigits;

return bf
.toLocaleString(undefined, { minimumFractionDigits: minFractionDigits })
.replace(/\.?0+$/, "");
}
}
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