##taking maximum benifit out of plyr library

library("plyr")
## Warning: package 'plyr' was built under R version 3.6.3

##An analysis where we compare two types of cars based on there mode of changining gears(transmission): manual and automatic.

Dateset collection

Import the dataset

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
mera_data <- mtcars[c("mpg","am")]
head(mera_data)
##                    mpg am
## Mazda RX4         21.0  1
## Mazda RX4 Wag     21.0  1
## Datsun 710        22.8  1
## Hornet 4 Drive    21.4  0
## Hornet Sportabout 18.7  0
## Valiant           18.1  0

Exploratory data analysis

#an analysis to show how the data is manipulated to get this. this is m summary

summary(mera_data)
##       mpg              am        
##  Min.   :10.40   Min.   :0.0000  
##  1st Qu.:15.43   1st Qu.:0.0000  
##  Median :19.20   Median :0.0000  
##  Mean   :20.09   Mean   :0.4062  
##  3rd Qu.:22.80   3rd Qu.:1.0000  
##  Max.   :33.90   Max.   :1.0000
boxplot(mpg~am, data = mera_data)

##mpg vs am graph for manual vs automatic

count(mtcars, vars = "am")
##   am freq
## 1  0   19
## 2  1   13
mera_pre_model <- lm(mpg ~ ., mtcars);
summary(mera_pre_model)
## 
## Call:
## lm(formula = mpg ~ ., data = mtcars)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -3.4506 -1.6044 -0.1196  1.2193  4.6271 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)  
## (Intercept) 12.30337   18.71788   0.657   0.5181  
## cyl         -0.11144    1.04502  -0.107   0.9161  
## disp         0.01334    0.01786   0.747   0.4635  
## hp          -0.02148    0.02177  -0.987   0.3350  
## drat         0.78711    1.63537   0.481   0.6353  
## wt          -3.71530    1.89441  -1.961   0.0633 .
## qsec         0.82104    0.73084   1.123   0.2739  
## vs           0.31776    2.10451   0.151   0.8814  
## am           2.52023    2.05665   1.225   0.2340  
## gear         0.65541    1.49326   0.439   0.6652  
## carb        -0.19942    0.82875  -0.241   0.8122  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 2.65 on 21 degrees of freedom
## Multiple R-squared:  0.869,  Adjusted R-squared:  0.8066 
## F-statistic: 13.93 on 10 and 21 DF,  p-value: 3.793e-07

#different parameters comparing between manual and automatic

anova(lm(mpg ~ am, mtcars),                           
      lm(mpg ~ am + wt, mtcars),                      
      lm(mpg ~ am + wt + qsec, mtcars),               
      lm(mpg ~ am + wt + qsec + drat, mtcars),        
      lm(mpg ~ am + wt + qsec + drat + gear, mtcars)
      )     
## Analysis of Variance Table
## 
## Model 1: mpg ~ am
## Model 2: mpg ~ am + wt
## Model 3: mpg ~ am + wt + qsec
## Model 4: mpg ~ am + wt + qsec + drat
## Model 5: mpg ~ am + wt + qsec + drat + gear
##   Res.Df    RSS Df Sum of Sq       F    Pr(>F)    
## 1     30 720.90                                   
## 2     29 278.32  1    442.58 68.8055 8.913e-09 ***
## 3     28 169.29  1    109.03 16.9510 0.0003442 ***
## 4     27 167.89  1      1.40  0.2176 0.6447654    
## 5     26 167.24  1      0.65  0.1006 0.7537011    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

#we come to conclusion that 3rd i better than 4th and 5th.

mera_model_number_2 <- lm(mpg ~ am + wt + qsec, mtcars)
par(mfrow = c(2,2)); plot(mera_model_number_2)

##we compare so many different variations

mera_model_number_1 <- lm(mpg~am,mtcars)
coef(mera_model_number_1)
## (Intercept)          am 
##   17.147368    7.244939
coef(mera_model_number_2)
## (Intercept)          am          wt        qsec 
##    9.617781    2.935837   -3.916504    1.225886

##final verdict: in all the cases manual vehicles are giving better milage when compared to automatic vehichles. anyday choose manual over automatic if you use it for long drive, since fuel fficiency is more than automatic

choose automatic if you travel in metropolitian city where there is lot of traffic, in that case automatic coms in handy

project ends here

thank you

##comment

bgre rfdgvc qwedsfcv jfbgvdc jnhbgfv ujhbgfvd ikjhbgfv uijhbgfv iujyhtbgfv ikujnhbgv ujhbgv yhbgfv gbfvc tgfvc uyhbgvc yujhbgv fdvcfcv rfdcvdfgdfgfg rrrr r grtghjgfghjtwerthjyutr wefg gh tfnh ht5en tr bgt4rgh nht ght erfdvc tgfv tyhgfbv hbgv hbgv ghfbvc jhbgfvcd serdfghjgfds afgh gsdaf ghjgfds fghj gewert rdfgv rdfsae rtre wrtyt rewrty trew tghgew rtyuyt rertyuj ytretyu tret yut retyu trewf bgt5 tfgvcxdew dcv ty5r4we fgh ytrefd ght redfc bghyfgdc vbgh ytfred ghytr defghy trfcd ghtfred fcgvt redfcvg hygtr fgvh ty5rfg hytrd fcvghty rfghy trf ghygtrfdfc ght rdcf gtr5ed cfvgt rfedfcvgb hytrdfc ghygtredfc gvhyt rfgvh tyrfdc ghyt rdf gtr edfg tyr5d fgh gytredfgty6t5rd fgty6rd fcgvhty665r4d fbghy6543 refghy6t5re fgty6trf ghyu765rf ghyy6t5r fgy6 t5rfgvbh ytgrfdc vbghg fcd vbghyt rfdcfv bghygtfdc vbgyhtg fcdvgbhyg trfdcvg bhygytrfdcf ghyt rfdcvbgh ygtrdc vbght rfdcvbghyt rfgvh ytred fcvbghy trf gty6 t5rdcfv gy6t5 redfgt y6t5redf gy67 rfg hyt65 rfcgv tt65r4ed fgtyh 6t5r fgy 6t5rf bghy6 t5rfg hy6t5 rfg y6tr54e fghy 6t5rf gyh tgfv hy6 t5rf ghy t5rdf gy6 t5rf tgy67 t5rfgh yt65 rfgt y6tre fghyu 6tfgv bhy 6trfgv hyt rfg hy6 trfdxsc vbnh tgrfedws dfgh gfdsa dfghy tredc dew 2sdc vfgre3w dcfvfgt redf vgty 5ewd fgty rewdfg ty5r edfgvh ytr fgbh ytred fghy t5rewrd fgt r4esdc fgtr r4edfcfvg tr4ed fgyt fcvg tr4edfcv bghty rdfg tyred fgyhy trdfgv ghyt5 rfghy 65refg yt5r4ed fgty654erdf gt65 r4efg y65refg t65rf ghyt6 rdfgv tyr5fg t65trf ghy6 t5redf gtyhu6t5 redfgv ty5r4ed fghy 6tr5fg hyutf gbhyt6 rdfcvg hy6trfg hyt5rf dcgvy6tr dfeedfbg edfcv bgf trdsfcvbghy tfdscvbgty rdfcvbhyt rfdcfvbhgy tfdcvbghyt rfdcvbnh gytfedcvbghty rfdcvbhtg fdcvbgghfcd vbhgtf vbfgtrdfc vbnhgfc dvbgfd edv fefbv frew fbfe rfgbn gewsdc vgt rdvb hy trfvb hytg nju ytfdgb hjuytg fbnmj uygf bnj uyhgfb njy trgfbn hjuy trgfbn juyt rfbn hjytr fdvbh ytref ghy 6trf gbh y6trf ghy 6t5erfg hy6t45e rfgh y65r4 edfg y65t fbgh y654t gh y6t5erfg hjy 45trfgh 765trf gh65t4 rgh7 65refg y65 rfgyy6trf ty65tghy6t5r fgy65 t4rfghy 6terty65 r4fghy6t5 rfg hy6t5rdf gt5r4df ghytrfdv gy6tgfb nhytfrdc gt5rfv bghytrfg bhy6t5rfcv bhytrf ghyt rfcvgytrd fgtredfgv htyr4e dfcgtrd fcgty rfgvbghy trfgvbh yt5rfgvbh ytgfvhy t65rfgvh ytrfgvbnh yghvbh ytgfv bhgttf bnhgyt rfg ytgfv trfgv ghytfc v trfgv gtrf ghyt gfvbhy gtfvbh ytrfgv ghtyrfcv bgfdc vbght rfgvg tyfgv bhtyr fgbnh ytgfv b fgvbh ytfg vyt fcdvfghy trfd gh tfrgv t5rt fgvhtyf gbhtyg hytgbh ytgfvbghy tfgvghy trfgvh yt65rf gh tygfv trf vbgtrd fcvbghty rfgv htyf gbnj ytgfvb hytr fgbvghgy tfv bght fvbnhgy tfvbgh tfvb gtfvb ghtfgv bgtyrf gbt rfgvbg tfgvbgtfg bggrf bgt rfgbgtgf vgt fgg trfgg trfgtrfg t5trfg tg hytgfv ty5fg ghyt gyt rfghy trfghytg hy