url <- "https://raw.githubusercontent.com/tmatis12/datafiles/main/US_Japanese_Cars.csv"
cars_data<-read.csv(url, header=TRUE)
us_mpg<-na.omit(cars_data$USCars)
jp_mpg<-na.omit(cars_data$JapaneseCars)
length(us_mpg)
## [1] 35
length(jp_mpg)
## [1] 28
Testing the hypothesis that the mean mpg (miles per gallon) of cars manufactured in the United States is less than that of those manufactured in Japan for an environmental group, this report analyses the file US_Japanese_Cars.csv regarding the data of mpg fuel efficiency. The sample were n1=35 US cars and n2=28 Japanese cars. We assume that this is a random sample from a large population of United States and Japan.
The following information shows NPPs and box plot of the original data:
par(mfrow=c(1, 2))
qqnorm(us_mpg, main = "NPP - US Cars")
qqline(us_mpg, col="red")
qqnorm(jp_mpg, main="NPP - Japanese Cars")
qqline(jp_mpg, col="red")
par(mfrow = c(1, 1))
boxplot(us_mpg, jp_mpg,
names = c("US Cars", "Japanese Cars"),
col = c("lightblue", "lightgreen"),
main = "Original MPG Comparison",
ylab = "MPG")
The Normal Probability plots (NPPs) of both samples show that the central part of the plots follows the red line, which indicates a normal distribution. However, in both graphs, the extremes appears a little distance from the reference line, demonstrating that the distribution is not perfect and the data needs treatment.
Regarding the side-by-side boxplot, the Japanese cars present higher values of mpg in comparison with US cars. The median of Japanese cars is approximately 27 mpg while for US car the median is only 15 mpg.
Additionally, the box for Japanese Cars is taller, which demonstrates greater variability. Specifically, the interquartile range for Japanese cars spans from 24 to 31 mpg, whereas the range for US cars is narrower, spanning from 14 to 18 mpg.
Furthermore, the maximum value of US cars is close to the minimum of Japanese cars. However, the US cars data indicates two outliers.
The following information shows NPP data and a box plot with a log transformation.
us_log<-log(us_mpg)
jp_log<-log(jp_mpg)
par(mfrow = c(1, 2))
qqnorm(us_log, main = "NPP - US Cars (Log)")
qqline(us_log, col = "red")
qqnorm(jp_log, main = "NPP - Japanese Cars (Log)")
qqline(jp_log, col = "red")
par(mfrow = c(1, 1))
boxplot(us_log, jp_log,
names = c("US Cars (Log)", "Japanese Cars (Log)"),
col = c("lightblue", "lightgreen"),
main = "Log-Transformed MPG Comparison",
ylab = "Log(MPG)")
The NPPs with log transformation change the interval of samples from 10 and 35 to 2.2 and 3.5, which indicates the adjustment in the scale. However, the distribution plots remains similar even with the application of the log transformation.
The side-by-side box plot with the log transformation helped to stabilize the variability between the two groups.The outlier points, that appeared together in the US sample, now reflect the adjusted scale.
The following information shows the null and alternative hypothesis test using a 0.05 level of significance.
mean_us_log<-mean(us_log)
mean_jp_log<-mean(jp_log)
print(paste("Mean US Log MPG:", round(mean_us_log, 4)))
## [1] "Mean US Log MPG: 2.741"
print(paste("Mean Japanese Log MPG:", round(mean_jp_log, 4)))
## [1] "Mean Japanese Log MPG: 3.271"
t_test_result<-t.test(us_log, jp_log, var.equal=TRUE, alternative="less")
t_test_result
##
## Two Sample t-test
##
## data: us_log and jp_log
## 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
With the mean in Log Scale we can see the greater difference between the mpg of the US and the Japanese cars. The mean of Japanese car is 3.271 mpg, as the Japanese cars are more efficient than US cars (2.74 mpg).
The statistic of t-test is negative, t=-9.4828, because the mean of the US is less than Japanese.
Additionally, the p-value is 6.528e-14 well below than the level of significance of 0.05, therefore, the null hypotheses could be rejected.
Furthermore, with 95% of confidence, the maximum limit of the difference between the mean is negative, -0.4366143.
In summary, the analysis of the file data indicates that Japanese cars are more efficient in fuel consumption (mpg) than the United States cars.
The means are visibly distant without the Log transformation. After the application of Log transformation, the scale adjustment confirms that Japanese cars present higher mpg values in comparison with US cars, consolidated by the negative t-test and an extremely low p-value.
knitr::opts_chunk$set(echo=TRUE, warning=FALSE, message=FALSE)
url <- "https://raw.githubusercontent.com/tmatis12/datafiles/main/US_Japanese_Cars.csv"
cars_data<-read.csv(url, header=TRUE)
us_mpg<-na.omit(cars_data$USCars)
jp_mpg<-na.omit(cars_data$JapaneseCars)
length(us_mpg)
length(jp_mpg)
par(mfrow=c(1, 2))
qqnorm(us_mpg, main = "NPP - US Cars")
qqline(us_mpg, col="red")
qqnorm(jp_mpg, main="NPP - Japanese Cars")
qqline(jp_mpg, col="red")
par(mfrow = c(1, 1))
boxplot(us_mpg, jp_mpg,
names = c("US Cars", "Japanese Cars"),
col = c("lightblue", "lightgreen"),
main = "Original MPG Comparison",
ylab = "MPG")
us_log<-log(us_mpg)
jp_log<-log(jp_mpg)
par(mfrow = c(1, 2))
qqnorm(us_log, main = "NPP - US Cars (Log)")
qqline(us_log, col = "red")
qqnorm(jp_log, main = "NPP - Japanese Cars (Log)")
qqline(jp_log, col = "red")
par(mfrow = c(1, 1))
boxplot(us_log, jp_log,
names = c("US Cars (Log)", "Japanese Cars (Log)"),
col = c("lightblue", "lightgreen"),
main = "Log-Transformed MPG Comparison",
ylab = "Log(MPG)")
mean_us_log<-mean(us_log)
mean_jp_log<-mean(jp_log)
print(paste("Mean US Log MPG:", round(mean_us_log, 4)))
print(paste("Mean Japanese Log MPG:", round(mean_jp_log, 4)))
t_test_result<-t.test(us_log, jp_log, var.equal=TRUE, alternative="less")
t_test_result