This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.
When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
as of August 28, 2014, superceding the version of August 24. Always use the most recent version.
This analysis uses fuel economy data to test the effect of 3 factors, with 2 blocking factors, on the response variable of highway fuel economy.
Below is the installation and initial examination of the dataset:
#Installing data package
install.packages("fueleconomy", repos='http://cran.us.r-project.org')
## Installing package into 'C:/Users/tothk2/Documents/R/win-library/3.1'
## (as 'lib' is unspecified)
## package 'fueleconomy' successfully unpacked and MD5 sums checked
##
## The downloaded binary packages are in
## C:\Users\tothk2\AppData\Local\Temp\RtmpqCh5F6\downloaded_packages
library("fueleconomy", lib.loc="~/R/win-library/3.1")
data<-vehicles
attach(data)
For this multi-factor analysis we will be examining the effect of the factors of fuel type (fuel), drive type (drive) and year of car (year) on the response variable highway fuel economy.
Fuel type has 13 levels, drive type has 7 levels, and year has 16 levels all of which are shown below along with summary statistics and an overview of the data.
Note that only cars made after the year 2000 are examined.
#Subsetting data
datasub <- subset(data, year >= 2000)
#Levels of Year
unique(datasub$year)
## [1] 2001 2002 2003 2000 2004 2013 2014 2005 2006 2007 2008 2009 2010 2011
## [15] 2012 2015
#Levels of each Fuel Type
unique(datasub$fuel)
## [1] "Premium" "Regular"
## [3] "Diesel" "Premium or E85"
## [5] "Electricity" "Gasoline or E85"
## [7] "Premium Gas or Electricity" "Gasoline or natural gas"
## [9] "CNG" "Midgrade"
## [11] "Regular Gas and Electricity" "Gasoline or propane"
## [13] "Premium and Electricity"
# Levels of Drive Type
unique(datasub$drive)
## [1] "Front-Wheel Drive" "4-Wheel or All-Wheel Drive"
## [3] "All-Wheel Drive" "Rear-Wheel Drive"
## [5] "4-Wheel Drive" "2-Wheel Drive"
## [7] "Part-time 4-Wheel Drive"
head(datasub)
## id make model year class trans drive
## 24 16573 Acura 3.2CL 2001 Compact Cars Automatic (S5) Front-Wheel Drive
## 25 17489 Acura 3.2CL 2002 Compact Cars Automatic (S5) Front-Wheel Drive
## 26 18458 Acura 3.2CL 2003 Compact Cars Manual 6-spd Front-Wheel Drive
## 27 18459 Acura 3.2CL 2003 Compact Cars Automatic (S5) Front-Wheel Drive
## 29 15871 Acura 3.2TL 2000 Midsize Cars Automatic 5-spd Front-Wheel Drive
## 30 16734 Acura 3.2TL 2001 Midsize Cars Automatic (S5) Front-Wheel Drive
## cyl displ fuel hwy cty
## 24 6 3.2 Premium 27 17
## 25 6 3.2 Premium 27 17
## 26 6 3.2 Premium 26 17
## 27 6 3.2 Premium 27 17
## 29 6 3.2 Premium 27 17
## 30 6 3.2 Premium 27 17
tail(datasub)
## id make model year class
## 33437 31064 smart fortwo electric drive cabriolet 2011 Two Seaters
## 33438 33305 smart fortwo electric drive convertible 2013 Two Seaters
## 33439 34393 smart fortwo electric drive convertible 2014 Two Seaters
## 33440 31065 smart fortwo electric drive coupe 2011 Two Seaters
## 33441 33306 smart fortwo electric drive coupe 2013 Two Seaters
## 33442 34394 smart fortwo electric drive coupe 2014 Two Seaters
## trans drive cyl displ fuel hwy cty
## 33437 Automatic (A1) Rear-Wheel Drive NA NA Electricity 79 94
## 33438 Automatic (A1) Rear-Wheel Drive NA NA Electricity 93 122
## 33439 Automatic (A1) Rear-Wheel Drive NA NA Electricity 93 122
## 33440 Automatic (A1) Rear-Wheel Drive NA NA Electricity 79 94
## 33441 Automatic (A1) Rear-Wheel Drive NA NA Electricity 93 122
## 33442 Automatic (A1) Rear-Wheel Drive NA NA Electricity 93 122
summary(datasub)
## id make model year
## Min. :15589 Length:16649 Length:16649 Min. :2000
## 1st Qu.:19754 Class :character Class :character 1st Qu.:2004
## Median :24086 Mode :character Mode :character Median :2008
## Mean :24881 Mean :2007
## 3rd Qu.:30728 3rd Qu.:2011
## Max. :34932 Max. :2015
##
## class trans drive cyl
## Length:16649 Length:16649 Length:16649 Min. : 2.00
## Class :character Class :character Class :character 1st Qu.: 4.00
## Mode :character Mode :character Mode :character Median : 6.00
## Mean : 5.96
## 3rd Qu.: 8.00
## Max. :16.00
## NA's :49
## displ fuel hwy cty
## Min. :1.00 Length:16649 Min. : 11.0 Min. : 7.0
## 1st Qu.:2.40 Class :character 1st Qu.: 20.0 1st Qu.: 15.0
## Median :3.30 Mode :character Median : 24.0 Median : 17.0
## Mean :3.44 Mean : 24.5 Mean : 17.9
## 3rd Qu.:4.30 3rd Qu.: 28.0 3rd Qu.: 20.0
## Max. :8.40 Max. :109.0 Max. :138.0
## NA's :49
The continuous variables in this data are the city (“cty”) and highway (“hwy”) gas mileage of each vehicle. Highway mileage ranges from 9 to 109 and City mileage ranges from 6 to 138.
For this experiment we will be focusing on the highway gas mileage for the response variable being effected by the chosen factors.
The data set is organized by the following variables: id, make, model, year, class, trans, drive, cyl, displ, fuel, hwy, cty
Make, model and class are indications of the manufacturer and type of the vehicle such as Audi and Ford and the model of the vehicle is model from that manufacturere such as Passat or Gran Prix. Class indicates vehicle type such as compact car or van.
Year is simply the year that vehicle was manufactured.
trans, drive, cyl, and displ all describe the type of set up the car has, mostly relating to the engine. The trans is the transmission which is thinks like Automatic 9-spd or Manual 5-spd. The drive describes the type of wheel drive like All-wheel or front-wheel. Cyl is the number of cylinders the engine has and displ shows the displacement in liters of the engine.
Fuel is the type of fuel the engine uses such as Regular or Premium.
Cty and hwy are the gas mileage for city driving and gas mileage for highway driving.
It is unknown whether or not the data collected for this study was collected by a randomly designed experiment.
To perform the experiment the data will first be altered so that our blocking factors have two levels. Then an analysisof variance will be performed on each factor individually while blocking on the two blocking factors. From these analysis we will be able to test the null hypothesis, that highway gas mileage is independant of drive type, year and fuel type while blocking for cylinders and engine displacement.
The rationale for using an analysis of variance test is used when multiple factors are considered. It checks whether the means of several groups are equal. The alternative would be to use multiple two-sample t-tests however there is more likely chance of the test resulting in a false hypothesis. We use blocking factors to eliminate what could be nuisance variables we cannot control.
The data was collected in an unknown way so we do not know if there was any randomization to it.
There are no replicated or repeated measures in the data. Each unique vehicle had it’s fuel economy statistics measured once.
There was blocking performed on the data using the factors number of cylinders (cyl) and engine displacement (displ). Both factors were split into two levels. Cylinder was split into less than 6 and greater than 6 cylinders. Engine displacement was split into less than or greater than 4 litres.
To start our statistical analysis we will make our variables factors for the analysis of variance and look at some boxplots of those factors. We will also alter our data entries for our blocking factors and check that our between group variance is greater than our within group variance by comparing interquartile ranges and means. If our between group variance is greater than our within group variance we know we have good blocking factors.
#Creating 2 levels for Cylinder
datasub$cyl[datasub$cyl>0 & datasub$cyl <= 6 ] ="<= 6 cyl"
datasub$cyl[as.numeric(datasub$cyl)>6] = "> 6 cyl"
## Warning: NAs introduced by coercion
#Subsetting data for withing and between group variance analysis
xsmall <- subset(datasub, cyl == "<= 6 cyl")
xbig <- subset(datasub, cyl == "> 6 cyl")
#Examining withing group variation and the difference in between group variation
IQR(xsmall$hwy)
## [1] 6
IQR(xbig$hwy)
## [1] 4
mean(xsmall$hwy)-mean(xbig$hwy)
## [1] 7.119
#Creating 2 levels for Displacement
datasub$displ[datasub$displ>=0 & datasub$displ <= 4 ] ="<= 4 litres"
datasub$displ[datasub$displ>4] = "> 4 litres"
#Subsetting data for withing and between group variance analysis
ysmall <- subset(datasub, displ == "<= 4 litres")
ybig <- subset(datasub, displ == "> 4 litres")
#Examining withing group variation and the difference in between group variation
IQR(ysmall$hwy)
## [1] 6
IQR(ybig$hwy)
## [1] 4
mean(ysmall$hwy)-mean(ybig$hwy)
## [1] 7.442
As we can see our inter-quartile ranges are both lower than the difference in means between groups leading us to conclude that our blocking factors are good.
Next we will define our variables as factors and examine boxplots
#Defining Fuel Type as a factor
datasub$fuel = as.factor(datasub$fuel)
#Defining Year as a factor
datasub$year = as.factor(datasub$year)
#Defining Drive Type as a factor
datasub$drive = as.factor(datasub$drive)
#Defining Block Cylinders as a factor
datasub$cyl = as.factor(datasub$cyl)
#Defining block Displacement as a factor
datasub$displ = as.factor(datasub$displ)
#Boxplots of the means of each factor against response variable
boxplot(hwy~fuel, data=datasub, xlab="Fuel Type", ylab="Highway Fuel Economy")
boxplot(hwy~year, data=datasub, xlab="Year", ylab="Highway Fuel Economy")
boxplot(hwy~drive, data=datasub, xlab="Drive Type", ylab="Highway Fuel Economy")
#Boxplots of blocking factors
boxplot(hwy~cyl, data=datasub, xlab="Number of Cylinders", ylab="Highway Fuel Economy")
boxplot(hwy~displ, data=datasub, xlab="Enginge Displacement", ylab="Highway Fuel Economy")
We can’t discern any noticeable effects of the factors from the boxplots but we can appear to see inverse relationships between our blocking factors and response variable. As our block factor increases the response variable decreases.
To test the hypotheses we perform an ANOVA test on the factors including each blocking factor with an “or” operator (using + instead of * in the analysis of variance)
The null hypothesis of the tests is that the single factor does not have an effect on the response variable of highway gas mileage.
#Model Key:
#Factors
# 1 = Fuel Type
# 2 = Drive Type
# 3 = Year
#Blocking
# A = Number of Cylinders
# B = Engine Displacement
#Analysis of Variance for Fuel Type
model1A=aov(hwy~fuel+cyl, data=datasub)
model1B=aov(hwy~fuel+displ, data=datasub)
anova(model1A)
## Analysis of Variance Table
##
## Response: hwy
## Df Sum Sq Mean Sq F value Pr(>F)
## fuel 11 42353 3850 191 <2e-16 ***
## cyl 1 144161 144161 7169 <2e-16 ***
## Residuals 16587 333546 20
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
anova(model1B)
## Analysis of Variance Table
##
## Response: hwy
## Df Sum Sq Mean Sq F value Pr(>F)
## fuel 11 42353 3850 204 <2e-16 ***
## displ 1 164656 164656 8724 <2e-16 ***
## Residuals 16587 313051 19
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#Analysis of Variance for Drive Type
model2A=aov(hwy~drive+cyl, data=datasub)
model2B=aov(hwy~drive+displ, data=datasub)
anova(model2A)
## Analysis of Variance Table
##
## Response: hwy
## Df Sum Sq Mean Sq F value Pr(>F)
## drive 6 218680 36447 2480 <2e-16 ***
## cyl 1 57494 57494 3911 <2e-16 ***
## Residuals 16592 243886 15
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
anova(model2B)
## Analysis of Variance Table
##
## Response: hwy
## Df Sum Sq Mean Sq F value Pr(>F)
## drive 6 218680 36447 2578 <2e-16 ***
## displ 1 66784 66784 4723 <2e-16 ***
## Residuals 16592 234596 14
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#Analysis of Variance for Year
model3A=aov(hwy~year+cyl, data=datasub)
model3B=aov(hwy~year+displ, data=datasub)
anova(model3A)
## Analysis of Variance Table
##
## Response: hwy
## Df Sum Sq Mean Sq F value Pr(>F)
## year 15 44146 2943 158 <2e-16 ***
## cyl 1 166238 166238 8902 <2e-16 ***
## Residuals 16583 309676 19
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
anova(model3B)
## Analysis of Variance Table
##
## Response: hwy
## Df Sum Sq Mean Sq F value Pr(>F)
## year 15 44146 2943 166 <2e-16 ***
## displ 1 182289 182289 10295 <2e-16 ***
## Residuals 16583 293624 18
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
For each of our individual tests we found resulting p-values of 2.2e-16. We also found near zero p-values for our interaction model. The p-value represents the probability that we can get the F value using the null hypothesis. Since our probability is extremely close to 0 we can assume that each factor demonstrates an effect on the response variable. We are lead to reject the null hypothesis.
Next we graph Q-Q plots to check our data in our model for normality. If the data is not normal the results of the analysis may not be valid.
#QQ plots for residuals of Fuel Type models
qqnorm(residuals(model1A))
qqline(residuals(model1A))
qqnorm(residuals(model1B))
qqline(residuals(model1B))
#QQ plots for residuals of Drive Type models
qqnorm(residuals(model2A))
qqline(residuals(model2A))
qqnorm(residuals(model2B))
qqline(residuals(model2B))
#QQ plots for residuals of Year models
qqnorm(residuals(model3A))
qqline(residuals(model3A))
qqnorm(residuals(model3B))
qqline(residuals(model3B))
We also perform the Tukey test which is used to determine which groups in the sample differ as opposed to the anova which tells whether or not there are differences in groups.
#Tukey HSD test for Fuel models
TukeyHSD(model1A, ordered=FALSE, conf.level = .95)
## Tukey multiple comparisons of means
## 95% family-wise confidence level
##
## Fit: aov(formula = hwy ~ fuel + cyl, data = datasub)
##
## $fuel
## diff lwr
## Diesel-CNG 13.27007 10.84729
## Gasoline or E85-CNG -0.94490 -3.17644
## Gasoline or natural gas-CNG -4.06667 -8.15425
## Gasoline or propane-CNG -5.56667 -11.19041
## Midgrade-CNG 0.11938 -3.00627
## Premium-CNG 1.89746 -0.29524
## Premium and Electricity-CNG 6.93333 -7.88542
## Premium Gas or Electricity-CNG 12.21905 6.26400
## Premium or E85-CNG 1.99015 -0.69592
## Regular-CNG 2.65741 0.46695
## Regular Gas and Electricity-CNG 22.55833 16.93459
## Gasoline or E85-Diesel -14.21497 -15.35602
## Gasoline or natural gas-Diesel -17.33673 -20.94652
## Gasoline or propane-Diesel -18.83673 -24.12339
## Midgrade-Diesel -13.15069 -15.61886
## Premium-Diesel -11.37261 -12.43568
## Premium and Electricity-Diesel -6.33673 -21.03087
## Premium Gas or Electricity-Diesel -1.05102 -6.68882
## Premium or E85-Diesel -11.27992 -13.16066
## Regular-Diesel -10.61266 -11.67111
## Regular Gas and Electricity-Diesel 9.28827 4.00161
## Gasoline or natural gas-Gasoline or E85 -3.12176 -6.60609
## Gasoline or propane-Gasoline or E85 -4.62176 -9.82356
## Midgrade-Gasoline or E85 1.06428 -1.21647
## Premium-Gasoline or E85 2.84236 2.35240
## Premium and Electricity-Gasoline or E85 7.87824 -6.78558
## Premium Gas or Electricity-Gasoline or E85 13.16395 7.60564
## Premium or E85-Gasoline or E85 2.93505 1.30806
## Regular-Gasoline or E85 3.60231 3.12246
## Regular Gas and Electricity-Gasoline or E85 23.50324 18.30144
## Gasoline or propane-Gasoline or natural gas -1.50000 -7.72794
## Midgrade-Gasoline or natural gas 4.18605 0.07139
## Premium-Gasoline or natural gas 5.96413 2.50456
## Premium and Electricity-Gasoline or natural gas 11.00000 -4.05843
## Premium Gas or Electricity-Gasoline or natural gas 16.28571 9.75706
## Premium or E85-Gasoline or natural gas 6.05682 2.26529
## Regular-Gasoline or natural gas 6.72408 3.26592
## Regular Gas and Electricity-Gasoline or natural gas 26.62500 20.39706
## Midgrade-Gasoline or propane 5.68605 0.04259
## Premium-Gasoline or propane 7.46413 2.27888
## Premium and Electricity-Gasoline or propane 12.50000 -3.04588
## Premium Gas or Electricity-Gasoline or propane 17.78571 10.20010
## Premium or E85-Gasoline or propane 7.55682 2.14444
## Regular-Gasoline or propane 8.22408 3.03977
## Regular Gas and Electricity-Gasoline or propane 28.12500 20.79660
## Premium-Midgrade 1.77808 -0.46467
## Premium and Electricity-Midgrade 6.81395 -8.01229
## Premium Gas or Electricity-Midgrade 12.09967 6.12600
## Premium or E85-Midgrade 1.87077 -0.85632
## Regular-Midgrade 2.53803 0.29746
## Regular Gas and Electricity-Midgrade 22.43895 16.79550
## Premium and Electricity-Premium 5.03587 -9.62209
## Premium Gas or Electricity-Premium 10.32159 4.77876
## Premium or E85-Premium 0.09269 -1.48060
## Regular-Premium 0.75995 0.51831
## Regular Gas and Electricity-Premium 20.66087 15.47562
## Premium Gas or Electricity-Premium and Electricity 5.28571 -10.38306
## Premium or E85-Premium and Electricity -4.94318 -19.68302
## Regular-Premium and Electricity -4.27592 -18.93355
## Regular Gas and Electricity-Premium and Electricity 15.62500 0.07912
## Premium or E85-Premium Gas or Electricity -10.22890 -15.98476
## Regular-Premium Gas or Electricity -9.56164 -15.10358
## Regular Gas and Electricity-Premium Gas or Electricity 10.33929 2.75367
## Regular-Premium or E85 0.66726 -0.90292
## Regular Gas and Electricity-Premium or E85 20.56818 15.15580
## Regular Gas and Electricity-Regular 19.90092 14.71662
## upr p adj
## Diesel-CNG 15.69284 0.0000
## Gasoline or E85-CNG 1.28664 0.9668
## Gasoline or natural gas-CNG 0.02092 0.0526
## Gasoline or propane-CNG 0.05708 0.0553
## Midgrade-CNG 3.24503 1.0000
## Premium-CNG 4.09016 0.1680
## Premium and Electricity-CNG 21.75209 0.9327
## Premium Gas or Electricity-CNG 18.17410 0.0000
## Premium or E85-CNG 4.67622 0.3911
## Regular-CNG 4.84787 0.0042
## Regular Gas and Electricity-CNG 28.18208 0.0000
## Gasoline or E85-Diesel -13.07392 0.0000
## Gasoline or natural gas-Diesel -13.72695 0.0000
## Gasoline or propane-Diesel -13.55008 0.0000
## Midgrade-Diesel -10.68251 0.0000
## Premium-Diesel -10.30953 0.0000
## Premium and Electricity-Diesel 8.35740 0.9620
## Premium Gas or Electricity-Diesel 4.58678 1.0000
## Premium or E85-Diesel -9.39918 0.0000
## Regular-Diesel -9.55421 0.0000
## Regular Gas and Electricity-Diesel 14.57492 0.0000
## Gasoline or natural gas-Gasoline or E85 0.36256 0.1309
## Gasoline or propane-Gasoline or E85 0.58003 0.1394
## Midgrade-Gasoline or E85 3.34503 0.9339
## Premium-Gasoline or E85 3.33233 0.0000
## Premium and Electricity-Gasoline or E85 22.54206 0.8417
## Premium Gas or Electricity-Gasoline or E85 18.72226 0.0000
## Premium or E85-Gasoline or E85 4.56205 0.0000
## Regular-Gasoline or E85 4.08216 0.0000
## Regular Gas and Electricity-Gasoline or E85 28.70503 0.0000
## Gasoline or propane-Gasoline or natural gas 4.72794 0.9998
## Midgrade-Gasoline or natural gas 8.30070 0.0419
## Premium-Gasoline or natural gas 9.42370 0.0000
## Premium and Electricity-Gasoline or natural gas 26.05843 0.4145
## Premium Gas or Electricity-Gasoline or natural gas 22.81437 0.0000
## Premium or E85-Gasoline or natural gas 9.84835 0.0000
## Regular-Gasoline or natural gas 10.18223 0.0000
## Regular Gas and Electricity-Gasoline or natural gas 32.85294 0.0000
## Midgrade-Gasoline or propane 11.32950 0.0463
## Premium-Gasoline or propane 12.64938 0.0002
## Premium and Electricity-Gasoline or propane 28.04588 0.2638
## Premium Gas or Electricity-Gasoline or propane 25.37133 0.0000
## Premium or E85-Gasoline or propane 12.96920 0.0003
## Regular-Gasoline or propane 13.40838 0.0000
## Regular Gas and Electricity-Gasoline or propane 35.45340 0.0000
## Premium-Midgrade 4.02084 0.2845
## Premium and Electricity-Midgrade 21.64020 0.9404
## Premium Gas or Electricity-Midgrade 18.07333 0.0000
## Premium or E85-Midgrade 4.59786 0.5186
## Regular-Midgrade 4.77860 0.0116
## Regular Gas and Electricity-Midgrade 28.08241 0.0000
## Premium and Electricity-Premium 19.69383 0.9937
## Premium Gas or Electricity-Premium 15.86441 0.0000
## Premium or E85-Premium 1.66599 1.0000
## Regular-Premium 1.00159 0.0000
## Regular Gas and Electricity-Premium 25.84612 0.0000
## Premium Gas or Electricity-Premium and Electricity 20.95449 0.9946
## Premium or E85-Premium and Electricity 9.79666 0.9949
## Regular-Premium and Electricity 10.38170 0.9985
## Regular Gas and Electricity-Premium and Electricity 31.17088 0.0475
## Premium or E85-Premium Gas or Electricity -4.47303 0.0000
## Regular-Premium Gas or Electricity -4.01970 0.0000
## Regular Gas and Electricity-Premium Gas or Electricity 17.92490 0.0005
## Regular-Premium or E85 2.23743 0.9659
## Regular Gas and Electricity-Premium or E85 25.98056 0.0000
## Regular Gas and Electricity-Regular 25.08523 0.0000
##
## $cyl
## diff lwr upr p adj
## > 6 cyl-<= 6 cyl -6.335 -6.489 -6.18 0
TukeyHSD(model1B, ordered=FALSE, conf.level = .95)
## Tukey multiple comparisons of means
## 95% family-wise confidence level
##
## Fit: aov(formula = hwy ~ fuel + displ, data = datasub)
##
## $fuel
## diff lwr
## Diesel-CNG 13.27007 10.9229
## Gasoline or E85-CNG -0.94490 -3.1068
## Gasoline or natural gas-CNG -4.06667 -8.0267
## Gasoline or propane-CNG -5.56667 -11.0149
## Midgrade-CNG 0.11938 -2.9087
## Premium-CNG 1.89746 -0.2268
## Premium and Electricity-CNG 6.93333 -7.4229
## Premium Gas or Electricity-CNG 12.21905 6.4499
## Premium or E85-CNG 1.99015 -0.6121
## Regular-CNG 2.65741 0.5353
## Regular Gas and Electricity-CNG 22.55833 17.1101
## Gasoline or E85-Diesel -14.21497 -15.3204
## Gasoline or natural gas-Diesel -17.33673 -20.8339
## Gasoline or propane-Diesel -18.83673 -23.9584
## Midgrade-Diesel -13.15069 -15.5418
## Premium-Diesel -11.37261 -12.4025
## Premium and Electricity-Diesel -6.33673 -20.5723
## Premium Gas or Electricity-Diesel -1.05102 -6.5129
## Premium or E85-Diesel -11.27992 -13.1020
## Regular-Diesel -10.61266 -11.6381
## Regular Gas and Electricity-Diesel 9.28827 4.1666
## Gasoline or natural gas-Gasoline or E85 -3.12176 -6.4973
## Gasoline or propane-Gasoline or E85 -4.62176 -9.6612
## Midgrade-Gasoline or E85 1.06428 -1.1453
## Premium-Gasoline or E85 2.84236 2.3677
## Premium and Electricity-Gasoline or E85 7.87824 -6.3279
## Premium Gas or Electricity-Gasoline or E85 13.16395 7.7791
## Premium or E85-Gasoline or E85 2.93505 1.3588
## Regular-Gasoline or E85 3.60231 3.1374
## Regular Gas and Electricity-Gasoline or E85 23.50324 18.4638
## Gasoline or propane-Gasoline or natural gas -1.50000 -7.5336
## Midgrade-Gasoline or natural gas 4.18605 0.1998
## Premium-Gasoline or natural gas 5.96413 2.6125
## Premium and Electricity-Gasoline or natural gas 11.00000 -3.5885
## Premium Gas or Electricity-Gasoline or natural gas 16.28571 9.9608
## Premium or E85-Gasoline or natural gas 6.05682 2.3836
## Regular-Gasoline or natural gas 6.72408 3.3738
## Regular Gas and Electricity-Gasoline or natural gas 26.62500 20.5914
## Midgrade-Gasoline or propane 5.68605 0.2187
## Premium-Gasoline or propane 7.46413 2.4407
## Premium and Electricity-Gasoline or propane 12.50000 -2.5607
## Premium Gas or Electricity-Gasoline or propane 17.78571 10.4368
## Premium or E85-Gasoline or propane 7.55682 2.3134
## Regular-Gasoline or propane 8.22408 3.2016
## Regular Gas and Electricity-Gasoline or propane 28.12500 21.0253
## Premium-Midgrade 1.77808 -0.3947
## Premium and Electricity-Midgrade 6.81395 -7.5496
## Premium Gas or Electricity-Midgrade 12.09967 6.3124
## Premium or E85-Midgrade 1.87077 -0.7712
## Regular-Midgrade 2.53803 0.3674
## Regular Gas and Electricity-Midgrade 22.43895 16.9716
## Premium and Electricity-Premium 5.03587 -9.1646
## Premium Gas or Electricity-Premium 10.32159 4.9518
## Premium or E85-Premium 0.09269 -1.4315
## Regular-Premium 0.75995 0.5258
## Regular Gas and Electricity-Premium 20.66087 15.6375
## Premium Gas or Electricity-Premium and Electricity 5.28571 -9.8940
## Premium or E85-Premium and Electricity -4.94318 -19.2230
## Regular-Premium and Electricity -4.27592 -18.4761
## Regular Gas and Electricity-Premium and Electricity 15.62500 0.5643
## Premium or E85-Premium Gas or Electricity -10.22890 -15.8051
## Regular-Premium Gas or Electricity -9.56164 -14.9306
## Regular Gas and Electricity-Premium Gas or Electricity 10.33929 2.9904
## Regular-Premium or E85 0.66726 -0.8539
## Regular Gas and Electricity-Premium or E85 20.56818 15.3247
## Regular Gas and Electricity-Regular 19.90092 14.8784
## upr p adj
## Diesel-CNG 15.6172 0.0000
## Gasoline or E85-CNG 1.2170 0.9581
## Gasoline or natural gas-CNG -0.1067 0.0379
## Gasoline or propane-CNG -0.1184 0.0400
## Midgrade-CNG 3.1475 1.0000
## Premium-CNG 4.0217 0.1340
## Premium and Electricity-CNG 21.2896 0.9171
## Premium Gas or Electricity-CNG 17.9882 0.0000
## Premium or E85-CNG 4.5924 0.3400
## Regular-CNG 4.7795 0.0025
## Regular Gas and Electricity-CNG 28.0066 0.0000
## Gasoline or E85-Diesel -13.1095 0.0000
## Gasoline or natural gas-Diesel -13.8396 0.0000
## Gasoline or propane-Diesel -13.7151 0.0000
## Midgrade-Diesel -10.7595 0.0000
## Premium-Diesel -10.3427 0.0000
## Premium and Electricity-Diesel 7.8988 0.9523
## Premium Gas or Electricity-Diesel 4.4108 1.0000
## Premium or E85-Diesel -9.4579 0.0000
## Regular-Diesel -9.5872 0.0000
## Regular Gas and Electricity-Diesel 14.4099 0.0000
## Gasoline or natural gas-Gasoline or E85 0.2538 0.1020
## Gasoline or propane-Gasoline or E85 0.4177 0.1092
## Midgrade-Gasoline or E85 3.2739 0.9185
## Premium-Gasoline or E85 3.3170 0.0000
## Premium and Electricity-Gasoline or E85 22.0844 0.8115
## Premium Gas or Electricity-Gasoline or E85 18.5488 0.0000
## Premium or E85-Gasoline or E85 4.5113 0.0000
## Regular-Gasoline or E85 4.0672 0.0000
## Regular Gas and Electricity-Gasoline or E85 28.5427 0.0000
## Gasoline or propane-Gasoline or natural gas 4.5336 0.9997
## Midgrade-Gasoline or natural gas 8.1723 0.0296
## Premium-Gasoline or natural gas 9.3157 0.0000
## Premium and Electricity-Gasoline or natural gas 25.5885 0.3626
## Premium Gas or Electricity-Gasoline or natural gas 22.6106 0.0000
## Premium or E85-Gasoline or natural gas 9.7300 0.0000
## Regular-Gasoline or natural gas 10.0743 0.0000
## Regular Gas and Electricity-Gasoline or natural gas 32.6586 0.0000
## Midgrade-Gasoline or propane 11.1534 0.0330
## Premium-Gasoline or propane 12.4875 0.0001
## Premium and Electricity-Gasoline or propane 27.5607 0.2198
## Premium Gas or Electricity-Gasoline or propane 25.1346 0.0000
## Premium or E85-Gasoline or propane 12.8003 0.0002
## Regular-Gasoline or propane 13.2466 0.0000
## Regular Gas and Electricity-Gasoline or propane 35.2247 0.0000
## Premium-Midgrade 3.9508 0.2389
## Premium and Electricity-Midgrade 21.1775 0.9263
## Premium Gas or Electricity-Midgrade 17.8869 0.0000
## Premium or E85-Midgrade 4.5127 0.4661
## Regular-Midgrade 4.7087 0.0074
## Regular Gas and Electricity-Midgrade 27.9063 0.0000
## Premium and Electricity-Premium 19.2364 0.9918
## Premium Gas or Electricity-Premium 15.6914 0.0000
## Premium or E85-Premium 1.6169 1.0000
## Regular-Premium 0.9941 0.0000
## Regular Gas and Electricity-Premium 25.6843 0.0000
## Premium Gas or Electricity-Premium and Electricity 20.4655 0.9930
## Premium or E85-Premium and Electricity 9.3366 0.9933
## Regular-Premium and Electricity 9.9242 0.9980
## Regular Gas and Electricity-Premium and Electricity 30.6857 0.0339
## Premium or E85-Premium Gas or Electricity -4.6527 0.0000
## Regular-Premium Gas or Electricity -4.1927 0.0000
## Regular Gas and Electricity-Premium Gas or Electricity 17.6882 0.0003
## Regular-Premium or E85 2.1884 0.9570
## Regular Gas and Electricity-Premium or E85 25.8116 0.0000
## Regular Gas and Electricity-Regular 24.9234 0.0000
##
## $displ
## diff lwr upr p adj
## > 4 litres-<= 4 litres -6.751 -6.897 -6.604 0
#Tukey HSD test for Drive Type models
TukeyHSD(model2A, ordered=FALSE, conf.level = .95)
## Tukey multiple comparisons of means
## 95% family-wise confidence level
##
## Fit: aov(formula = hwy ~ drive + cyl, data = datasub)
##
## $drive
## diff lwr
## 4-Wheel Drive-2-Wheel Drive 4.9953 -0.07882
## 4-Wheel or All-Wheel Drive-2-Wheel Drive 3.2634 -1.79627
## All-Wheel Drive-2-Wheel Drive 7.5593 2.49354
## Front-Wheel Drive-2-Wheel Drive 11.8899 6.83197
## Part-time 4-Wheel Drive-2-Wheel Drive 1.5292 -3.65659
## Rear-Wheel Drive-2-Wheel Drive 4.6776 -0.38041
## 4-Wheel or All-Wheel Drive-4-Wheel Drive -1.7319 -2.20738
## All-Wheel Drive-4-Wheel Drive 2.5639 2.02805
## Front-Wheel Drive-4-Wheel Drive 6.8946 6.43799
## Part-time 4-Wheel Drive-4-Wheel Drive -3.4662 -4.69807
## Rear-Wheel Drive-4-Wheel Drive -0.3177 -0.77513
## All-Wheel Drive-4-Wheel or All-Wheel Drive 4.2958 3.92081
## Front-Wheel Drive-4-Wheel or All-Wheel Drive 8.6265 8.37757
## Part-time 4-Wheel Drive-4-Wheel or All-Wheel Drive -1.7343 -2.90519
## Rear-Wheel Drive-4-Wheel or All-Wheel Drive 1.4142 1.16378
## Front-Wheel Drive-All-Wheel Drive 4.3307 3.97986
## Part-time 4-Wheel Drive-All-Wheel Drive -6.0301 -7.22684
## Rear-Wheel Drive-All-Wheel Drive -2.8816 -3.23351
## Part-time 4-Wheel Drive-Front-Wheel Drive -10.3608 -11.52415
## Rear-Wheel Drive-Front-Wheel Drive -7.2123 -7.42472
## Rear-Wheel Drive-Part-time 4-Wheel Drive 3.1485 1.98475
## upr p adj
## 4-Wheel Drive-2-Wheel Drive 10.0695 0.0570
## 4-Wheel or All-Wheel Drive-2-Wheel Drive 8.3231 0.4790
## All-Wheel Drive-2-Wheel Drive 12.6250 0.0002
## Front-Wheel Drive-2-Wheel Drive 16.9479 0.0000
## Part-time 4-Wheel Drive-2-Wheel Drive 6.7149 0.9770
## Rear-Wheel Drive-2-Wheel Drive 9.7357 0.0917
## 4-Wheel or All-Wheel Drive-4-Wheel Drive -1.2564 0.0000
## All-Wheel Drive-4-Wheel Drive 3.0998 0.0000
## Front-Wheel Drive-4-Wheel Drive 7.3512 0.0000
## Part-time 4-Wheel Drive-4-Wheel Drive -2.2343 0.0000
## Rear-Wheel Drive-4-Wheel Drive 0.1397 0.3842
## All-Wheel Drive-4-Wheel or All-Wheel Drive 4.6709 0.0000
## Front-Wheel Drive-4-Wheel or All-Wheel Drive 8.8754 0.0000
## Part-time 4-Wheel Drive-4-Wheel or All-Wheel Drive -0.5633 0.0003
## Rear-Wheel Drive-4-Wheel or All-Wheel Drive 1.6646 0.0000
## Front-Wheel Drive-All-Wheel Drive 4.6815 0.0000
## Part-time 4-Wheel Drive-All-Wheel Drive -4.8334 0.0000
## Rear-Wheel Drive-All-Wheel Drive -2.5298 0.0000
## Part-time 4-Wheel Drive-Front-Wheel Drive -9.1974 0.0000
## Rear-Wheel Drive-Front-Wheel Drive -6.9999 0.0000
## Rear-Wheel Drive-Part-time 4-Wheel Drive 4.3122 0.0000
##
## $cyl
## diff lwr upr p adj
## > 6 cyl-<= 6 cyl -3.772 -3.904 -3.64 0
TukeyHSD(model2B, ordered=FALSE, conf.level = .95)
## Tukey multiple comparisons of means
## 95% family-wise confidence level
##
## Fit: aov(formula = hwy ~ drive + displ, data = datasub)
##
## $drive
## diff lwr
## 4-Wheel Drive-2-Wheel Drive 4.9953 0.01875
## 4-Wheel or All-Wheel Drive-2-Wheel Drive 3.2634 -1.69897
## All-Wheel Drive-2-Wheel Drive 7.5593 2.59095
## Front-Wheel Drive-2-Wheel Drive 11.8899 6.92923
## Part-time 4-Wheel Drive-2-Wheel Drive 1.5292 -3.55687
## Rear-Wheel Drive-2-Wheel Drive 4.6776 -0.28314
## 4-Wheel or All-Wheel Drive-4-Wheel Drive -1.7319 -2.19824
## All-Wheel Drive-4-Wheel Drive 2.5639 2.03836
## Front-Wheel Drive-4-Wheel Drive 6.8946 6.44677
## Part-time 4-Wheel Drive-4-Wheel Drive -3.4662 -4.67439
## Rear-Wheel Drive-4-Wheel Drive -0.3177 -0.76634
## All-Wheel Drive-4-Wheel or All-Wheel Drive 4.2958 3.92802
## Front-Wheel Drive-4-Wheel or All-Wheel Drive 8.6265 8.38236
## Part-time 4-Wheel Drive-4-Wheel or All-Wheel Drive -1.7343 -2.88267
## Rear-Wheel Drive-4-Wheel or All-Wheel Drive 1.4142 1.16859
## Front-Wheel Drive-All-Wheel Drive 4.3307 3.98660
## Part-time 4-Wheel Drive-All-Wheel Drive -6.0301 -7.20382
## Rear-Wheel Drive-All-Wheel Drive -2.8816 -3.22674
## Part-time 4-Wheel Drive-Front-Wheel Drive -10.3608 -11.50178
## Rear-Wheel Drive-Front-Wheel Drive -7.2123 -7.42064
## Rear-Wheel Drive-Part-time 4-Wheel Drive 3.1485 2.00712
## upr p adj
## 4-Wheel Drive-2-Wheel Drive 9.9719 0.0484
## 4-Wheel or All-Wheel Drive-2-Wheel Drive 8.2258 0.4542
## All-Wheel Drive-2-Wheel Drive 12.5276 0.0001
## Front-Wheel Drive-2-Wheel Drive 16.8506 0.0000
## Part-time 4-Wheel Drive-2-Wheel Drive 6.6152 0.9747
## Rear-Wheel Drive-2-Wheel Drive 9.6384 0.0797
## 4-Wheel or All-Wheel Drive-4-Wheel Drive -1.2656 0.0000
## All-Wheel Drive-4-Wheel Drive 3.0895 0.0000
## Front-Wheel Drive-4-Wheel Drive 7.3424 0.0000
## Part-time 4-Wheel Drive-4-Wheel Drive -2.2580 0.0000
## Rear-Wheel Drive-4-Wheel Drive 0.1309 0.3596
## All-Wheel Drive-4-Wheel or All-Wheel Drive 4.6637 0.0000
## Front-Wheel Drive-4-Wheel or All-Wheel Drive 8.8706 0.0000
## Part-time 4-Wheel Drive-4-Wheel or All-Wheel Drive -0.5859 0.0002
## Rear-Wheel Drive-4-Wheel or All-Wheel Drive 1.6598 0.0000
## Front-Wheel Drive-All-Wheel Drive 4.6747 0.0000
## Part-time 4-Wheel Drive-All-Wheel Drive -4.8564 0.0000
## Rear-Wheel Drive-All-Wheel Drive -2.5366 0.0000
## Part-time 4-Wheel Drive-Front-Wheel Drive -9.2197 0.0000
## Rear-Wheel Drive-Front-Wheel Drive -7.0040 0.0000
## Rear-Wheel Drive-Part-time 4-Wheel Drive 4.2898 0.0000
##
## $displ
## diff lwr upr p adj
## > 4 litres-<= 4 litres -3.95 -4.077 -3.823 0
#Tukey HSD test for Year models
TukeyHSD(model3A, ordered=FALSE, conf.level = .95)
## Tukey multiple comparisons of means
## 95% family-wise confidence level
##
## Fit: aov(formula = hwy ~ year + cyl, data = datasub)
##
## $year
## diff lwr upr p adj
## 2001-2000 -0.06069 -0.77083 0.6494 1.0000
## 2002-2000 -0.23881 -0.93727 0.4597 0.9987
## 2003-2000 -0.42217 -1.10955 0.2652 0.7626
## 2004-2000 -0.14994 -0.82648 0.5266 1.0000
## 2005-2000 0.08348 -0.58758 0.7545 1.0000
## 2006-2000 -0.16520 -0.84409 0.5137 1.0000
## 2007-2000 -0.13063 -0.80665 0.5454 1.0000
## 2008-2000 0.18218 -0.48652 0.8509 0.9999
## 2009-2000 0.81376 0.14483 1.4827 0.0032
## 2010-2000 1.75883 1.08061 2.4371 0.0000
## 2011-2000 2.01324 1.33722 2.6893 0.0000
## 2012-2000 2.79200 2.11825 3.4658 0.0000
## 2013-2000 3.88674 3.21616 4.5573 0.0000
## 2014-2000 4.42482 3.75797 5.0917 0.0000
## 2015-2000 5.03589 3.87956 6.1922 0.0000
## 2002-2001 -0.17811 -0.86192 0.5057 1.0000
## 2003-2001 -0.36148 -1.03396 0.3110 0.9012
## 2004-2001 -0.08925 -0.75064 0.5721 1.0000
## 2005-2001 0.14418 -0.51161 0.8000 1.0000
## 2006-2001 -0.10451 -0.76830 0.5593 1.0000
## 2007-2001 -0.06994 -0.73080 0.5909 1.0000
## 2008-2001 0.24287 -0.41050 0.8962 0.9968
## 2009-2001 0.87445 0.22084 1.5281 0.0005
## 2010-2001 1.81953 1.15641 2.4826 0.0000
## 2011-2001 2.07393 1.41307 2.7348 0.0000
## 2012-2001 2.85270 2.19416 3.5112 0.0000
## 2013-2001 3.94743 3.29213 4.6027 0.0000
## 2014-2001 4.48551 3.83403 5.1370 0.0000
## 2015-2001 5.09658 3.94905 6.2441 0.0000
## 2003-2002 -0.18336 -0.84352 0.4768 0.9999
## 2004-2002 0.08886 -0.55998 0.7377 1.0000
## 2005-2002 0.32229 -0.32085 0.9654 0.9428
## 2006-2002 0.07360 -0.57769 0.7249 1.0000
## 2007-2002 0.10817 -0.54014 0.7565 1.0000
## 2008-2002 0.42098 -0.21969 1.0616 0.6599
## 2009-2002 1.05256 0.41165 1.6935 0.0000
## 2010-2002 1.99764 1.34703 2.6482 0.0000
## 2011-2002 2.25204 1.60373 2.9004 0.0000
## 2012-2002 3.03081 2.38487 3.6768 0.0000
## 2013-2002 4.12555 3.48291 4.7682 0.0000
## 2014-2002 4.66363 4.02488 5.3024 0.0000
## 2015-2002 5.27469 4.13434 6.4150 0.0000
## 2004-2003 0.27222 -0.36468 0.9091 0.9863
## 2005-2003 0.50565 -0.12543 1.1367 0.3014
## 2006-2003 0.25697 -0.38243 0.8964 0.9926
## 2007-2003 0.29154 -0.34482 0.9279 0.9736
## 2008-2003 0.60434 -0.02423 1.2329 0.0751
## 2009-2003 1.23593 0.60711 1.8647 0.0000
## 2010-2003 2.18100 1.54230 2.8197 0.0000
## 2011-2003 2.43541 1.79905 3.0718 0.0000
## 2012-2003 3.21417 2.58023 3.8481 0.0000
## 2013-2003 4.30891 3.67833 4.9395 0.0000
## 2014-2003 4.84699 4.22038 5.4736 0.0000
## 2015-2003 5.45805 4.32446 6.5916 0.0000
## 2005-2004 0.23343 -0.38582 0.8527 0.9962
## 2006-2004 -0.01526 -0.64298 0.6125 1.0000
## 2007-2004 0.01931 -0.60531 0.6439 1.0000
## 2008-2004 0.33212 -0.28456 0.9488 0.8998
## 2009-2004 0.96370 0.34677 1.5806 0.0000
## 2010-2004 1.90878 1.28177 2.5358 0.0000
## 2011-2004 2.16318 1.53856 2.7878 0.0000
## 2012-2004 2.94195 2.31979 3.5641 0.0000
## 2013-2004 4.03668 3.41795 4.6554 0.0000
## 2014-2004 4.57476 3.96008 5.1894 0.0000
## 2015-2004 5.18583 4.05878 6.3129 0.0000
## 2006-2005 -0.24869 -0.87050 0.3731 0.9930
## 2007-2005 -0.21412 -0.83280 0.4046 0.9985
## 2008-2005 0.09869 -0.51198 0.7094 1.0000
## 2009-2005 0.73027 0.11934 1.3412 0.0043
## 2010-2005 1.67535 1.05426 2.2964 0.0000
## 2011-2005 1.92975 1.31107 2.5484 0.0000
## 2012-2005 2.70852 2.09231 3.3247 0.0000
## 2013-2005 3.80326 3.19052 4.4160 0.0000
## 2014-2005 4.34134 3.73268 4.9500 0.0000
## 2015-2005 4.95240 3.82863 6.0762 0.0000
## 2007-2006 0.03457 -0.59260 0.6617 1.0000
## 2008-2006 0.34738 -0.27188 0.9666 0.8661
## 2009-2006 0.97896 0.35945 1.5985 0.0000
## 2010-2006 1.92404 1.29450 2.5536 0.0000
## 2011-2006 2.17844 1.55128 2.8056 0.0000
## 2012-2006 2.95721 2.33249 3.5819 0.0000
## 2013-2006 4.05194 3.43064 4.6732 0.0000
## 2014-2006 4.59002 3.97275 5.2073 0.0000
## 2015-2006 5.20109 4.07263 6.3295 0.0000
## 2008-2007 0.31281 -0.30331 0.9289 0.9364
## 2009-2007 0.94439 0.32802 1.5608 0.0000
## 2010-2007 1.88947 1.26302 2.5159 0.0000
## 2011-2007 2.14387 1.51981 2.7679 0.0000
## 2012-2007 2.92264 2.30103 3.5442 0.0000
## 2013-2007 4.01737 3.39921 4.6355 0.0000
## 2014-2007 4.55545 3.94134 5.1696 0.0000
## 2015-2007 5.16652 4.03978 6.2933 0.0000
## 2009-2008 0.63158 0.02325 1.2399 0.0325
## 2010-2008 1.57666 0.95812 2.1952 0.0000
## 2011-2008 1.83106 1.21494 2.4472 0.0000
## 2012-2008 2.60983 1.99620 3.2235 0.0000
## 2013-2008 3.70456 3.09442 4.3147 0.0000
## 2014-2008 4.24265 3.63660 4.8487 0.0000
## 2015-2008 4.85371 3.73135 5.9761 0.0000
## 2010-2009 0.94508 0.32629 1.5639 0.0000
## 2011-2009 1.19948 0.58311 1.8159 0.0000
## 2012-2009 1.97825 1.36437 2.5921 0.0000
## 2013-2009 3.07298 2.46258 3.6834 0.0000
## 2014-2009 3.61106 3.00476 4.2174 0.0000
## 2015-2009 4.22213 3.09963 5.3446 0.0000
## 2011-2010 0.25440 -0.37204 0.8809 0.9918
## 2012-2010 1.03317 0.40917 1.6572 0.0000
## 2013-2010 2.12791 1.50733 2.7485 0.0000
## 2014-2010 2.66599 2.04944 3.2825 0.0000
## 2015-2010 3.27705 2.14899 4.4051 0.0000
## 2012-2011 0.77877 0.15716 1.4004 0.0019
## 2013-2011 1.87350 1.25533 2.4917 0.0000
## 2014-2011 2.41158 1.79746 3.0257 0.0000
## 2015-2011 3.02265 1.89591 4.1494 0.0000
## 2013-2012 1.09474 0.47905 1.7104 0.0000
## 2014-2012 1.63282 1.02120 2.2444 0.0000
## 2015-2012 2.24388 1.11850 3.3693 0.0000
## 2014-2013 0.53808 -0.07005 1.1462 0.1557
## 2015-2013 1.14915 0.02566 2.2726 0.0388
## 2015-2014 0.61106 -0.51020 1.7323 0.8908
##
## $cyl
## diff lwr upr p adj
## > 6 cyl-<= 6 cyl -7.144 -7.293 -6.995 0
TukeyHSD(model3B, ordered=FALSE, conf.level = .95)
## Tukey multiple comparisons of means
## 95% family-wise confidence level
##
## Fit: aov(formula = hwy ~ year + displ, data = datasub)
##
## $year
## diff lwr upr p adj
## 2001-2000 -0.06069 -0.752176 0.6308 1.0000
## 2002-2000 -0.23881 -0.918929 0.4413 0.9983
## 2003-2000 -0.42217 -1.091502 0.2472 0.7246
## 2004-2000 -0.14994 -0.808710 0.5088 1.0000
## 2005-2000 0.08348 -0.569954 0.7369 1.0000
## 2006-2000 -0.16520 -0.826257 0.4959 1.0000
## 2007-2000 -0.13063 -0.788900 0.5276 1.0000
## 2008-2000 0.18218 -0.468958 0.8333 0.9999
## 2009-2000 0.81376 0.162396 1.4651 0.0020
## 2010-2000 1.75883 1.098421 2.4192 0.0000
## 2011-2000 2.01324 1.354972 2.6715 0.0000
## 2012-2000 2.79200 2.135948 3.4481 0.0000
## 2013-2000 3.88674 3.233769 4.5397 0.0000
## 2014-2000 4.42482 3.775481 5.0742 0.0000
## 2015-2000 5.03589 3.909925 6.1618 0.0000
## 2002-2001 -0.17811 -0.843961 0.4877 0.9999
## 2003-2001 -0.36148 -1.016299 0.2933 0.8803
## 2004-2001 -0.08925 -0.733269 0.5548 1.0000
## 2005-2001 0.14418 -0.494390 0.7827 1.0000
## 2006-2001 -0.10451 -0.750868 0.5419 1.0000
## 2007-2001 -0.06994 -0.713447 0.5736 1.0000
## 2008-2001 0.24287 -0.393340 0.8791 0.9957
## 2009-2001 0.87445 0.238009 1.5109 0.0003
## 2010-2001 1.81953 1.173825 2.4652 0.0000
## 2011-2001 2.07393 1.430425 2.7174 0.0000
## 2012-2001 2.85270 2.211452 3.4939 0.0000
## 2013-2001 3.94743 3.309344 4.5855 0.0000
## 2014-2001 4.48551 3.851142 5.1199 0.0000
## 2015-2001 5.09658 3.979183 6.2140 0.0000
## 2003-2002 -0.18336 -0.826179 0.4595 0.9999
## 2004-2002 0.08886 -0.542943 0.7207 1.0000
## 2005-2002 0.32229 -0.303958 0.9485 0.9291
## 2006-2002 0.07360 -0.560587 0.7078 1.0000
## 2007-2002 0.10817 -0.523112 0.7395 1.0000
## 2008-2002 0.42098 -0.202861 1.0448 0.6145
## 2009-2002 1.05256 0.428483 1.6766 0.0000
## 2010-2002 1.99764 1.364118 2.6312 0.0000
## 2011-2002 2.25204 1.620760 2.8833 0.0000
## 2012-2002 3.03081 2.401831 3.6598 0.0000
## 2013-2002 4.12555 3.499785 4.7513 0.0000
## 2014-2002 4.66363 4.041657 5.2856 0.0000
## 2015-2002 5.27469 4.164290 6.3851 0.0000
## 2004-2003 0.27222 -0.347951 0.8924 0.9823
## 2005-2003 0.50565 -0.108861 1.1202 0.2577
## 2006-2003 0.25697 -0.365640 0.8796 0.9903
## 2007-2003 0.29154 -0.328110 0.9112 0.9665
## 2008-2003 0.60434 -0.007718 1.2164 0.0573
## 2009-2003 1.23593 0.623622 1.8482 0.0000
## 2010-2003 2.18100 1.559077 2.8029 0.0000
## 2011-2003 2.43541 1.815762 3.0551 0.0000
## 2012-2003 3.21417 2.596876 3.8315 0.0000
## 2013-2003 4.30891 3.694892 4.9229 0.0000
## 2014-2003 4.84699 4.236836 5.4571 0.0000
## 2015-2003 5.45805 4.354228 6.5619 0.0000
## 2005-2004 0.23343 -0.369558 0.8364 0.9950
## 2006-2004 -0.01526 -0.626490 0.5960 1.0000
## 2007-2004 0.01931 -0.588905 0.6275 1.0000
## 2008-2004 0.33212 -0.268368 0.9326 0.8786
## 2009-2004 0.96370 0.362967 1.5644 0.0000
## 2010-2004 1.90878 1.298240 2.5193 0.0000
## 2011-2004 2.16318 1.554967 2.7714 0.0000
## 2012-2004 2.94195 2.336126 3.5478 0.0000
## 2013-2004 4.03668 3.434204 4.6392 0.0000
## 2014-2004 4.57476 3.976223 5.1733 0.0000
## 2015-2004 5.18583 4.088378 6.2833 0.0000
## 2006-2005 -0.24869 -0.854171 0.3568 0.9908
## 2007-2005 -0.21412 -0.816557 0.3883 0.9980
## 2008-2005 0.09869 -0.495945 0.6933 1.0000
## 2009-2005 0.73027 0.135387 1.3252 0.0027
## 2010-2005 1.67535 1.070566 2.2801 0.0000
## 2011-2005 1.92975 1.327315 2.5322 0.0000
## 2012-2005 2.70852 2.108497 3.3085 0.0000
## 2013-2005 3.80326 3.206607 4.3999 0.0000
## 2014-2005 4.34134 3.748665 4.9340 0.0000
## 2015-2005 4.95240 3.858141 6.0467 0.0000
## 2007-2006 0.03457 -0.576125 0.6453 1.0000
## 2008-2006 0.34738 -0.255621 0.9504 0.8399
## 2009-2006 0.97896 0.375716 1.5822 0.0000
## 2010-2006 1.92404 1.311029 2.5370 0.0000
## 2011-2006 2.17844 1.567747 2.7891 0.0000
## 2012-2006 2.95721 2.348895 3.5655 0.0000
## 2013-2006 4.05194 3.446960 4.6569 0.0000
## 2014-2006 4.59002 3.988962 5.1911 0.0000
## 2015-2006 5.20109 4.102261 6.2999 0.0000
## 2008-2007 0.31281 -0.287130 0.9127 0.9215
## 2009-2007 0.94439 0.344205 1.5446 0.0000
## 2010-2007 1.88947 1.279469 2.4995 0.0000
## 2011-2007 2.14387 1.536198 2.7515 0.0000
## 2012-2007 2.92264 2.317359 3.5279 0.0000
## 2013-2007 4.01737 3.415440 4.6193 0.0000
## 2014-2007 4.55545 3.957463 5.1534 0.0000
## 2015-2007 5.16652 4.069368 6.2637 0.0000
## 2009-2008 0.63158 0.039228 1.2239 0.0234
## 2010-2008 1.57666 0.974365 2.1790 0.0000
## 2011-2008 1.83106 1.231124 2.4310 0.0000
## 2012-2008 2.60983 2.012316 3.2073 0.0000
## 2013-2008 3.70456 3.110441 4.2987 0.0000
## 2014-2008 4.24265 3.652516 4.8328 0.0000
## 2015-2008 4.85371 3.760824 5.9466 0.0000
## 2010-2009 0.94508 0.342538 1.5476 0.0000
## 2011-2009 1.19948 0.599296 1.7997 0.0000
## 2012-2009 1.97825 1.380487 2.5760 0.0000
## 2013-2009 3.07298 2.478610 3.6674 0.0000
## 2014-2009 3.61106 3.020683 4.2014 0.0000
## 2015-2009 4.22213 3.129107 5.3151 0.0000
## 2011-2010 0.25440 -0.355593 0.8644 0.9892
## 2012-2010 1.03317 0.425558 1.6408 0.0000
## 2013-2010 2.12791 1.523626 2.7322 0.0000
## 2014-2010 2.66599 2.065634 3.2663 0.0000
## 2015-2010 3.27705 2.178612 4.3755 0.0000
## 2012-2011 0.77877 0.173487 1.3840 0.0011
## 2013-2011 1.87350 1.271568 2.4754 0.0000
## 2014-2011 2.41158 1.813591 3.0096 0.0000
## 2015-2011 3.02265 1.925496 4.1198 0.0000
## 2013-2012 1.09474 0.495220 1.6943 0.0000
## 2014-2012 1.63282 1.037259 2.2284 0.0000
## 2015-2012 2.24388 1.148055 3.3397 0.0000
## 2014-2013 0.53808 -0.054077 1.1302 0.1256
## 2015-2013 1.14915 0.055164 2.2431 0.0282
## 2015-2014 0.61106 -0.480753 1.7029 0.8682
##
## $displ
## diff lwr upr p adj
## > 4 litres-<= 4 litres -7.343 -7.485 -7.201 0
Lastly we plot a fitted model against the residuals. We do not see a very large degree of variation among the plot.
#Plot of Fitted vs Residuals of Fuel Type models
plot(fitted(model1A), residuals(model1A))
plot(fitted(model1B), residuals(model1B))
#Plot of Fitted vs Residuals of Drive Type models
plot(fitted(model2A), residuals(model2A))
plot(fitted(model2B), residuals(model2B))
#Plot of Fitted vs Residuals of Year models
plot(fitted(model3A), residuals(model3A))
plot(fitted(model3B), residuals(model3B))
Overrall the results of our model lead us to believe our model is not adequate and does not explain the effect of the fuel type, year, and drive type on the variance in highway gas mileage.
No literature was used
The R package in which this data was found can be located at https://github.com/hadley/fueleconomy
It is possible that the conclusions of our analysis are the results of chance. One concern is that the data for each car was collected only once. We don’t know the condition of the tests and it is possible that the conditions of each test may have resulted in better or worse outputs for highway gas mileage. There are other factors involved as well. Two vehicles could have the exact same engine set up yet it is possible that they have different weights therefore effecting their mileage output.
Also since our data appears to not be normal, and data being normal is an assumption for the ANOVA test we can instead perform a Kruskal-Wallis rank sum test. Kruskal-Wallis is a non-parametric to test whether the different groups all have the same distribution. We use this on each of our factors.
#Kruskal-Wallis test on Fuel Type factor
kruskal.test(hwy~fuel, data=datasub)
##
## Kruskal-Wallis rank sum test
##
## data: hwy by fuel
## Kruskal-Wallis chi-squared = 969.1, df = 12, p-value < 2.2e-16
#Kruskal-Wallis test on Year factor
kruskal.test(hwy~year, data=datasub)
##
## Kruskal-Wallis rank sum test
##
## data: hwy by year
## Kruskal-Wallis chi-squared = 1283, df = 15, p-value < 2.2e-16
#Kruskal-Wallis test on Drive Type factor
kruskal.test(hwy~drive, data=datasub)
##
## Kruskal-Wallis rank sum test
##
## data: hwy by drive
## Kruskal-Wallis chi-squared = 7523, df = 6, p-value < 2.2e-16