plotData = {
const pts = [];
for (let x = -3; x <= 6; x += 0.04) {
pts.push({
x,
h0: normalPDF(x, 0, sigma_xbar),
ha: normalPDF(x, mu_a, sigma_xbar)
});
}
return pts;
}
Plot.plot({
width: 700, height: 360,
marginLeft: 50, marginBottom: 45,
x: { domain: [-3, 6], label: "Sample mean xฬ (ฯ=1, n=25)" },
y: { domain: [0, 6], label: "Density" },
title: `Hโ: ฮผ=0 vs Hโ: ฮผ=${mu_a.toFixed(1)} | ฮฑ=${(alpha_val*100).toFixed(0)}%`,
marks: [
Plot.line(plotData, {x: "x", y: "h0", stroke: "steelblue", strokeWidth: 2.5}),
Plot.line(plotData, {x: "x", y: "ha", stroke: "tomato", strokeWidth: 2.5}),
Plot.areaY(plotData.filter(d => d.x >= z_crit * sigma_xbar),
{x: "x", y: "h0", fill: "steelblue", fillOpacity: 0.3}),
Plot.areaY(plotData.filter(d => d.x < z_crit * sigma_xbar),
{x: "x", y: "ha", fill: "tomato", fillOpacity: 0.3}),
Plot.ruleX([z_crit * sigma_xbar], {stroke: "black", strokeWidth: 2, strokeDasharray: "6,3"}),
Plot.text([{x: z_crit * sigma_xbar + 0.1, y: 5.5, text: "โ RR boundary"}],
{x: "x", y: "y", text: "text", fontSize: 13})
]
})