This report contains a series of steps to test the hypothesis that, on average, US cars are less efficient than Japanese cars by comparing the means of their miles per gallon (MPG). The structure of the report is as follows: data input, normality and variance assumption checks, log transformation followed by assumption checks, t-test, and analysis.
To begin the test, we import the data set into R.
dat <- read.csv("https://raw.githubusercontent.com/tmatis12/datafiles/main/US_Japanese_Cars.csv")
Next, we have to know how many sample data are available to use.
## The total sample for US Cars is 35
##
## The total sample for Japanese Cars is 28
The available sample data for both types of cars are relatively small (less than 40). This is an early indicator that a t-test is more appropriate to use rather than a z-test. Next, we have to check whether the distribution and variance of the data violate the assumptions needed to use the t-test.
There are two assumptions that need to be true to use the t-test:
Both samples are approximately normally distributed.
The variance are equal.
To check the distribution, we use a Normal Probability Plot for both samples.
From the plots, we can see that the majority of the observations for both samples are relatively close to the reference line. Therefore, both samples can be considered approximately normally distributed.
The second assumption will be check by using box plot.
Visually, the Japanese car sample data have a noticeably wider interquartile range than the US car sample data. This means that the second assumption may not be true, as the variances do not appear to be equal.
Based on these observations, the t-test cannot be used directly to test the data. Therefore, we try to transform the data using a logarithmic transformation to check whether the transformed data can satisfy both assumptions.
Next, we repeat the steps of Assumption Check on the transformed data.
After applying the logarithmic transformation, the Normal Probability Plots show that the majority of the observations for both samples remain close to the reference line. Therefore, the transformed data can still be considered approximately normally distributed.
The box plot of the transformed data shows that the spread between the two samples is more similar after the transformation. Therefore, the variances can be considered approximately equal.
Based on these results, the transformed data satisfy both assumptions required for the t-test. Therefore, a two-sample t-test can be used to test whether there is a significant difference between the mean mpg of US cars and Japanese cars.
We set the hypothesis of the testing: null hypothesis is that the mean mpg of US cars is equal to the mean mpg of Japanese cars. The alternative hypothesis is that the mean mpg of US cars is lower than the mean mpg of Japanese cars. Because the alternative specifically states lower mpg, one-tail test will be used.
\[H_0 : \mu_{us} = \mu_{jpn} \\H_1 : \mu_{us} < \mu_{jpn}\]
##
## Two Sample t-test
##
## data: log(dat$USCars) and log(dat$JapaneseCars)
## t = -9.4828, df = 61, p-value = 6.528e-14
## alternative hypothesis: true difference in means is less than 0
## 95 percent confidence interval:
## -Inf -0.4366143
## sample estimates:
## mean of x mean of y
## 2.741001 3.270957
From the t-testing, we can observe the mean of log(US Cars) is 2.741 and mean of log(Japanese Cars) is 3.27. The p-value obtained from the t-test is \(6.528×10−146.528\times10^{-14}\), which is much smaller than the significance level of 0.05. Therefore, there is enough evidence to reject the null hypothesis. This result supports the alternative hypothesis that US cars have a lower average MPG than Japanese cars.
Below are the complete R Code used for building this report.
#input data
dat <- read.csv("https://raw.githubusercontent.com/tmatis12/datafiles/main/US_Japanese_Cars.csv")
#length of sample
cat("The total sample for US Cars is", length(dat$USCars) - sum(is.na(dat$USCars)))
cat("\nThe total sample for Japanese Cars is", length(dat$JapaneseCars) - sum(is.na(dat$JapaneseCars)))
#npp check
par(mfrow = c(1,2))
#NPP for US Cars
qqnorm(dat$USCars,
main = "NPP - US Cars")
qqline(dat$USCars,
col = "blue")
#NPP for Japan Cars
qqnorm(dat$JapaneseCars,
main = "NPP - Japanese Cars")
qqline(dat$JapaneseCars,
col = "red")
#boxplot
boxplot(dat$USCars, dat$JapaneseCars,
names = c("US Car", "Japanense Car"),
col = c("blue", "red"),
main = "Box Plot of Fuel Efficiency Between US Car and Japan Car",
xlab = "Car Origin",
ylab = "Miles per Gallon ")
#npp transformed
par(mfrow = c(1,2))
#NPP for US Cars
qqnorm(log(dat$USCars),
main = "NPP - US Cars")
qqline(log(dat$USCars),
col = "blue")
#NPP for Japan Cars
qqnorm(log(dat$JapaneseCars),
main = "NPP - Japanese Cars")
qqline(log(dat$JapaneseCars),
col = "red")
#boxplot transformed
boxplot(log(dat$USCars), log(dat$JapaneseCars),
names = c("US Car", "Japanense Car"),
col = c("blue", "red"),
main = "Box Plot of Fuel Efficiency Between US Car and Japan Car",
xlab = "Car Origin",
ylab = "Miles per Gallon ")
#t-test
t.test(log(dat$USCars), log(dat$JapaneseCars), var.equal = TRUE, alternative = "less")