{"schemaVersion":2,"courseId":"foundations","module":{"id":"probability","title":"1 · Probability models and random variables","summary":"Build coherent probability models and translate them into simulated data.","stages":[{"type":"read","id":"foundations-probability-guide","skillIds":["foundations.probability-models","foundations.expectation-variance"],"estimatedMinutes":7,"difficulty":"core","title":"Probability models and random variables: research guide","html":"<h2>Probability models and random variables</h2><p class=\"lead\">Build coherent probability models and translate them into simulated data.</p><p>Probability statements become useful only after the support, conditioning information, and data-generating experiment are explicit.</p><div class=\"callout\"><b>Workflow.</b> Define a sample space, events, and a coherent distribution before calculating.</div><p><b>Diagnostic:</b> Inspect support, normalization, and conditioning information. The main failure to avoid is probabilities attached to impossible or incomplete events.</p>","prerequisiteStageIds":[]},{"type":"interactive","id":"foundations-probability-lab","skillIds":["foundations.probability-models"],"estimatedMinutes":6,"difficulty":"core","title":"Probability models intuition lab","note":"Set the mixing weight and separation: the two-component model defines one normalized density, and the simulated draws fall exactly under it.","params":[{"name":"p","label":"Mixing weight p (component A)","min":0,"max":1,"step":0.05,"value":0.3},{"name":"sep","label":"Component separation","min":0,"max":6,"step":0.5,"value":3}],"template":"import numpy as np, matplotlib.pyplot as plt\nfrom scipy import stats\nrng = np.random.default_rng(0)\np = {{p}}; sep = {{sep}}; n = 4000\n# model: with prob p draw N(-sep/2,1), else N(+sep/2,1)\nz = rng.random(n) < p\nx = np.where(z, rng.normal(-sep/2, 1, n), rng.normal(sep/2, 1, n))\ngrid = np.linspace(-7, 7, 500)\ndens = p*stats.norm.pdf(grid, -sep/2, 1) + (1-p)*stats.norm.pdf(grid, sep/2, 1)\nplt.figure(figsize=(6,3.7))\nplt.hist(x, bins=55, density=True, color='#da9100', alpha=0.5, label='simulated draws')\nplt.plot(grid, dens, color='#c9c6ac', lw=2, label='model density')\nplt.legend(); plt.xlabel('x'); plt.ylabel('density')\nplt.title(f'two-component model: p={p:.2f}, separation={sep:.1f}')\nmodel_mean = p*(-sep/2) + (1-p)*(sep/2)\nprint(f'model mean = {model_mean:.3f}, empirical mean = {x.mean():.3f}')\nprint(f'density integrates to {np.trapz(dens, grid):.3f} (a coherent model normalizes to 1)')\n","prerequisiteStageIds":["foundations-probability-guide"]},{"type":"code","id":"foundations-probability-worked","skillIds":["foundations.probability-models"],"estimatedMinutes":10,"difficulty":"core","title":"Probability models and random variables: worked Python model","note":"Run the reproducible example, then change one assumption and compare the output.","code":"import numpy as np\nrng = np.random.default_rng(42)\nn = 40\nrepetitions = 2000\nmeans = rng.normal(loc=2.0, scale=3.0, size=(repetitions, n)).mean(axis=1)\nprint(f\"Monte Carlo mean: {means.mean():.3f}\")\nprint(f\"Monte Carlo SE:   {means.std(ddof=1):.3f}\")\nprint(f\"Theory SE:        {3 / np.sqrt(n):.3f}\")","prerequisiteStageIds":["foundations-probability-lab"]},{"type":"codechallenge","id":"foundations-probability-challenge","skillIds":["foundations.probability-models"],"estimatedMinutes":12,"difficulty":"core","title":"Probability models code challenge","note":"Complete the simulation so estimate contains the sample mean and se contains its analytical standard error.","starter":"import numpy as np\nsample = np.array([1.2, 2.1, 1.7, 2.5, 1.9])\nestimate = ...\nse = ...","tests":"assert np.isclose(estimate, sample.mean())\nassert np.isclose(se, sample.std(ddof=1)/np.sqrt(len(sample)))\nprint(\"grader: estimate and standard error are correct\")","hints":["Use the sample mean for estimate.","Use ddof=1, divide the sample standard deviation by sqrt(n)."],"success":"The numerical result and the probability models workflow both pass the grader.","prerequisiteStageIds":["foundations-probability-worked"],"variantId":"foundations-probability-challenge-core"},{"type":"case","id":"foundations-probability-case","skillIds":["foundations.expectation-variance"],"estimatedMinutes":8,"difficulty":"core","title":"Expectation and variance: model decision","note":"A team is about to report results without checking units, existence of moments, and covariance terms.","steps":[{"prompt":"What is the best next action?","choices":["Use expectations for location and variance for dispersion around the mean.","Increase decimal precision and report immediately.","Drop observations until the preferred coefficient appears."],"answer":0,"explain":"The defensible workflow is to use expectations for location and variance for dispersion around the mean."},{"prompt":"Which risk should the final report address explicitly?","choices":["Only whether the sample mean is positive.","dropping dependence terms or confusing spread with level","Whether every coefficient has the same sign."],"answer":1,"explain":"The relevant failure mode is dropping dependence terms or confusing spread with level."}],"prerequisiteStageIds":["foundations-probability-challenge"],"variantId":"foundations-probability-case-core"},{"type":"match","id":"foundations-probability-match","skillIds":["foundations.expectation-variance"],"estimatedMinutes":7,"difficulty":"core","title":"Expectation and variance: evidence map","note":"Match each research role to the course-specific evidence.","pairs":[{"left":"Good practice","right":"Use expectations for location and variance for dispersion around the mean."},{"left":"Diagnostic evidence","right":"units, existence of moments, and covariance terms"},{"left":"Failure to guard against","right":"dropping dependence terms or confusing spread with level"}],"prerequisiteStageIds":["foundations-probability-case"],"variantId":"foundations-probability-match-core"}]}}
