2024-09-21
Hypothesis testing is a statistical method used to make decisions about a population parameter based on sample data.
We will perform a t-test to see if heavier cars have significantly lower MPG.
\(H_0\): Heavier cars have the same average MPG as the population (μ = 20).
\(H_A\): Heavier cars have significantly lower MPG than the population.
## Loading public data set heavy_cars <- subset(mtcars, wt > median(mtcars$wt)) ## Performing t-test t.test(heavy_cars$mpg, mu = 20)
## ## One Sample t-test ## ## data: heavy_cars$mpg ## t = -6.3224, df = 15, p-value = 1.369e-05 ## alternative hypothesis: true mean is not equal to 20 ## 95 percent confidence interval: ## 14.20857 17.12893 ## sample estimates: ## mean of x ## 15.66875
Having performed the t-test, we will next visualize the relationship between car weight and fuel efficiency using a scatter plot with a linear trend line.
An additional hypothesis we could have would be:
\(H_0\): Car weight has no significant effect on MPG (fuel efficiency).
\(H_A\): Heavier cars have significantly lower MPG than lighter cars.
## `geom_smooth()` using formula = 'y ~ x'
In the following 3D scatter plot, we will visualize the relationship between car weight, MPG, and quarter-mile time (or qsec).
Hypothesis:
\(H_0\): There is no relationship between car weight, MPG, and quarter-mile time.
\(H_A\): Heavier cars have lower MPG and longer quarter-mile times.
Lastly, in the following plot, we compare the fuel efficiency (mpg) of cars with different cylinder counts.
Hypothesis:
\(H_0\): There is no significant difference for the MPG of cars with 4, 6, or 8 cylinders.
\(H_A\): Cars that have 6 or 8 cylinders have significantly lower MPG than those with 4 cylinders.
Hypothesis testing is an essential tool in statistics that allows us to make informed decisions based on sample data.
Through this method, we’re able to precisely test assumptions about populations.