2023-03-15

library(tinytex)

Showcasing Population Mean using Cars

Using the mtcars dataset in R, we will be learning about the population mean by examing the Miles per Gallon (mpg) and the Displacement (disp)

What is Population Mean?

Population mean is calculating the mean for the entire group, every member. In this presentation the population mean will be of every car.

This will be the Population Mean for every vehicles MPG and DISP.

Formula for Population and Sample means:

\[ \mu = \frac{\sum x}{N} \]

Calculating the Population Mean:

\[ \mu = \frac{\sum X}{N} = \] \[ \mu = \frac{642.9}{32} = 20.09062 \]

ggplot Histogram of mpg Pop Mean

The green line is the pop mean:

ggplot Histogram of displacement Pop Mean

The red line is the pop mean:

Scatter plot of Mean MPG using Plotly

Code to generate the Scatter plot using Plotly

library(plotly, warn.conflicts = FALSE)

sorted_data <- mtcars[order(rownames(mtcars)),]

p <- plot_ly(sorted_data, x = ~disp, y = ~rownames(sorted_data), type = “scatter”, mode = “lines”)

p <- p %>% layout(xaxis = list(title = “Displacement”), yaxis = list(title = “Car Model”), title = “Line Graph of Displacement by Car Model”)

p