How to do it...

Perform the following steps:

  1. First, we visualize the attribute, mpg, against am using a boxplot:
        > boxplot(mtcars$mpg, mtcars$mpg[mtcars$am==0], ylab = "mpg",        names=c("overall","automobile"))        > abline(h=mean(mtcars$mpg),lwd=2, col="red")        > abline(h=mean(mtcars$mpg[mtcars$am==0]),lwd=2, col="blue")
The boxplot of mpg of the overall population and automobiles
  1. We then perform a statistical procedure to validate whether the average mpg of automobiles is lower than the average of the overall mpg:
        > mpg.mu = mean(mtcars$mpg)
        > mpg_am = mtcars$mpg[mtcars$am == 0]
        > t.test(mpg_am,mu = mpg.mu)  
  1. We begin visualizing the data ...

Get Machine Learning with R Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.