cars <- read.csv("https://raw.githubusercontent.com/tmatis12/datafiles/main/US_Japanese_Cars.csv")
# Removing the missing values
US <- na.omit(cars$USCars)
Japan <- na.omit(cars$JapaneseCars)
# Sample sizes
length(US)
## [1] 35
length(Japan)
## [1] 28
qqnorm(US, main = "NPP for U.S. Cars")
qqline(US)
qqnorm(Japan, main = "NPP for Japanese Cars")
qqline(Japan)
In these figures, the Japanese car data appear reasonably close to a straight line and therefore appear approximately Normally distributed. On the other hand, the U.S. car data show more noticeable deviations from the straight line, especially in the tails. So, Normality is less convincing for the original U.S. mpg data.
boxplot(US, Japan, names = c("U.S.", "Japan"), ylab = "MPG", main = "MPG of U.S. and Japanese Cars")
var(US)
## [1] 16.44034
var(Japan)
## [1] 22.12037
Reggarding the variance, the two groups have broadly comparable overall spreads, although the Japanese group has a somewhat larger central spread in the boxplot.
logUS <- log(US)
logJapan <- log(Japan)
par(mfrow = c(1, 2))
qqnorm(logUS, main = "U.S. Cars", xlab = "Theoretical Quantiles", ylab = "Sample Quantiles")
qqline(logUS)
qqnorm(logJapan, main = "Japanese Cars", xlab = "Theoretical Quantiles", ylab = "Sample Quantiles")
qqline(logJapan)
par(mfrow = c(1, 1))
After taking the logarithm, the U.S. observations follow the reference line more closely, so the log transformation improves the Normality of the U.S. data. The Japanese data also remain reasonably consistent with a Normal distribution.
boxplot(logUS, logJapan, names = c("U.S.", "Japan"), ylab = "log(MPG)", main = "Log-Transformed MPG of U.S. and Japanese Cars")
sd(logUS)
## [1] 0.2466874
sd(logJapan)
## [1] 0.1820182
var(logUS)
## [1] 0.06085468
var(logJapan)
## [1] 0.03313062
On the log scale, the widths of the boxes are more similar than on the original scale, so the central variability of the two groups appears more comparable. The log transformation also improves the appearance of the U.S. Normal probability plot.
Let
\[\mu_{US} = \text{population mean of log(MPG) for U.S. cars}\]
and
\[\mu_{Japan} = \text{population mean of log(MPG) for Japanese cars}.\]
The hypotheses are
\[H_0: \mu_{US} = \mu_{Japan}\]
or
\[H_a: \mu_{US} < \mu_{Japan}.\]
The significance level is
\[\alpha = 0.05.\]
mean_log_US <- mean(logUS)
mean_log_Japan <- mean(logJapan)
mean_log_US
## [1] 2.741001
mean_log_Japan
## [1] 3.270957
The sample average log(MPG) for U.S. cars is2.74 and the sample average log(MPG) for Japanese cars is 3.27.
exp(mean_log_US)
## [1] 15.5025
exp(mean_log_Japan)
## [1] 26.33654
test_result <- t.test(logUS, logJapan, alternative = "less", var.equal = TRUE, conf.level = 0.95)
test_result
##
## Two Sample t-test
##
## data: logUS and logJapan
## 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
Because the p-value is much smaller than the significance level of 0.05, we reject the null hypothesis. There is statistically significant evidence that the population mean of log(MPG) for U.S. cars is lower than the population mean of log(MPG) for Japanese cars.
In this sample, the mean log(MPG) is 15.5 for U.S. cars and 26.3 for Japanese cars. Thus, the data support the environmental group’s hypothesis that U.S. manufactured cars have lower fuel efficiency than Japanese manufactured cars.
cars <- read.csv("https://raw.githubusercontent.com/tmatis12/datafiles/main/US_Japanese_Cars.csv")
# Removing the missing values
US <- na.omit(cars$USCars)
Japan <- na.omit(cars$JapaneseCars)
# Sample sizes
length(US)
length(Japan)
# NPP
qqnorm(US, main = "NPP for U.S. Cars")
qqline(US)
qqnorm(Japan, main = "NPP for Japanese Cars")
qqline(Japan)
#Boxplot
boxplot(US, Japan, names = c("U.S.", "Japan"), ylab = "MPG", main = "MPG of U.S. and Japanese Cars")
var(US)
var(Japan)
#Log Transformation
logUS <- log(US)
logJapan <- log(Japan)
# NPP after transformation
par(mfrow = c(1, 2))
qqnorm(logUS, main = "U.S. Cars", xlab = "Theoretical Quantiles", ylab = "Sample Quantiles")
qqline(logUS)
qqnorm(logJapan, main = "Japanese Cars", xlab = "Theoretical Quantiles", ylab = "Sample Quantiles")
qqline(logJapan)
par(mfrow = c(1, 1))
# Boxplot after transformation
boxplot(logUS, logJapan, names = c("U.S.", "Japan"), ylab = "log(MPG)", main = "Log-Transformed MPG of U.S. and Japanese Cars")
sd(logUS)
sd(logJapan)
var(logUS)
var(logJapan)
# Sample Averages of log(MPG)
mean_log_US <- mean(logUS)
mean_log_Japan <- mean(logJapan)
mean_log_US
mean_log_Japan
exp(mean_log_US)
exp(mean_log_Japan)
# Two sample T-test
test_result <- t.test(logUS, logJapan, alternative = "less", var.equal = TRUE, conf.level = 0.95)
test_result