file_path <- "/Users/kehindeoladele/Downloads/US_Japanese_Cars.csv"
DF <- read.csv(file_path, fileEncoding = "UTF-8-BOM")
US <- na.omit(DF$USCars)
Japan <- na.omit(DF$JapaneseCars)
length(US)
## [1] 35
length(Japan)
## [1] 28
summary(US)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 9.00 14.00 15.00 15.97 18.00 28.00
summary(Japan)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 18.00 24.00 27.00 26.75 31.00 35.00
The samples contain 35 U.S. cars and 28 Japanese cars.
par(mfrow = c(1, 2))
qqnorm(US, main = "NPP: U.S. Cars", col = "steelblue", pch = 19)
qqline(US, col = "red", lwd = 2)
qqnorm(Japan, main = "NPP: Japanese Cars", col = "hotpink", pch = 19)
qqline(Japan, col = "red", lwd = 2)
par(mfrow = c(1, 1))
The U.S. data depart from the line in the upper tail, indicating right skewness. The Japanese observations are closer to a straight line and appear approximately Normal.
boxplot(
US, Japan,
names = c("U.S.", "Japan"),
main = "MPG by Country",
ylab = "MPG",
col = c("steelblue", "hotpink")
)
IQR(US)
## [1] 4
IQR(Japan)
## [1] 7
The IQR for U.S. cars is noticeably larger than the IQR for Japanese cars, suggesting the equal-variance assumption is questionable on the original scale.
logUS <- log(US)
logJapan <- log(Japan)
par(mfrow = c(1, 2))
qqnorm(logUS, main = "NPP: U.S. Log(MPG)", col = "steelblue", pch = 19)
qqline(logUS, col = "red", lwd = 2)
qqnorm(logJapan, main = "NPP: Japan Log(MPG)", col = "hotpink", pch = 19)
qqline(logJapan, col = "red", lwd = 2)
par(mfrow = c(1, 1))
The log transformation pulls both sets of points closer to the reference line. The U.S. points now track the line much better in the upper tail, and the Japanese points remain approximately Normal.
boxplot(
logUS, logJapan,
names = c("U.S.", "Japan"),
main = "Log(MPG) by Country",
ylab = "Log(MPG)",
col = c("steelblue", "hotpink")
)
IQR(logUS)
## [1] 0.2513144
IQR(logJapan)
## [1] 0.2559334
mean_logUS <- mean(logUS)
mean_logJapan <- mean(logJapan)
mean_logUS
## [1] 2.741001
mean_logJapan
## [1] 3.270957
test_result <- t.test(
logUS,
logJapan,
alternative = "less",
var.equal = TRUE
)
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 less than 0.05, I reject Ho. There is sufficient evidence that the population mean log(MPG) of U.S. cars is lower than that of Japanese cars.