c(mean = (0 + 20) / 2,
height = 1 / (20 - 0),
p_above_15 = punif(15, min = 0, max = 20, lower.tail = FALSE)) mean height p_above_15
10.00 0.05 0.25
POSC 8410
1. \(X \sim \text{Unif}(0, 20)\). What is \(E[X]\)? What is \(P(X > 15)\)? What is the height of the density?
All three come from the uniform formulas with \(a = 0\) and \(b = 20\).
Check all three in R. punif() is the uniform CDF, and lower.tail = FALSE asks for the area above 15 instead of below it:
c(mean = (0 + 20) / 2,
height = 1 / (20 - 0),
p_above_15 = punif(15, min = 0, max = 20, lower.tail = FALSE)) mean height p_above_15
10.00 0.05 0.25
Notice that the height here is 0.05. On \(\text{Unif}(0, 0.5)\) from the slides it was 2. Height is not probability. It is probability per unit of \(x\), and it only becomes a probability when you multiply by a width (or, in general, integrate). Since every interval of length 5 on \([0, 20]\) has the same area, \(P(X > 15)\) is the same as \(P(3 < X < 8)\), or any other five-unit stretch.
2. Test scores are \(N(500, 100^2)\). What share fall between 400 and 600? Use pnorm to check.
400 and 600 are each exactly one standard deviation from the mean (500 minus 100, and 500 plus 100). So this is the first number in the 68–95–99.7 rule: about 68%.
pnorm() gives the area below a value. The area between two values is the CDF at the top minus the CDF at the bottom, \(F(600) - F(400)\):
pnorm(600, mean = 500, sd = 100) - pnorm(400, mean = 500, sd = 100)[1] 0.6826895
You get the same answer by standardizing first. \(z = (600 - 500)/100 = 1\) and \(z = (400 - 500)/100 = -1\), so on the standard normal:
pnorm(1) - pnorm(-1)[1] 0.6826895
This is why standardizing works: any normal question can be translated into a question about \(Z \sim N(0, 1)\).
3. What score puts a student at the 90th percentile? Use qnorm.
Now we go the other way. Instead of a score and asking for a probability, we have a probability (0.90) and want the score \(x\) with \(F(x) = 0.90\). That is what qnorm() does:
qnorm(0.90, mean = 500, sd = 100)[1] 628.1552
qnorm(0.90) # the same thing as a z-score[1] 1.281552
About 628. Equivalently, the 90th percentile is \(1.28\) standard deviations above the mean: \(500 + 1.28 \times 100 \approx 628\).
Compare the 1.28 here with the 1.96 from the slides. Why are they different? \(1.96\) leaves 2.5% in the upper tail, so 95% lies between \(-1.96\) and \(+1.96\). \(1.28\) leaves 10% in the upper tail and ignores the lower tail.
4. A polling estimate has standard deviation of 2 points. Roughly how far from the truth would you expect it to be, 95% of the time?
About 4 points either way. From the 68–95–99.7 rule, 95% of a normal distribution lies within two standard deviations of its mean, and two standard deviations is \(2 \times 2 = 4\) points. Using the exact multiplier, \(1.96 \times 2 = 3.92\):
c(rule_of_thumb = 2 * 2,
exact = qnorm(0.975) * 2)rule_of_thumb exact
4.000000 3.919928
This is where the “margin of error” on a poll comes from. Two assumptions: