In this lab, we will examine the Motor Trend Cars data set.

The data was extracted from the 1974 Motor Trend US magazine, and comprises fuel consumption and 10 aspects of automobile design and performance for 32 automobiles (1973â€“74 models).

Variable | Description |
---|---|

mpg | Miles/(US) Gallon |

cyl | Number of Cylinders |

disp | Displacement (cu.in.) |

hp | Gross horsepower |

wt | Weight (lb/1000) |

qsec | 1/4 mile time |

vs | V or Straight Configuration Engine |

am | Transmission Type (auto/manual) |

A Tab Separated File (.tsv) containing the data can be found here:

http://stat.wvu.edu/~draffle/111/week1/lab1/mtcars2.tsv

- In StatCrunch, use the menus
`Data`

\(\to\)`Load`

\(\to\)`From File`

\(\to\)`On the web`

. - Copy and Paste the address given above into
`WWW Address`

- Click
`Load File`

at the bottom of the page.

Hand in your answers at the end of lab â€“ make sure to include you name and the lab number. Instructions are included for making graphs and finding the necessary statistics for each problem.

Each question will be worth two points, and you can receive partial credit for incorrect answers if your process was correct.

Write your final answer as a sentence and include all steps you used to get there, otherwise you will receive partial credit.

```
library(ggplot2)
mtcars2 <- read.table("mtcars2.tsv", header = T, sep = "\t")
data.frame(Variable = colnames(mtcars2)[-1],
Type = c("Numeric", "Categorical", "Numeric", "Numeric", "Numeric",
"Numeric", "Categorical", "Categorical"))
```

```
## Variable Type
## 1 mpg Numeric
## 2 cyl Categorical
## 3 disp Numeric
## 4 hp Numeric
## 5 wt Numeric
## 6 qsec Numeric
## 7 vs Categorical
## 8 am Categorical
```

`cyl`

. Describe the distribution.```
counts <- summary(factor(mtcars2$cyl))
n <- nrow(mtcars2)
data.frame(Frequency = counts,
"Rel. Freq" = counts/n*100)
```

```
## Frequency Rel..Freq
## 4 11 34.375
## 6 7 21.875
## 8 14 43.750
```

Most of the cars in the data set have eight cylinders, while six is the least common.

`am`

. Which Transmission type is more common?`ggplot(mtcars2, aes(x = am)) + geom_bar()`

Manual cars are more common than automatics in this data set.

`hp`

(you do not need to sketch it). Describe the shape of the distribution.`ggplot(mtcars2, aes(x = hp)) + geom_histogram(binwidth = 50, color = "grey80")`

The distribution of horsepower is right-skewed and unimodal with no outliers.

`hp`

? Report it.`summary(mtcars2$hp)`

```
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 52.0 96.5 123.0 146.7 180.0 335.0
```

Because the distribution is right-skewed, the median (123 hp) is a more accurate measure of center.

`hp`

grouped by `am`

. Describe the differences in the distributions.`ggplot(mtcars2, aes(x = am, y = hp, fill = am)) + geom_boxplot()`

Manuals have higher horsepower on average and more variation, while there are two automatics with unusually high horsepower.

`mpg`

. Is the distribution approximately Normal?```
library(car)
gg_qq(mtcars2, "mpg")
```

Because fuel efficiency generally follows the reference line, we can conclude that it is approximately normal.

`by(mtcars2, mtcars2$am, function(tr) round(data.frame(mean = mean(tr$mpg), sd = sd(tr$mpg)), 2))`

```
## mtcars2$am: auto
## mean sd
## 1 24.39 6.17
## --------------------------------------------------------
## mtcars2$am: manual
## mean sd
## 1 17.15 3.83
```

`(z.auto <- (22 - 24.39)/6.17)`

`## [1] -0.3873582`

`(z.manual <- (22 - 17.15)/3.83)`

`## [1] 1.266319`

22 mpg would be 1.27 standard deviations above the mean for manuals, and 0.39 standard deviations below the mean for automatics. This means that it would be more rare for a manual car to get 22 mpg.

`MPG`

\(\sim N(\mu = 20, \sigma = 6)\). What is the 90% percentile for the `MPG`

of all cars?I.e., if \(P(MPG \le x) = 0.9\), what is \(x\)?

`qnorm(.9, mean = 20, sd = 6)`

`## [1] 27.68931`

The 90% of cars have fuel efficiency less than 27.7 mpg.

I.e., if \(P(l \le QSEC \le u) = 0.75\), what are \(l\) and \(u\)?

`qnorm(c(.125, .875), mean = 17.85, sd = 1.79)`

`## [1] 15.79087 19.90913`

The middle 75% of cars finish the quarter mile in 15.8-19.9 seconds.