The Question

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.

Statistics tools used

  • Point estimate: The sample mean
  • Confidence interval: a range around that guess.

A 95% confidence interval comes from a method that captures the true mean about 95% of the time.

Point Estimate Equations

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}\]

Confidence Interval

\[\bar{x} \;\pm\; t^* \cdot \frac{s}{\sqrt{n}}\]

  • \(\dfrac{s}{\sqrt{n}}\) is the standard error, the typical error of the sample mean.
  • \(t^*\) is a multiplier from the t-distribution, about 2 for a 95% interval.
  • The part after the \(\pm\) is the margin of error.

Bigger \(n\) makes the margin of error smaller. Bigger \(s\) makes it larger.

The R Code

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               

Histogram On MPG

Conclusion: most cars fall between 15 and 25 mpg, and the mean sits near the middle.

Dot And Whisker Plot On Engine Size

Conclusion: the 4-cylinder and 8-cylinder intervals do not overlap, so their average mileage is different.

3D Plot

Displays margin of error, standard deviation and the sample size

Summarization On The Data

  • Sample mean: 20.09 mpg
  • Sample standard deviation: 6.03 mpg
  • Standard error: 1.07 mpg
  • Margin of error: 2.17 mpg
  • 95% confidence interval: (17.92, 22.26) mpg

What Did We Learn?

The average mileage is about 20 mpg, and we are 95% confident the true mean is between about 17.9 and 22.3 mpg.