Build mathematical modelsLesson 41 of 48 · 8 min
Integrate a probability density
Check a density’s total mass and calculate an expectation on its stated support.
Maths refresher: Density versus probability
Probabilities are areas under a density. A density can exceed one at a point while its total integral remains one.
The density reaches 2 at , but the probability of an interval is its area, not that endpoint height.
A continuous probability density assigns probability through integrals over intervals. Its height is not the probability of a single point. A valid density must be nonnegative and have total mass one over its support.
Use the authored density between zero and one, and zero elsewhere. Symbolic integration checks its normalisation and calculates its mean and variance. The integration limits encode the support and must not be discarded.
An expectation weights each value by the density before integrating. The variance is the second moment minus the square of the mean. These exact answers can later benchmark numerical integration or Monte Carlo, but they describe this chosen teaching distribution rather than measured population evidence.
Does a density value of 2 necessarily make the probability model invalid?
Write a prediction (optional)
Exact calculation for an authored density
Select Run Python with the code unchanged.
Your saved draft is open. To use the published code, select Restore example in Tools. Use Recover draft to bring back your code.
Tools
About Python
Python and the course packages can load while you read. Each run starts with fresh user variables; imported modules stay loaded. Stop replaces the worker. Runtime details ↗
Ctrl+Enter or ⌘+Enter runs Python.
Execution error
Technical error details
Your result
Python text output
Compare with the worked example
Executed from the published Python during the site build. Your own run appears above. Build environment ↗
Worked text output
Scale for unit mass: 2 Mass on [0,1]: 1 Mean: 2/3 Variance: 1/18 P(X > 3/4): 7/16
Read the starter result
Mass on [0,1] checks that the density integrates to one. Mean and Variance describe this authored distribution. The model assigns density zero outside its support.
Edit and compare
Replace shape = x with shape = x**2. The code chooses the multiplier that makes total probability one. Select Run Python. Read Scale for unit mass, verify Mass on [0,1] and compare Mean with the first run.
Scope. Nonnegativity and normalisation are mathematical checks; they do not validate an assumed distribution against real data.
Try a fresh case
How is obtained from a continuous density f?
Need a hint?
Hint 1
Think of area under the curve.
Hint 2
Use the relevant interval and support.