Fuel efficiency is an important measure of vehicle performance. This
project investigates relationships between vehicle characteristics and
fuel efficiency using the mtcars dataset in R.
The analysis focuses on two main questions:
The mtcars dataset is a built-in dataset in R containing
information on 32 automobiles and 11 variables. The dataset describes
vehicle characteristics such as engine size, horsepower, weight,
transmission type, and number of cylinders. The main outcome variable in
this analysis is mpg, which represents fuel efficiency
measured in miles per gallon. # Data Preparation The original
mtcars dataset was preserved, while a working copy was
created for data preparation. The transmission, engine type, and
cylinder variables were converted into categorical factors to support
appropriate statistical analysis. The dataset was also checked for
missing values, and no missing observations were identified. #
Exploratory Analysis The exploratory analysis was conducted to examine
the distribution of fuel efficiency and identify differences in MPG
across cylinder groups. Descriptive statistics and graphical methods
were used to summarize the data before conducting formal statistical
tests. ## Fuel Efficiency Summary
The distribution of fuel efficiency was examined using descriptive statistics. The mean MPG was 20.09, while the median was 19.20. The standard deviation was approximately 6.02 MPG, indicating noticeable variation in fuel efficiency across the vehicles. The mean being slightly higher than the median also suggests some right-skewness in the distribution.
hist(cardata_clean$mpg)
Cars with different numbers of cylinders showed clear differences in fuel efficiency. The mean MPG was 26.66 for 4-cylinder vehicles, 19.74 for 6-cylinder vehicles, and 15.10 for 8-cylinder vehicles. These results suggest an association between cylinder group and fuel efficiency, with lower-cylinder vehicles generally having higher MPG.
boxplot(mpg ~ cylinder_group, data = cardata_clean, xlab = ‘cylinder_group’, ylab = ‘mpg’ )
boxplot( mpg ~ cylinder_group, data = cardata_clean, main = “Fuel Efficiency by Cylinder Group”, xlab = “Cylinder Group”, ylab = “Miles per Gallon (MPG)” )
The exploratory analysis indicated differences in fuel efficiency across cylinder groups. Statistical tests were therefore conducted to determine whether these differences were statistically significant and to assess whether the assumption of equal variances was satisfied.
Levene’s test was used to assess whether the variance in MPG was similar across the three cylinder groups.
Because Levene’s test indicated that the variances were not equal across the cylinder groups, Welch’s one-way ANOVA was used to test whether mean MPG differed between the groups.
The Games–Howell post-hoc test was conducted to identify which pairs of cylinder groups differed significantly in mean MPG. This test was selected because the Levene’s test indicated unequal variances.
The relationship between vehicle weight and fuel efficiency was examined using Pearson’s correlation coefficient.
A simple linear regression model was used to examine whether vehicle weight predicts fuel efficiency. Vehicle weight was treated as the predictor variable, while MPG was treated as the outcome variable.
A 95% confidence interval was calculated for the regression coefficient of vehicle weight. The interval provides a range of values for the population-level change in MPG associated with an additional 1,000 pounds of vehicle weight.
The residuals-versus-fitted-values plot was examined to assess whether the linear regression model adequately represented the relationship between vehicle weight and fuel efficiency.
plot(regression, which = 1)
The analysis identified clear differences in fuel efficiency across cylinder groups. Mean MPG was highest among 4-cylinder vehicles and lowest among 8-cylinder vehicles, with all three cylinder groups showing statistically significant pairwise differences.
Vehicle weight also showed a strong negative linear association with fuel efficiency. The regression analysis indicated that heavier vehicles tended to have lower MPG, and vehicle weight explained approximately 75% of the observed variation in MPG in the simple linear regression model.
The regression diagnostic indicated some curvature in the residual pattern, suggesting that the relationship may not be perfectly linear. Therefore, the regression results should be interpreted as describing the observed linear relationship rather than establishing a causal effect.
This analysis is based on the mtcars dataset, which
contains a relatively small sample of 32 vehicles. The dataset
represents a specific collection of automobiles and may not be
representative of all vehicles.
The analyses identify statistical associations and differences within the dataset but do not establish causal relationships. In addition, the simple linear regression model uses vehicle weight as the only predictor, so other factors that may influence fuel efficiency are not accounted for.
This analysis examined fuel efficiency in the mtcars
dataset using descriptive statistics, hypothesis testing, correlation
analysis, and simple linear regression. The results showed substantial
differences in MPG across cylinder groups and a strong negative
relationship between vehicle weight and fuel efficiency.
Overall, the analysis demonstrates how R can be used to explore data, test statistical assumptions, conduct appropriate statistical tests, and quantify relationships between variables.