1 Data Import

This data set includes measurements on the fuel efficiency of cars manufactured in both the United States and Japan. Fuel efficiency of the cars is measured in miles traveled per gallon of fuel consumed. Data was recorded for 35 US made vehicles and 28 Japanese made vehicles. The data from the file US_Japanese_Cars.csv can be found in the code chunk below.

sampledata<-read.csv("https://raw.githubusercontent.com/tmatis12/datafiles/main/US_Japanese_Cars.csv")
sampledata$USCars<-as.numeric(sampledata$USCars)
sampledata$JapaneseCars<-as.numeric(sampledata$JapaneseCars)
rmarkdown::paged_table(sampledata)

An environmental group would like to test the hypothesis that the fuel efficiency of cars manufactured in the US is less than the fuel efficiency of cars manufactured in Japan using the sampled data above.

2 Normal Probability Plots

To begin our analysis, we start by taking Normal Probability Plots of our two different populations, US Cars and Japanese Cars. These plots are used to determine whether or not the populations are normally distributed.

2.1 US Cars

qqnorm(sampledata$USCars, main = "Normal Probability Plot for US Cars", ylab = "Miles Per Gallon", col = "blue")
qqline(sampledata$USCars, col = "red")

2.2 Japanese Cars

qqnorm(sampledata$JapaneseCars, main = "Normal Probability Plot for Japanese Cars", ylab = "Miles Per Gallon", col = "red")
qqline(sampledata$JapaneseCars, col = "blue")

2.3 NPP Discussion

The Normal Probability Plots for both US and Japanese cars appear to be mostly normally distributed. There appears to be a couple of outliers in both plots that make the determination a little less clear cut.

3 Box-and-Whisker Plots

Next, we will take Box-and-Whisker Plots of our two different populations, US Cars and Japanese Cars. These plots are used to determine whether or not the populations have constant variance.

3.1 Side-by-Side Plot

boxplot(sampledata$USCars, sampledata$JapaneseCars, main = "US & Japanese Box-and-Whisker Plots", names = c("US Cars", "Japanese Cars"), ylab = "Miles Per Gallon", col = c("blue", "red"))

3.2 Box Plot Discussion

The whiskers in both plots all have similar length. However, the Inner Quartile Range (IQR), or the box, of the US plot is much more condensed than the Japanese plot. This indicates that the US data has a smaller variance than the Japanese data and we cannot assume that both populations have constant variance.

4 Log Transformation

To correct for the unequal variances, a transformation of the data will be performed to get similar results between the two populations. Specifically, this is done by performing a logarithmic transformation of the data. The code chunk below shows the transformation of the data.

USCars1<-log(sampledata$USCars)
JapaneseCars1<-log(sampledata$JapaneseCars)
print("US Transformed Data")
## [1] "US Transformed Data"
print(USCars1)
##  [1] 2.890372 2.708050 2.890372 2.772589 2.833213 2.708050 2.639057 2.639057
##  [9] 2.639057 2.708050 2.708050 2.639057 2.708050 2.639057 3.091042 2.890372
## [17] 3.044522 3.044522 2.302585 2.302585 2.397895 2.197225 3.332205 3.218876
## [25] 2.944439 2.772589 2.833213 2.944439 2.890372 2.639057 2.639057 2.639057
## [33] 2.639057 2.484907 2.564949
print("Japanese Transformed Data")
## [1] "Japanese Transformed Data"
print(JapaneseCars1)
##  [1] 3.178054 3.295837 3.295837 3.218876 3.433987 3.555348 3.178054 2.944439
##  [9] 3.332205 3.135494 3.295837 2.995732 3.091042 2.890372 2.995732 3.433987
## [17] 3.465736 3.433987 3.465736 3.178054 3.258097 3.367296 3.178054 3.178054
## [25] 3.496508 3.496508 3.465736 3.332205       NA       NA       NA       NA
## [33]       NA       NA       NA

4.1 Log Transformed NPPs

qqnorm(USCars1, main = "Log NPP for US Cars", ylab = "Log(MPG)", col = "blue")
qqline(USCars1, col = "red")

qqnorm(JapaneseCars1, main = "Log NPP for Japanese Cars", ylab = "Log(MPG)", col = "red")
qqline(JapaneseCars1, col = "blue")

4.2 Log Transformed Box-and-Whisker Plots

boxplot(USCars1, JapaneseCars1, main = "Log US & Japanese Box-and-Whisker Plots", names = c("US Cars", "Japanese Cars"), ylab = "Log(MPG)", col = c("blue", "red"))

4.3 Log Transformation Discussion

The Normal Probability Plots and Box-and-Whisker Plots were re-generated using the logarithmic transformed data. The NPPs show a slightly clearer normal distribution of the data. A significant difference can be seen in the Box-and-Whisker Plots. The IQRs between the two different plots are essentially the same size. The whiskers on US Cars are practically equal length while the whiskers on Japanese cars vary a decent amount. Overall, this transformation corrects the issue of unequal variances and allows us to use a Two-Sample T-Test with pooled variance on the data.

5 Two-Sample T-Test with Pooled Variance

The null hypothesis states that the mean fuel efficiency of US and Japanese cars is equal. An environmental group proposed an alternative hypothesis which states that the mean fuel efficiency of US cars is less than the mean fuel efficiency of Japanese cars. A Two-Sample T-Test with Pooled Variance and 0.05 level of significance will be used to determine which hypothesis is correct. The code chunk for the T-Test can be seen below.

t.test(USCars1, JapaneseCars1, var.equal = TRUE)
## 
##  Two Sample t-test
## 
## data:  USCars1 and JapaneseCars1
## t = -9.4828, df = 61, p-value = 1.306e-13
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -0.6417062 -0.4182053
## sample estimates:
## mean of x mean of y 
##  2.741001  3.270957

Since the p-value, 1.306e-13, from the T-Test is less than the level of significance of 0.05, the environmental group’s hypothesis of US Cars having a mean fuel efficiency less than Japanese Cars mean fuel efficiency is correct. The log(mpg) mean of US Cars is 2.741001 while the log(mpg) mean of Japanese Cars is 3.270957. This analysis shows that Japanese Cars have better fuel efficiency than US Cars.

6 Complete R Code

# Data Import
sampledata<-read.csv("https://raw.githubusercontent.com/tmatis12/datafiles/main/US_Japanese_Cars.csv")
sampledata$USCars<-as.numeric(sampledata$USCars)
sampledata$JapaneseCars<-as.numeric(sampledata$JapaneseCars)
rmarkdown::paged_table(sampledata)

## US Cars
qqnorm(sampledata$USCars, main = "Normal Probability Plot for US Cars", ylab = "Miles Per Gallon", col = "blue")
qqline(sampledata$USCars, col = "red")

## Japanese Cars
qqnorm(sampledata$JapaneseCars, main = "Normal Probability Plot for Japanese Cars", ylab = "Miles Per Gallon", col = "red")
qqline(sampledata$JapaneseCars, col = "blue")

## Side-by-Side Plot
boxplot(sampledata$USCars, sampledata$JapaneseCars, main = "US & Japanese Box-and-Whisker Plots", names = c("US Cars", "Japanese Cars"), ylab = "Miles Per Gallon", col = c("blue", "red"))

# Log Transformation
USCars1<-log(sampledata$USCars)
JapaneseCars1<-log(sampledata$JapaneseCars)
print("US Transformed Data")
print(USCars1)
print("Japanese Transformed Data")
print(JapaneseCars1)

## Log Transformed NPPs
qqnorm(USCars1, main = "Log NPP for US Cars", ylab = "Log(MPG)", col = "blue")
qqline(USCars1, col = "red")

qqnorm(JapaneseCars1, main = "Log NPP for Japanese Cars", ylab = "Log(MPG)", col = "red")
qqline(JapaneseCars1, col = "blue")

## Log Transformed Box-and-Whisker Plots
boxplot(USCars1, JapaneseCars1, main = "Log US & Japanese Box-and-Whisker Plots", names = c("US Cars", "Japanese Cars"), ylab = "Log(MPG)", col = c("blue", "red"))

# Two-Sample T-Test with Pooled Variance
t.test(USCars1, JapaneseCars1, var.equal = TRUE)