Published
Edited
Apr 4, 2020
Importers
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
aggregate_distribution = guesstimatorInputToCdf({
guesstimatorInput: aggregate_input,
simulationSampleCount: 10000,
outputSampleCount: 80,
smoothingWidth: 2
})
Insert cell
Insert cell
md `# Statistics`
Insert cell
Insert cell
expected_value_cdf = cdf => {
let pdf = cdf.toPdf()
let xs = pdf.xs
let ys = pdf.ys
let normalizing_constant = ys.reduce((a, b) => a + b, 0)
ys = ys.map(element => element/normalizing_constant)
let mean = xs.reduce( (accumulator, x, index ) => (accumulator + x*ys[index]), 0)
return mean
}
Insert cell
expected_value_cdf(aggregate_distribution)
Insert cell
Insert cell
median_cdf = cdf => {
let ys = cdf.ys
let pos = ys.findIndex( y => y>=0.5)
return pos==-1 ? "" : cdf.xs[pos]
}
Insert cell
median_cdf(aggregate_distribution)
Insert cell
md `### Confidence intervals`
Insert cell
confidence_intervals_cdf = (cdf, p) => {
let ys = cdf.ys
let low_p = ((100-p)/100)/2
let high_p = 1-low_p
let low_value_index = ys.findIndex( y => y>=low_p)
let high_value_index = ys.findIndex( y => y>=high_p)
let low_value = cdf.xs[low_value_index]
let high_value = cdf.xs[high_value_index]
return ({
low_p,
low_value,
high_p,
high_value
})
}
// confidence_intervals_cdf(cdf, 90) => {low_p: 0.05, high_p: 0.95, low_value = 12, high_value= 23}
Insert cell
confidence_intervals_cdf(aggregate_distribution, 90)
Insert cell
confidence_intervals_cdf(aggregate_distribution, 80)
Insert cell
Insert cell
score = (player, aggregate, resolution, type="floatCdf", marketType="marketScore") => {
if (type == "floatCdf") {
return new predictionAnalysis.PredictionResolutionGroup(
{agentPrediction: {
data: { xs: player["xs"], ys: player["ys"] },
dataType: type},
marketPrediction: (marketType == "marketScore")? {
data: { xs: aggregate["xs"], ys: aggregate["ys"] },
dataType: type} : undefined,
resolution: {
data: { xs: resolution["xs"], ys: resolution["ys"] },
dataType: type}
}).pointScore(predictionAnalysis[marketType])["data"]}
else {
return new predictionAnalysis.PredictionResolutionGroup(
{agentPrediction: {
data: player,
dataType: type},
marketPrediction: (marketType == "marketScore")? {
data: aggregate,
dataType: type} : undefined,
resolution: {
data: resolution,
dataType: type}
}).pointScore(predictionAnalysis[marketType])["data"]}
}
Insert cell
md `### Peak`
Insert cell
peak = cdf => {
let pdf = cdf.toPdf()
let xs = pdf.xs
let ys = pdf.ys
let indexOfMaxValue = ys.reduce((iMax, x, i, arr) => x > arr[iMax] ? i : iMax, 0);
return xs[indexOfMaxValue]
}
Insert cell
Insert cell
Insert cell
// input = (value) => html`<input style="height: 23px; font-size: 16px; width: ${width-10}px; font-weight: 400; background-color: #f6f8fa; border-radius: 3px; border: 2px solid #cedbe9; padding: 3px 10px" type=text value="${value}">`
Insert cell
Insert cell
predictionAnalysis = require('@foretold/prediction-analysis@0.0.7/dist/index.js')
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