Simulating Random Variables and the Kolmogorov-Smirnov Test | OCR B (MEI) A Level Further Maths notes
Free preview: Simulating Random Variables and the Kolmogorov-Smirnov Test
Simulating a Random Variable
Year 2 (A level only). It is in OCR B (MEI)'s Statistics Major, not the Statistics Minor (the AS content).
Let's start with a question that is hard to answer exactly, like the total waiting time in a queue at a busy supermarket. The maths gets messy fast. But we can simulate it: generate many random values on a computer, play the situation out thousands of times, and count how often the event happens.
- A probability is a long-run proportion. So if we can copy the random process faithfully, the proportion of simulated runs where an event happens estimates its probability.
- The raw material is random numbers: digits or decimals from a calculator or computer, where every value is equally likely.
Discrete variables
- List the probabilities.
- Split the random numbers 00 to 99 in proportion to the probabilities. Why? Each two-digit number has probability 0.01, so a block of 30 numbers has probability 0.3.
- Read off a value of X for each random number.
- If P(X = 0) = 0.25, P(X = 1) = 0.6 and P(X = 2) = 0.15, use 00 to 24 for 0, 25 to 84 for 1, and 85 to 99 for 2. (25 numbers, 60 numbers, 15 numbers.)
๐ Watch me do it: with that allocation, simulate 8 values of X using the random numbers 41, 07, 88, 63, 25, 96, 50, 19, and use them to estimate the mean of X
| What I write | Why I do it |
|---|---|
| 41 โ 1, 07 โ 0, 88 โ 2, 63 โ 1 | Find which block each number falls in: 41 is in 25 to 84, so X = 1. |
| 25 โ 1, 96 โ 2, 50 โ 1, 19 โ 0 | Careful at the edges: 25 is the first number of the block for 1. |
| Simulated values: 1, 0, 2, 1, 1, 2, 1, 0 | Eight values of X. |
| Estimated mean | The sample mean of the simulated values. |
| True mean | Close, but 8 values only give a rough estimate. More simulations give a better one. |
๐ก In plain words
- A probability is a long-run proportion, so simulating the experiment many times and counting estimates it.
- The random numbers are like a fair spinner; we paint sections of it to match our distribution.
โ๏ธ YOUR TURN 1
Try this first:
P(X = 1) = 0.15, P(X = 2) = 0.45, P(X = 3) = 0.4. Give an allocation of the numbers 00 to 99, and simulate five values using the random numbers 07, 62, 33, 91, 58.
Answer:
- 00 to 14 โ 1; 15 to 59 โ 2; 60 to 99 โ 3.
- 07 โ 1, 62 โ 3, 33 โ 2, 91 โ 3, 58 โ 2.
Continuous Variables: the Inverse cdf Method
A random number generator gives values U uniformly distributed on (0, 1). How can we turn those into, say, exponential waiting times? Use the cdf backwards.
Method: the inverse cdf method
- Find the cdf .
- Set and solve for x. This gives .
- Feed in random u values between 0 and 1; each gives one simulated x.
- Why does it work? , because for a uniform U, . So has exactly the cdf F.

Unlock the full note: start 7 days free.
Log in or subscribe to read the rest of this note. Members also get the AI tutor, practice quizzes, mock exams and flashcards for this topic.
Log in ยท Subscribe ยท Start free trial
What's inside for this topic
1 teacher note, 60 practice questions, 44 flashcards, 2 quizzes.
Get the full notes, every practice question, flashcards, quizzes and mock papers.
All OCR B (MEI) A Level Further Maths topics ยท A Level Further Maths