基于数据分析,是否自动档汽车比手动挡更耗油

Overview

这是一个多元回归方程用于揭示汽车油耗和汽车属性之间的关系,试图回答常见的问题:是否自动档的汽车更费油?除了自动档这个属性,还有其他属性和汽车耗油之间的关系更大吗?原文见于RPubshere.

分析基于R语言,mtcars小数据集(可以扩展到更大数据集),,希望对读者有所帮助。

There are always same questions we are being asked, "Is an automatic or manual transmission better for MPG (miles per gallon)"? "Can you show me the quantitative MPG difference between automatic and manual transmissions?" such kinds of question which are related to choosing a car and saving money on gasoline. In this document we will give our answer to these questions based on our data.This supplement was also published on RPubs here with a virtual magazine name.Executive SummaryFirstly we setup the relationship between transmission and MPG via statistical regression analysis technology and find the result that manual transmission is better for MPG. Secondly we go deeply with data to show the detailed quantitative information on MPG between the two main transmissions. After analyzing the single variable transmission, we create new models with new variables to further our finding about which variables help increase MPG.Analysis phase I:

In this part, we setup a regression model between transmissions and MPG. And below are the first 6 records of data.

data(mtcars)head(mtcars)## mpg cyl disp hp drat wt qsec vs am gear carb## Mazda RX4 21.0 6 160 110 3.90 2.620 16.46 0 1 4 4## Mazda RX4 Wag 21.0 6 160 110 3.90 2.875 17.02 0 1 4 4## Datsun 710 22.8 4 108 93 3.85 2.320 18.61 1 1 4 1## Hornet 4 Drive 21.4 6 258 110 3.08 3.215 19.44 1 0 3 1## Hornet Sportabout 18.7 8 360 175 3.15 3.440 17.02 0 0 3 2

## Valiant 18.1 6 225 105 2.76 3.460 20.22 1 0 3 1

here, the most left column shows cars’ model and, other colums are properties of that model. while am variable is for Transmission (0 = automatic, 1 = manual) and as its names suggests mpg column is for MPG.Bar plot with Regression LineNow, let’s draw a basic bar plot to show the general distribution of MPG(mpg) with Transmission(am) and a regression line to show the general relationship between MPG(mpg) and Transmission(am).plot(factor(mtcars$am),mtcars$mpg)abline(lm(mpg~am,data=mtcars),col="red",lwd=3)

There’s obvious difference between these 2 variables compared their highest, mean and lowest value pairs. On any level, the manual transmission cars has a bigger MPG value.(0 for automatic and 1 for manual).

And We could also find the trend has a positive slope that means when transmission increases one unit(from 0 to 1), or to say from automatic to manual, the MPG value will increase.

Quantitative Differencefit=lm(mtcars$mpg~factor(mtcars$am))fit## ## Call:## lm(formula = mtcars$mpg ~ factor(mtcars$am))## ## Coefficients:## (Intercept) factor(mtcars$am)1 ## 17.147 7.245Here, the intercept 17.147 is a virtual value when the regression model created, which can be regarded as a meaningless value used only for model creation(transmission equals negative value), and the slope 7.245 means every one unit increase of transmission will beget 7.245 units increase of MPG, or to say manual transmision cars has a higher MPG 7.245 than the automatic cars in general.Getting a confidence intervalsumCoef <- summary(fit)$coefficientssumCoef[2,1] + c(-1, 1) * qt(.975, df = fit$df) * sumCoef[2, 2]## [1] 3.64151 10.84837It shows the 95% confidence is 3.64151~10.84837, that make us confident for the conclusion that manual transmission have a higher MPG than automatic ones.Residual Plot and diagnosticNow, draw a residual point plot.plot(mtcars$am, resid(lm(mtcars$mpg ~ factor(mtcars$am))))

没有人会帮你一辈子,所以你要奋斗一生。

基于数据分析,是否自动档汽车比手动挡更耗油

相关文章:

你感兴趣的文章:

标签云: