Published
Edited
Oct 6, 2022
3 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
calculate_power(0.5, 50, .05)
Insert cell
stdlib = require( "https://unpkg.com/@stdlib/stdlib@0.0.32/dist/stdlib-flat.min.js" )
Insert cell
function calculate_power(effectSize, sampleSize, alpha)
{
let sides = 2 // one-sided
let df = sampleSize - 1;
let zval = stdlib.base.dists.t.quantile(alpha / sides, df - 1) + effectSize * Math.sqrt(sampleSize);
return stdlib.base.dists.t.cdf(zval, df - 1);
}
Insert cell
power = `Your power is ${Math.round(100 * calculate_power(params[0], params[1], params[2]))}%`
Insert cell
_ = require("https://unpkg.com/underscore@1.13.6/underscore-umd.js")
Insert cell
import { vl } from "@vega/vega-lite-api"
Insert cell
refPlot = (data, color) => {
return vl.markLine().data(data)
.encode(
vl.color().value(color),
vl.x().fieldQ("x"),
vl.y().fieldQ("y"),
)
}
Insert cell
tdist = (center) => {
let dx = 4 / Math.sqrt(params[1]);
let xs = stdlib.linspace(0 - .5, params[0] + .5, 500)
let ys = xs.map((x) => stdlib.base.dists.t.pdf((x - center) * Math.sqrt(params[1]), params[1] - 1))
// Zip the two arrays
let results = []
for(let i = 0; i < xs.length; i++) {
results.push({'x': xs[i], 'y': ys[i]})
}
return results
}
Insert cell
truncatedTdist = (center, p) => {
let [effectSize, sampleSize, alpha] = params;
let dx = 4 / Math.sqrt(params[1]);
let xs = stdlib.linspace(p, params[0] + .5, 500)
let ys = xs.map((x) => stdlib.base.dists.t.pdf((x - center) * Math.sqrt(params[1]), params[1] - 1))
// Zip the two arrays
let results = []
for(let i = 0; i < xs.length; i++) {
results.push({'x': xs[i], 'y': ys[i]})
}
return results
}
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