What is the typical gas mileage of a car?
Using the mtcars data we will give the best guess of average gas mileage.
Goal: give the best guess of what the average gas mileage is and check the deviation.
What is the typical gas mileage of a car?
Using the mtcars data we will give the best guess of average gas mileage.
Goal: give the best guess of what the average gas mileage is and check the deviation.
A 95% confidence interval comes from a method that captures the true mean about 95% of the time.
Sample mean:
\[\bar{x} = \frac{1}{n}\sum_{i=1}^{n} x_i\]
Sample standard deviation:
\[s^2 = \frac{1}{n-1}\sum_{i=1}^{n}(x_i-\bar{x})^2 \qquad = \sqrt{s^2}\]
\[\bar{x} \;\pm\; t^* \cdot \frac{s}{\sqrt{n}}\]
Bigger \(n\) makes the margin of error smaller. Bigger \(s\) makes it larger.
x <- mtcars$mpg n <- length(x) xbar <- mean(x) s <- sd(x) se <- s / sqrt(n) tcrit <- qt(0.975, df = n - 1) c(xbar - tcrit * se, xbar + tcrit * se) t.test(x)$conf.int
Conclusion: most cars fall between 15 and 25 mpg, and the mean sits near the middle.
Conclusion: the 4-cylinder and 8-cylinder intervals do not overlap, so their average mileage is different.
Displays margin of error, standard deviation and the sample size
The average mileage is about 20 mpg, and we are 95% confident the true mean is between about 17.9 and 22.3 mpg.