dat<-read.csv("https://raw.githubusercontent.com/tmatis12/datafiles/main/US_Japanese_Cars.csv")
str(dat)
## 'data.frame': 35 obs. of 2 variables:
## $ USCars : int 18 15 18 16 17 15 14 14 14 15 ...
## $ JapaneseCars: int 24 27 27 25 31 35 24 19 28 23 ...
USCars <- dat$USCars
JapaneseCars <- dat$JapaneseCars
qqnorm(USCars,main = "Normal Probability Plot for US Cars")
qqline(USCars)
qqnorm(JapaneseCars,main = "Normal Probability Plot for Japanese Cars")
qqline(JapaneseCars)
The mpg of US cars looks not approximately normal, and mpg of Japanese cars looks approximately normal.
boxplot(USCars,JapaneseCars, names = c("US cars", "Japanese cars"), ylab = "mpg")
The variance does not appear to be constant.
USCarslog<-log(USCars)
JapaneseCarslog<-log(JapaneseCars)
qqnorm(USCarslog,main = "Normal Probability Plot for US Cars (log)")
qqline(USCarslog)
qqnorm(JapaneseCarslog,main = "Normal Probability Plot for Japanese Cars (log)")
qqline(JapaneseCarslog)
boxplot(USCarslog,JapaneseCarslog, names = c("US cars (log)", "Japanese cars (log)"), ylab = "log(mpg)")
The NPPs after the log transformation looks similar to those from the original data. The Japanese car still looks approximately normal. The US car data still looks not approximately normal. Therefore, the log transformation does not improve the normality of the two groups. After the log transformation, the two groups have more similar variance, so the equal variance assumption is more reasonable.
\(H_0:\mu_{\log(USCars)}-\mu_{\log(JapaneseCars)}=0\) \(H_a:\mu_{\log(USCars)}-\mu_{\log(JapaneseCars)}<0\)
mean(USCarslog)
## [1] 2.741001
mean(JapaneseCarslog, na.rm = TRUE)
## [1] 3.270957
The sample average of log of the mpg for US cars is 2.741001. The sample average of log of the mpg for Japanese cars is 3.270957.
t.test(USCarslog,JapaneseCarslog, alternative= "less", var.equal = TRUE)
##
## Two Sample t-test
##
## data: USCarslog and JapaneseCarslog
## 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
Since the p-value=6.528e-14 is less than 0.05, we reject the null hypothesis. And there is sufficient evidence to conclude that the mean log(mpg) of US cars is less than the mean log(mpg) of Japanese cars.
dat<-read.csv("https://raw.githubusercontent.com/tmatis12/datafiles/main/US_Japanese_Cars.csv")
str(dat)
USCars <- dat$USCars
JapaneseCars <- dat$JapaneseCars
qqnorm(USCars,main = "Normal Probability Plot for US Cars")
qqline(USCars)
qqnorm(JapaneseCars,main = "Normal Probability Plot for Japanese Cars")
qqline(JapaneseCars)
boxplot(USCars,JapaneseCars, names = c("US cars", "Japanese cars"), ylab = "mpg")
USCarslog<-log(USCars)
JapaneseCarslog<-log(JapaneseCars)
qqnorm(USCarslog,main = "Normal Probability Plot for US Cars (log)")
qqline(USCarslog)
qqnorm(JapaneseCarslog,main = "Normal Probability Plot for Japanese Cars (log)")
qqline(JapaneseCarslog)
boxplot(USCarslog,JapaneseCarslog, names = c("US cars (log)", "Japanese cars (log)"), ylab = "log(mpg)")
mean(USCarslog)
mean(JapaneseCarslog, na.rm = TRUE)
t.test(USCarslog,JapaneseCarslog, alternative= "less", var.equal = TRUE)