An environmental group would like to test the hypothesis that the mean mpg of cars manufactured in the US is less than that of cars manufactured in Japan. Towards this end, n1=35 US cars and n2=28 Japanese cars were sampled and tested for mpg fuel efficiency. The data is assumed to be a random sample from a large population of US and Japanese cars. All of the data manipulation, analysis and plotting is done within R.
The data is read directly from the web with read.csv().
df<-read.csv("https://raw.githubusercontent.com/tmatis12/datafiles/main/US_Japanese_Cars.csv")
The file contains one column for each country, the first one holding the US cars and the second one holding the Japanese cars. The two columns are extracted by position. Since the two samples have different sizes, the shorter column is padded with missing values, and these are removed by keeping only the entries for which is.na() is false.
us<-df[,1]
japan<-df[,2]
us<-us[!is.na(us)]
japan<-japan[!is.na(japan)]
length(us)
## [1] 35
length(japan)
## [1] 28
The sample sizes are 35 and 28, as stated in the problem.
qqnorm(us,main="Normal Probability Plot of the mpg of US Cars")
qqline(us)
The points do not follow the straight line well. There is a systematic curvature and the largest observations fall clearly above the line, which is the pattern produced by a distribution that is skewed to the right. The normality assumption is therefore questionable for the US cars.
qqnorm(japan,main="Normal Probability Plot of the mpg of Japanese Cars")
qqline(japan)
The points of the Japanese cars follow the straight line much more closely, with only minor departures in the tails. The normality assumption is reasonable for this group.
boxplot(us,japan,main="mpg of US and Japanese Cars",names=c("US","Japan"),xlab="Country of Manufacture",ylab="mpg",col=c("blue","red"))
sd(us)
## [1] 4.054668
sd(japan)
## [1] 4.70323
The two boxes have a comparable height, and the sample standard deviations are close to each other, so there is no severe violation of the constant variance assumption. The US box, however, is not symmetric around its median and shows observations plotted far above the upper whisker, which again reflects the right skewness seen in the normal probability plot. The main problem with the original data is the shape of the US distribution, not the difference in variability.
The log transform is applied to both samples.
lus<-log(us)
ljapan<-log(japan)
qqnorm(lus,main="Normal Probability Plot of the log of the mpg of US Cars")
qqline(lus)
qqnorm(ljapan,main="Normal Probability Plot of the log of the mpg of Japanese Cars")
qqline(ljapan)
boxplot(lus,ljapan,main="log of the mpg of US and Japanese Cars",names=c("US","Japan"),xlab="Country of Manufacture",ylab="log(mpg)",col=c("blue","red"))
sd(lus)
## [1] 0.2466874
sd(ljapan)
## [1] 0.1820182
Let mu1 be the mean of the log of the mpg of US cars and mu2 be the mean of the log of the mpg of Japanese cars. The claim of the environmental group is that the US mean is smaller, so this claim is placed in the alternative hypothesis and the test is one sided.
H0: mu1 - mu2 = 0
H1: mu1 - mu2 < 0
The level of significance is 0.05.
mean(lus)
## [1] 2.741001
mean(ljapan)
## [1] 3.270957
The sample average of the log of the mpg is about 2.741 for the US cars and about 3.271 for the Japanese cars.
The two samples are independent and the variances were found to be comparable, so the pooled version of the two sample t-test is used with var.equal=TRUE. The argument alternative=“less” produces the one sided test described above.
t.test(lus,ljapan,alternative="less",var.equal=TRUE)
##
## Two Sample t-test
##
## data: lus and ljapan
## 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
The pooled two sample t-test returns a test statistic of about -9.48 with 61 degrees of freedom and a p-value of the order of 10^-14, which is far smaller than the level of significance of 0.05. The null hypothesis is therefore rejected.
There is very strong statistical evidence that the mean of the log of the mpg of cars manufactured in the US is less than the mean of the log of the mpg of cars manufactured in Japan. Since the log is an increasing function, the same ordering holds on the original scale, and the sample means of about 16.0 mpg for the US cars and about 26.8 mpg for the Japanese cars show that the difference is also large in practical terms. The hypothesis of the environmental group is supported by the data.
df<-read.csv("https://raw.githubusercontent.com/tmatis12/datafiles/main/US_Japanese_Cars.csv")
us<-df[,1]
japan<-df[,2]
us<-us[!is.na(us)]
japan<-japan[!is.na(japan)]
length(us)
length(japan)
qqnorm(us,main="Normal Probability Plot of the mpg of US Cars")
qqline(us)
qqnorm(japan,main="Normal Probability Plot of the mpg of Japanese Cars")
qqline(japan)
boxplot(us,japan,main="mpg of US and Japanese Cars",names=c("US","Japan"),xlab="Country of Manufacture",ylab="mpg",col=c("blue","red"))
sd(us)
sd(japan)
lus<-log(us)
ljapan<-log(japan)
qqnorm(lus,main="Normal Probability Plot of the log of the mpg of US Cars")
qqline(lus)
qqnorm(ljapan,main="Normal Probability Plot of the log of the mpg of Japanese Cars")
qqline(ljapan)
boxplot(lus,ljapan,main="log of the mpg of US and Japanese Cars",names=c("US","Japan"),xlab="Country of Manufacture",ylab="log(mpg)",col=c("blue","red"))
sd(lus)
sd(ljapan)
mean(lus)
mean(ljapan)
t.test(lus,ljapan,alternative="less",var.equal=TRUE)
Comments on the Differences Between the Plots
The improvement produced by the transformation is most visible in the normal probability plot of the US cars. The log transform compresses the large values and stretches the small ones, so the upward curvature in the upper tail disappears and the points now fall close to the straight line. The plot of the Japanese cars was already acceptable before the transformation and it remains acceptable after it, so very little changes for that group.
The same effect appears in the box plots. On the log scale the US box is more symmetric around its median and the extreme observations that stood out in the original box plot are no longer separated from the rest of the data. The two spreads remain comparable, so the constant variance assumption is still reasonable.
Because the transformed data satisfies both assumptions of the pooled two sample t-test better than the original data, the log of the mpg is used for the remaining questions.