Inequalities and limit theorems exercises — exam-style with R, Chebyshev, the CLT and the continuity correction (and the 12.5 that cost me a part)
In a class mock exam I was asked for the probability of 12 or more quiet sessions, and I wrote without thinking 1 - pnorm(12.5, ...). I remembered the continuity correction as “add 0.5”, so I added it. I got 0.087 when the right answer was 0.164: almost half. “12 or more” starts at the bar for 12, which runs from 11.5 to 12.5, so the edge is 11.5. Since then I write down the integer values that belong before touching the 0.5, and that is what you will see in exercise 3.
These are exam-style exercises on inequalities and limit theorems, in the format of ME1’s EC2: one context per exercise, chained parts, paper and R mixed and the marks for each part. If you want to review first, you have the proofs and the R practice of the topic.
Table of Contents
How to use this article
- Do the exercises with the exam in mind. In ME1’s EC2 you have 4 hours for 50 marks, with RStudio and the data open. These three exercises add up to 40 marks plus a 2.5 bonus: give them about 3 hours.
- Paper for what is proved, R for what is computed. Calculations with 2 decimals, as the exam asks. Whatever you do in R, keep it in a script: at the end of the exam you have to upload the
.Rfile with the code for each exercise. - Before each
pnorm, decide what you are talking about. One observation, a sum or a mean? The standard deviation is , or . - Mark with the criteria. Each solution comes with “How it is marked” and a split of the marks. It is a guide, mine: not the official criteria.
- Finish with the cheat sheet and “For your script”. The cheat sheet only has results (it is what you may bring handwritten: two sheets, both sides, in EC2) and “For your script” is the topic’s code ready for your
.Rfile.
Exercise 1: the watch steps (10 marks)
Your sports watch counts the steps you take each day. After months of use, the app tells you the mean is 8000 steps a day with a standard deviation of 1500, and nothing more about the distribution. We call the steps of one day.
- (2 marks) Give a lower bound for the probability that on one day you take between 5000 and 11,000 steps.
- (2 marks) Give a bound for the probability that on one day you reach 16,000 steps or more, first with Markov’s inequality and then with Chebyshev’s. Which is better and why?
- (3 marks) If you also knew that , compute with R the probability of part 1 and compare it with the bound.
- (3 marks) Consider the mean steps over 30 days, with independent days. Give a lower bound for the probability that this mean is less than 500 steps away from 8000 and compute that same probability approximately with the CLT. Interpret the difference.
Exercise 2: the heart-rate monitor battery (15 marks)
In each workout session your heart-rate monitor uses a fraction of the battery, which we model with the density
Sessions are independent and the battery is fully recharged every night.
- (3 marks) Check on paper that is a density and compute and .
- (2 marks) Check the three results of the previous part with
integrate. - (4 marks) Let be the total fraction of battery used in 30 sessions (in “full charges”). Using the CLT, compute approximately , that is, that in a month of 30 sessions you use 19 charges or more.
- (3 marks) How many sessions do you need for the mean fraction used to be within 0.05 of its mean with probability 0.95? Answer with the CLT and with Chebyshev.
- (3 marks) Simulate with
rbeta10,000 months of 30 sessions, estimate and draw the histogram of with the CLT normal on top. Is the approximation of part 3 good?
Exercise 3: the workout notifications (15 marks)
During a one-hour workout session you get phone notifications according to a Poisson with mean 1.5, independent from one session to another. You have done 40 sessions.
- (3 marks) Let be the total number of notifications in the 40 sessions. Justify with the moment generating function what the exact distribution of is.
- (4 marks) Compute approximately, with the CLT and the continuity correction, , and compare it with the exact value in R.
- (4 marks) A session is “quiet” if no notification arrives. Compute the probability that a session is quiet and, with the CLT, the approximate probability of having 12 or more quiet sessions out of 40. Compare it with the exact one.
- (4 marks) You want to estimate with the proportion of quiet sessions, with an error below 0.05 and probability 0.95. How many sessions do you need if you know nothing about , with Chebyshev and with the CLT? And with the CLT, if you use the value of from part 3?
Bonus (2.5 marks)
Prove that the Chebyshev bound for cannot be improved: build a discrete variable with mean 8000 and standard deviation 1500 (the steps of exercise 1) for which is exactly .
Solutions
Exercise 1
Before the first calculation. You are given a mean, a standard deviation “and nothing else about the distribution”. That rules out the obvious path, pnorm: you don’t know the steps are normal, so in parts 1, 2 and 4 you can’t compute probabilities, only bound them. With so little information, Markov (mean and ) and Chebyshev (mean and variance) are what works. That’s why the first step of each part is to rewrite the event in the shape the inequality asks for: or . Part 3 gives you the normal precisely so you can measure how much you lose without it.
Part 1. The interval is , and : . By Chebyshev:
On at least 75 % of the days you take between 5000 and 11,000 steps.
Part 2. Steps are , so Markov applies:
With Chebyshev, since implies :
Chebyshev is much better (0.035 against 0.5) because it also uses the variance: with a standard deviation of 1500, moving 8000 steps away is moving more than 5 standard deviations away.
Why go through . Chebyshev talks about both tails at once, and the question asks about one. The trick is to enlarge the event: every day with 16,000 steps or more is 8000 or more away from the mean, and a bound for the big event also holds for the small one. Here and .
Using . measures the distance to the mean, not the value. And another classic: writing , which is the bound for staying close, when here you’re asked about moving away.
Part 3.
pnorm(11000, 8000, 1500) - pnorm(5000, 8000, 1500) # if X were N(8000, 1500)
Output:
[1] 0.9544997
With the normal, 95.45 % of the days fall in the interval, against Chebyshev’s “at least 75 %”. The bound is true (0.95 ≥ 0.75), but it falls short because it does not use the shape of the distribution.
Setting up part 4. The main character changes: it’s no longer the steps of one day, but the mean of 30 days. Before writing anything, ask yourself what standard deviation has: , much smaller, because when you average, the high days and the low days cancel out. With that, Chebyshev works just like in part 1: and .
Check you’ve got it: what do you get if in part 4 you use the standard deviation of one day, 1500?
and a “bound” . A probability greater than or equal to is true, but it says nothing. That absurd number is the sign that you’ve used the standard deviation of one observation to talk about a mean: for it’s .
Part 4. The 30-day mean has mean 8000 and variance . By the law of large numbers (Chebyshev on ):
With the CLT, :
1 - 1500^2 / (30 * 500^2) # Chebyshev bound 2 * pnorm(500 / (1500 / sqrt(30))) - 1 # CLT: P(|mean - 8000| < 500)
Output:
[1] 0.7 [1] 0.9321108
Chebyshev guarantees 70 % whatever happens; the CLT says that it is approximately 93 %. They do not contradict each other: 0.93 ≥ 0.70. The bound is loose because it holds for any distribution; the CLT is sharper because, with 30 days, the mean is almost normal.
How it is marked. Part 1: identifying (1 mark) and the bound with (1). Part 2: Markov with the condition (1), Chebyshev moving to and the comparison (1). Part 3: the code and 0.95 (2), the comparison (1). Part 4: the bound with (1.5), the CLT with (1), the interpretation (0.5).
Exercise 2
Part 1. on because and . We integrate:
You can also recognise a beta(3, 2): mean and variance .
Why and not the definition of variance. The obvious path, , forces you to expand a square with decimals. With , the three integrals are and only the exponent changes. And the beta(3, 2) gives you a free check: its constant, , is 12.
Part 2.
f <- function(x) 12 * x^2 * (1 - x) integrate(f, 0, 1) # 1: it is a density integrate(function(x) x * f(x), 0, 1) # E(X) = 0.6 integrate(function(x) x^2 * f(x), 0, 1) # E(X^2) = 0.4 => Var = 0.4 - 0.36
Output:
1 with absolute error < 1.1e-14 0.6 with absolute error < 6.7e-15 0.4 with absolute error < 4.4e-15
Setting up part 3. The sum of 30 betas has no named distribution: no R function gives you the exact , and that’s why you use the CLT. The first thing is to decide what you’re talking about: a sum. The means add up (18) and so do the variances (), but not the standard deviations.
Adding up the standard deviations, . You get , more than twice the right answer.
Part 3. , iid with and . By the CLT, :
1 - pnorm(19, 30 * 0.6, sqrt(30 * 0.04)) # CLT for the sum
Output:
[1] 0.1806552
In 18 % of the months you use 19 charges or more. is continuous: there is no continuity correction.
Setting up part 4. Now the unknown is . Translate the sentence first: . With the CLT, the central 95 % of the normal reaches 1.96 standard deviations, so is enough. With Chebyshev, the bound has to reach 0.95. You solve for and round up, never to the nearest: with 61 sessions the probability is 0.949, a hair below; with 62, 0.951.
Part 4. With the CLT, ; with Chebyshev, .
ceiling((qnorm(0.975) * 0.2 / 0.05)^2) # CLT ceiling(0.04 / (0.05 * 0.05^2)) # Chebyshev
Output:
[1] 62 [1] 320
62 sessions with the CLT and 320 with Chebyshev: Chebyshev asks for five times more because it guarantees 95 % without assuming anything about the shape.
Part 5.
set.seed(2026) S <- replicate(10000, sum(rbeta(30, 3, 2))) # 10,000 months of 30 sessions mean(S >= 19) # simulated P(S >= 19) c(mean(S), sd(S)) # against 18 and sqrt(1.2) = 1.0954 hist(S, freq = FALSE, breaks = 40, main = "30 sessions", xlab = "charges") curve(dnorm(x, 18, sqrt(1.2)), add = TRUE, col = "red", lwd = 2)
Output:
[1] 0.1784 [1] 17.9877 1.0945
The simulation gives 0.178 against 0.181 from the CLT: the approximation is good. The simulated mean and standard deviation (17.99 and 1.09) are the theoretical ones, and in the drawing the histogram follows the normal: the beta(3, 2) is only slightly skewed, so with 30 sessions the CLT works very well.
How it is marked. Part 1: density (1), (1), (1). Part 2: the three integrals (2). Part 3: mean and standard deviation of (2), standardising and the result (2). Part 4: CLT (1.5), Chebyshev (1.5); without rounding up, −0.5. Part 5: correct simulation (1), histogram with freq = FALSE and the curve (1), the comparison (1).
Exercise 3
Part 1. Each has mgf . Since they are independent, the mgf of the sum is the product:
which is the mgf of a Poisson(60). Since the mgf determines the distribution, : .
Part 2. is an integer: is the values 51 to 70, and with the continuity correction, the interval . With :
pnorm(70.5, 60, sqrt(60)) - pnorm(50.5, 60, sqrt(60)) # CLT with correction ppois(70, 60) - ppois(50, 60) # exact
Output:
[1] 0.8023622 [1] 0.8021355
The approximation and the exact value agree to the first three digits: 0.8024 and 0.8021. 80 % of the time, in 40 sessions you get between 51 and 70 notifications.
Setting up part 3. There are two levels. Within each session, notifications are Poisson(1.5); but all you care about is whether any arrived. Each session is a Bernoulli trial with success “quiet”, of probability , and counting successes in 40 independent sessions is a binomial. The Poisson(60) counts notifications, not sessions: it has nothing to do with this part.
Part 3. . The number of quiet sessions is , with mean and variance . is the values 12, 13, …: the edge is 11.5.
p <- dpois(0, 1.5) # = exp(-1.5) c(p = p, mean = 40 * p, var = 40 * p * (1 - p)) 1 - pnorm(11.5, 40 * p, sqrt(40 * p * (1 - p))) # CLT with correction 1 - pbinom(11, 40, p) # exact: P(Y >= 12) = 1 - P(Y <= 11)
Output:
p mean var 0.2231302 8.9252064 6.9337237 [1] 0.1640815 [1] 0.1633048
0.1641 with the CLT and 0.1633 exact. In the exact one, : pbinom(11, …), not pbinom(12, …).
Setting up part 4. The estimator has variance , which depends on the very you want to estimate. The way out is the worst case: is a parabola with maximum at , so the you get works for any .
Check you’ve got it: how many sessions would Chebyshev ask for with p = 0.2231?
With instead of : , that is, 1387. It drops from 2000, but it’s still far from the CLT’s 267: Chebyshev doesn’t use the fact that the mean is almost normal.
Part 4. Knowing nothing about , the worst case is . With Chebyshev (proof 4): . With the CLT, . With the CLT and , .
1 / (4 * 0.05 * 0.05^2) # Chebyshev, unknown p ceiling((qnorm(0.975) * 0.5 / 0.05)^2) # CLT, unknown p ceiling(qnorm(0.975)^2 * p * (1 - p) / 0.05^2) # CLT, with p = 0.2231
Output:
[1] 2000 [1] 385 [1] 267
2000, 385 and 267 sessions. Knowing something about saves sessions: the further from 0.5, the less variance each session has.
How it is marked. Part 1: mgf of the sum as a product (2), recognising the Poisson(60) (1). Part 2: the integer values and the correction (1.5), the calculation (1.5), the exact one (1). Part 3: (1), mean and variance of (1), the 11.5 edge and the result (1), the exact one with pbinom(11, …) (1). Part 4: Chebyshev (1.5), CLT without (1.5), CLT with (1).
Bonus
Where the 1/8 comes from. For Chebyshev to be exact, the “far” probability has to sit exactly at (further out it would add too much variance) and the rest exactly at the mean. With a probability split between 5000 and 11,000, the variance is ; setting it equal to , : at each end and at 8000.
Take with three values: with probability , with probability and with probability . It is symmetric about 8000, so . Its variance:
And only happens at 5000 and 11,000: , exactly the bound with . Since there is a variable with that mean and variance that reaches it, no better bound can hold for all of them.
x <- c(5000, 8000, 11000); px <- c(1/8, 3/4, 1/8) mu <- sum(x * px); sigma <- sqrt(sum((x - mu)^2 * px)) c(mu = mu, sigma = sigma, outside = sum(px[abs(x - mu) >= 2 * sigma]))
Output:
mu sigma outside 8000.00 1500.00 0.25
How it is marked. The variable (1), mean and standard deviation (1), the probability and the conclusion (0.5).
What’s wrong here?
Three snippets with one mistake each. Before reading the explanation, try to find it.
Snippet 1. Probability that a 20-song session (mean 3.5 and standard deviation 1.5 each) fits in 75 minutes:
pnorm(75, 20 * 3.5, 1.5)
Output:
[1] 0.9995709
The standard deviation of the sum is not 1.5, but . With 1.5 the bell is so narrow that 75 is more than three standard deviations away and you get 0.9996: “no way it runs over”. The right one is pnorm(75, 70, 1.5 * sqrt(20)) = 0.77.
Snippet 2. Bound for the probability that a song lasts between 1 and 7 minutes (mean 3.5, standard deviation 1.5):
k <- (7 - 3.5) / 1.5 1 - 1 / k^2
Output:
[1] 0.8163265
The interval is not centred on 3.5: it goes 2.5 below and 3.5 above. Chebyshev only talks about symmetric intervals, so you have to use the largest one that fits inside, , with : the bound is , not 0.82. With the of the long side, the bound talks about a wider interval than the one you are asked about.
With an interval that is not symmetric, . It is safe because lies inside .
Snippet 3. The probability of 12 or more quiet sessions out of 40 (part 3 of exercise 3), as in the hook:
p <- exp(-1.5) 1 - pnorm(12.5, 40 * p, sqrt(40 * p * (1 - p)))
Output:
[1] 0.08729737
includes 12, whose bar runs from 11.5 to 12.5. Cutting at 12.5 leaves out the whole bar for 12 and the probability drops by half: 0.087 against 0.164. For “” the edge is ; for ““, .
Practice quiz
Before moving on to the next topic, check you have got it. This quiz is here to consolidate what this article explains: the ME1 exam is not a multiple-choice test (you solve problems by hand and with R), so no mark here counts. There are 10 questions on inequalities and limit theorems: key ideas, typical mistakes and many «what does this R code print?», with the outputs from really running it. In the short answers, a decimal point or a decimal comma both work. Answer without running anything, press Check and read the explanation for each option; you can repeat it as many times as you like.
A session has 20 independent songs, each with mean 3.5 min and standard deviation 1.5. For P(session ≤ 75 min), which command is right?
pnorm(75, 20 * 3.5, 1.5 * sqrt(20))pnorm(75, 20 * 3.5, 1.5)pnorm(75, 3.5, 1.5)pnorm(75, 70, 1.5 * 20)
Solution
Answer: pnorm(75, 20 * 3.5, 1.5 * sqrt(20))
First of all: am I talking about one observation, a sum or a mean? Sum of n iid: mean nμ and standard deviation σ√n; mean: μ and σ/√n.
Mean duration 3.5 min and standard deviation 1.5. What bound does Chebyshev give for P(1 < X < 7)? (2 decimals.)
k <- min(3.5 - 1, 7 - 3.5) / 1.5 round(1 - 1 / k^2, 2)
Solution
Answer: 0.64
The interval is not symmetric (2.5 below, 3.5 above). Chebyshev talks about centred intervals, so you use the largest one that fits: k = 2.5 / 1.5 = 1.67 and the bound is 1 − 1/1.67² = 0.64. With the long side you would get 0.82, a bound for an interval wider than the one asked for.
Y is an integer (number of quiet sessions out of 40). With the normal approximation, where do you cut for P(Y ≥ 12)?
- At 11.5:
1 - pnorm(11.5, …) - At 12.5
- At 12
- At 13
Solution
Answer: At 11.5: 1 - pnorm(11.5, …)
Continuity correction: for «≥ k», k − 0.5; for «≤ k», k + 0.5.
X ≥ 0 with mean 4. What upper bound does Markov give for P(X ≥ 10)?
Solution
Answer: 0.4
Markov: P(X ≥ t) ≤ E(X)/t = 4/10 = 0.4. It only works for non-negative variables and does not need the variance.
The mean of n = 25 iid values with σ = 1.5 has standard deviation… (2 decimals)
round(1.5 / sqrt(25), 2)
Solution
Answer: 0.3
The mean of n iid values has standard deviation σ/√n = 1.5 / 5 = 0.30: the more data, the more concentrated around μ.
Match each result with what it says:
| Markov | |
| Chebyshev | |
| Central limit theorem | |
| Continuity correction |
Definitions:
- P(X ≥ t) ≤ E(X)/t, if X ≥ 0
- The mean of a sample is always equal to μ
- P(|X − μ| ≥ kσ) ≤ 1/k²
- Sums and means of many iid are nearly normal
- Move the cut by half a unit when approximating an integer variable
Solution
- Markov → P(X ≥ t) ≤ E(X)/t, if X ≥ 0
- Chebyshev → P(|X − μ| ≥ kσ) ≤ 1/k²
- Central limit theorem → Sums and means of many iid are nearly normal
- Continuity correction → Move the cut by half a unit when approximating an integer variable
A sample mean changes from one sample to another: what equals μ is its expectation.
True or false?
- Chebyshev does not need the distribution, only the mean and the standard deviation.
- The standard deviation of a sum of n iid is n·σ.
- When computing a sample size n, you round up.
- P(|X − μ| ≥ kσ) ≤ 1/k² is equivalent to P(|X − μ| < kσ) ≥ 1 − 1/k².
Solution
- T — Chebyshev does not need the distribution, only the mean and the standard deviation.
- F — The standard deviation of a sum of n iid is n·σ.
- T — When computing a sample size n, you round up.
- T — P(|X − μ| ≥ kσ) ≤ 1/k² is equivalent to P(|X − μ| < kσ) ≥ 1 − 1/k².
The standard deviation of the sum is σ√n (the variance is nσ²). The size is rounded up so the condition holds.
With Chebyshev, what minimum bound do you get for P(|X − μ| < 2σ)?
- 0.75
- 0.95
- 0.5
- 0.25
Solution
Answer: 0.75
Chebyshev’s bound is weaker than the normal’s because it holds for any distribution.
What does it print? (Approximation with continuity correction.)
p <- exp(-1.5) round(1 - pnorm(11.5, 40 * p, sqrt(40 * p * (1 - p))), 2)
Solution
Answer: 0.16
Y ~ Bin(40; e^(−1.5)) is approximated with a normal of mean 40p and standard deviation √(40p(1 − p)). Cutting at 11.5 gives 0.16; cutting at 12.5 would lose the bar for 12 (0.087).
When is the continuity correction needed?
- When a variable that only takes integer values is approximated with a normal
- Whenever pnorm is used
- Only with Chebyshev
- When n is small
Solution
Answer: When a variable that only takes integer values is approximated with a normal
It is the third question of «Before handing in»: is the variable an integer? If so, have I corrected towards the right side?
Try it in the R playground
Open the R playground on the site (or RStudio) and paste this script. It checks by simulation the three CLT answers of the exercises:
set.seed(2026) m <- 10000 # Exercise 1, part 4: mean of 30 days (with a gamma of mean 8000 and sd 1500) steps <- replicate(m, mean(rgamma(30, shape = (8000 / 1500)^2, rate = 8000 / 1500^2))) c(simulated = mean(abs(steps - 8000) < 500), CLT = 2 * pnorm(500 / (1500 / sqrt(30))) - 1) # Exercise 3, part 2: total notifications in 40 sessions total <- replicate(m, sum(rpois(40, 1.5))) c(simulated = mean(total > 50 & total <= 70), CLT = pnorm(70.5, 60, sqrt(60)) - pnorm(50.5, 60, sqrt(60))) # Exercise 3, part 3: quiet sessions Y <- replicate(m, sum(rpois(40, 1.5) == 0)) c(simulated = mean(Y >= 12), right = 1 - pnorm(11.5, 8.93, 2.63), wrong = 1 - pnorm(12.5, 8.93, 2.63))
Things to look at:
- In exercise 1 a gamma with mean 8000 and standard deviation 1500 was chosen: the CLT gets it right even though the steps are not normal.
- That the simulated total of notifications comes out close to 0.80.
- That the simulated quiet sessions are close to the
rightcolumn and far fromwrong.
Cheat sheet: inequalities and limit theorems
The essentials in 30 seconds. Markov: if . Chebyshev: . Sum of iid: mean , standard deviation . Mean: and . CLT: both, almost normal for large . Integer: continuity correction.
| I want… | Formula | In R |
|---|---|---|
| Bound for a tail, | mu / t | |
| Bound at standard deviations | 1 / k^2 | |
| Inside bound | 1 - 1 / k^2 | |
| of an interval | min(mu - a, b - mu) / sigma | |
| Law of large numbers | 1 - sigma^2 / (n * c^2) | |
| , CLT | pnorm(s, n * mu, sigma * sqrt(n)) | |
| , CLT | pnorm(x, mu, sigma / sqrt(n)) | |
| Binomial, CLT | pnorm(k + 0.5, n * p, sqrt(n * p * (1 - p))) | |
| Poisson, CLT | pnorm(k + 0.5, m, sqrt(m)) | |
| for precision , Chebyshev | ceiling(sigma^2 / (alpha * c^2)) | |
| for precision , CLT | ceiling((qnorm(1 - alpha/2) * sigma / c)^2) | |
| for a proportion, unknown | ceiling((qnorm(0.975) * 0.5 / c)^2) |
Continuity correction (integer variable):
| Event | Edge |
|---|---|
Symptom / likely cause:
| Symptom | Likely cause |
|---|---|
| Probability of the sum almost 1 or almost 0 | Standard deviation instead of |
| Chebyshev bound greater than 1 | or too small: the bound says nothing |
| Histogram of means with one bar | The sample was made outside replicate |
| The normal stuck to the floor of the histogram | Missing freq = FALSE |
Binomial approximation far from pbinom | Missing continuity correction, or on the wrong side |
Before handing in, ask yourself:
- Am I talking about one observation, a sum or a mean? Which standard deviation does it get?
- Does the bound go with (outside) or with (inside)?
- Is the variable an integer? If so, have I corrected, and on the right side?
- Have I rounded up?
For your script
The topic’s code, commented, for your exam .R file. Your own functions and the code of the solved exercises, without statements:
# ===== Topic 7: inequalities and limit theorems =====
# --- Bounds ---
markov_bound <- function(mean, t) mean / t # P(X >= t) <= E(X)/t, X >= 0
cheb_outside <- function(k) 1 / k^2 # P(|X - mu| >= k sigma) <= 1/k^2
cheb_inside <- function(k) 1 - 1 / k^2 # P(|X - mu| < k sigma) >= 1 - 1/k^2
k_interval <- function(a, b, mu, sigma) min(mu - a, b - mu) / sigma # non-symmetric interval
lln_bound <- function(sigma, n, c) 1 - sigma^2 / (n * c^2) # P(|mean - mu| < c) >= ...
# --- CLT ---
clt_sum <- function(s, n, mu, sigma, tail = "left") # P(S <= s) or P(S > s)
if (tail == "left") pnorm(s, n * mu, sigma * sqrt(n)) else 1 - pnorm(s, n * mu, sigma * sqrt(n))
clt_mean <- function(x, n, mu, sigma, tail = "left") # P(mean <= x) or P(mean > x)
if (tail == "left") pnorm(x, mu, sigma / sqrt(n)) else 1 - pnorm(x, mu, sigma / sqrt(n))
clt_binom_le <- function(k, n, p) pnorm(k + 0.5, n * p, sqrt(n * p * (1 - p))) # P(S <= k)
clt_binom_ge <- function(k, n, p) 1 - pnorm(k - 0.5, n * p, sqrt(n * p * (1 - p))) # P(S >= k)
clt_pois_between <- function(a, b, m) pnorm(b + 0.5, m, sqrt(m)) - pnorm(a - 0.5, m, sqrt(m)) # P(a <= T <= b)
# --- Sample size (rounded up) ---
# round(…, 8) before ceiling: with sqrt() and ^2, 320 can come out as 320.0000001 and go up to 321
n_cheb <- function(sigma, c, alpha = 0.05) ceiling(round(sigma^2 / (alpha * c^2), 8))
n_clt <- function(sigma, c, alpha = 0.05) ceiling(round((qnorm(1 - alpha / 2) * sigma / c)^2, 8))
# --- Checking the CLT by simulation (generates the data INSIDE the function) ---
check_clt <- function(generate, n, mu, sigma, m = 10000) {
means <- replicate(m, mean(generate(n)))
par(mfrow = c(1, 2))
hist(means, freq = FALSE, breaks = 40, main = paste("n =", n))
curve(dnorm(x, mu, sigma / sqrt(n)), add = TRUE, col = "red", lwd = 2)
qqnorm(means); qqline(means, col = "red")
c(mean = mean(means), sd = sd(means), sd_theoretical = sigma / sqrt(n))
}
# example: check_clt(function(n) rexp(n, 2), 30, 0.5, 0.5)
# --- Solved exercises ---
# Steps: N(8000, 1500) against Chebyshev; mean of 30 days
pnorm(11000, 8000, 1500) - pnorm(5000, 8000, 1500) # 0.95 (bound: 0.75)
lln_bound(1500, 30, 500); 2 * pnorm(500 / (1500 / sqrt(30))) - 1 # 0.70 and 0.93
# Battery: density 12 x^2 (1 - x), 30 sessions
f <- function(x) 12 * x^2 * (1 - x)
mu <- integrate(function(x) x * f(x), 0, 1)$value
s2 <- integrate(function(x) x^2 * f(x), 0, 1)$value - mu^2
clt_sum(19, 30, mu, sqrt(s2), tail = "right") # 0.18
n_clt(sqrt(s2), 0.05); n_cheb(sqrt(s2), 0.05) # 62 and 320
# Notifications: Poisson(1.5) per session, 40 sessions
clt_pois_between(51, 70, 60); ppois(70, 60) - ppois(50, 60) # 0.80
p <- dpois(0, 1.5)
clt_binom_ge(12, 40, p); 1 - pbinom(11, 40, p) # 0.16
What’s next?
With the CLT you already know that the mean of a sample is almost normal. The next ME1 topic is sampling distributions: what exact distribution the mean, the sample variance and their ratios have when the population is normal, and where the chi-squared, Student’s t and Snedecor’s F that you will use in confidence intervals come from.
If you want to review first, you have the theory, the proofs and the practice of this topic, and the normal distribution, where pnorm, qnorm and standardising come from.
Did this article help you? Here is how you can support SergioLearns →
Ready for the exam?ME1 EC2 mock exam — 4 hours with R beside you, from the normal to confidence intervals, four versions and a mark out of 50 (and why exercise 1 is worth double)


