1 Assignment Description

An environmental group is testing the fuel efficiency of vehicles manufactured in Japan against vehciles manufactured in the United States. They sampled 35 US vehiciles (n1) and 28 Japanese vehicles (n2).

2 Data Collection

url<-"https://raw.githubusercontent.com/tmatis12/datafiles/main/US_Japanese_Cars.csv"
csvdata<-read.csv(url)
csvdata
##    USCars JapaneseCars
## 1      18           24
## 2      15           27
## 3      18           27
## 4      16           25
## 5      17           31
## 6      15           35
## 7      14           24
## 8      14           19
## 9      14           28
## 10     15           23
## 11     15           27
## 12     14           20
## 13     15           22
## 14     14           18
## 15     22           20
## 16     18           31
## 17     21           32
## 18     21           31
## 19     10           32
## 20     10           24
## 21     11           26
## 22      9           29
## 23     28           24
## 24     25           24
## 25     19           33
## 26     16           33
## 27     17           32
## 28     19           28
## 29     18           NA
## 30     14           NA
## 31     14           NA
## 32     14           NA
## 33     14           NA
## 34     12           NA
## 35     13           NA

3 Question #1

Does the mpg of both US cars and Japanese cars appear to be Normally distributed (use NPPs)?

qqnorm(csvdata$USCars,
       main = "Normal Q-Q Plot, US Cars",
       ylab="Sample Quantiles (mpg)")
qqline(csvdata$USCars)

qqnorm(csvdata$JapaneseCars,
       main="Normal Q-Q Plot, Japanese Cars",
       ylab="Sample Quantiles (mpg)")
qqline(csvdata$JapaneseCars)

Based on the normal probability plots (NPP) the data from both the Japanese and US cars does not appear to be normally distributed.

  • The US data curves above the line significantly for quantiles > 1 and for quantiles < -1 the data slightly dips below the line. This data exhibits a right-skew.

  • The Japanese data deviates below the line in the upper right portion of the NPP. Also from -1 to 1 the data falls below the line in multiple locations. This data exhibits a left-skew.

4 Question #2

Does the variance appear to be constant (use side-by-side box plots)?

boxplot(csvdata$USCars,csvdata$JapaneseCars,
        names=c("US Vehicles","Japanese Vehicles"),
        ylab="Fuel Efficiency (mpg)",
        main="US vs. Japanese Vehicle Fuel Efficiency")

The variance does not appear to be constant. The height of the Japanese box plot is nearly double that of the US box plot; therefore, insinuating that the variance is not constant across the two data sets.

5 Question #3

Transform the data using a log transform and repeat questions 1 and 2. Comment on the differences between the plots. Use the transformed data for the remaining questions

USlog<-log(csvdata$USCars)
Japanlog<-log(csvdata$JapaneseCars)

5.1 NPP

qqnorm(USlog,
       main="Normal Q-Q Plot, US Cars",
       ylab="Sample Quantiles (mpg)")
qqline(USlog)

qqnorm(Japanlog,
       main="Normal Q-Q Plot, Japanese Cars",
       ylab="Sample Quantiles (mpg)")
qqline(Japanlog)

After performing a log transformation on the data both the Japanese and US vehicle data appears to be normally distributed. There are data points that deviate from the line in both NPPs; however, the magnitude of these deviations is small.

5.2 Box Plots

boxplot(USlog,Japanlog,
        names=c("US Vehicles","Japanese Vehicles"),
        ylab="Fuel Efficiency (mpg)",
        main="US vs. Japanese Vehicle Fuel Efficiency")

The variance between the two data sets appears to be constant after performing the log transformation. The height of the two box plots is roughly the same size. The range of the distributions is slightly different but not large enough to be concerning.

6 Question #4

State the null and alternative hypothesis and test using a 0.05 level of significance.

Null Hypothesis \[H_{0}: \mu _{1}= \mu _{2} \] Alternative Hypothesis \[ H_{a}: \mu _{1}< \mu _{2} \]

Where:

\[\mu_{1} = Sample\,Mean\,of\,US\,Cars \]

\[\mu_{2} = Sample\,Mean\,of\,Japanese\,Cars \]

t.test(USlog,Japanlog,var.equal=TRUE)
## 
##  Two Sample t-test
## 
## data:  USlog and Japanlog
## t = -9.4828, df = 61, p-value = 1.306e-13
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -0.6417062 -0.4182053
## sample estimates:
## mean of x mean of y 
##  2.741001  3.270957

6.1 Question #4a

What are the sample averages for the log of the mpg of US and Japanese cars?

meanuslog<-round(mean(USlog),3)
meanuslog<-as.character(meanuslog)
cat(meanuslog,"mpg")
US log Sample Average =  2.741 mpg
Japanlog<-na.omit(Japanlog)
meanjapanlog<-round(mean(Japanlog),3)
meanjapanlog<-as.character(meanjapanlog)
cat(meanjapanlog,"mpg")
Japanese log Sample Average =  3.271 mpg

6.2 Question #4b

State your conclusions

Based on the results from the two sample T test, US vehicles that were sampled have a fuel efficiency that is less than the sampled Japanese vehicles. The P value for this test (1.306 X 10^-13) is extremely less than the 0.05 level of significance; therefore, I am able to reject the null hypothesis that the sample means are equal to each other. After comparing the log means of both sample pools it is clear that the average fuel efficiency of the Japanese vehicles sampled is higher than the US vehicles that were sampled.

7 Complete R Code

It is a good idea to include this at the end of every RMarkdown document

# Data Collection
url<-"https://raw.githubusercontent.com/tmatis12/datafiles/main/US_Japanese_Cars.csv"
csvdata<-read.csv(url)
csvdata

# Question #1
qqnorm(csvdata$USCars,
       main = "Normal Q-Q Plot, US Cars",
       ylab="Sample Quantiles (mpg)")
qqline(csvdata$USCars)
qqnorm(csvdata$JapaneseCars,
       main="Normal Q-Q Plot, Japanese Cars",
       ylab="Sample Quantiles (mpg)")
qqline(csvdata$JapaneseCars)

# Question #2
boxplot(csvdata$USCars,csvdata$JapaneseCars,
        names=c("US Vehicles","Japanese Vehicles"),
        ylab="Fuel Efficiency (mpg)",
        main="US vs. Japanese Vehicle Fuel Efficiency")

# Question #3
USlog<-log(csvdata$USCars)
Japanlog<-log(csvdata$JapaneseCars)

qqnorm(USlog,
       main="Normal Q-Q Plot, US Cars",
       ylab="Sample Quantiles (mpg)")
qqline(USlog)
qqnorm(Japanlog,
       main="Normal Q-Q Plot, Japanese Cars",
       ylab="Sample Quantiles (mpg)")
qqline(Japanlog)

boxplot(USlog,Japanlog,
        names=c("US Vehicles","Japanese Vehicles"),
        ylab="Fuel Efficiency (mpg)",
        main="US vs. Japanese Vehicle Fuel Efficiency")

# Question #4
t.test(USlog,Japanlog,var.equal=TRUE)

meanuslog<-round(mean(USlog),3)
meanuslog<-as.character(meanuslog)
cat(meanuslog,"mpg")

Japanlog<-na.omit(Japanlog)
meanjapanlog<-round(mean(Japanlog),3)
meanjapanlog<-as.character(meanjapanlog)
cat(meanjapanlog,"mpg")