20250227 Multivariate Analysis
Homework 1, make the boxplot for the mileage of American, Japanese and European cars (from left to right).
Introduction
This assignment requires us to draw boxplots of car mileage for the United States, Japan, and Europe as shown in the textbook.
The dataset carc.txt and the R script MVAboxcar.R for generating the image can be downloaded from https://github.com/QuantLet/MVA/tree/master/QID-1485-MVAboxcar.
Dataset
In R, we can use the following command to read the dataset.
| |
Below is part of the dataset carc.txt.
| V1 | V2 | V3 | V4 | V5 | V6 | V7 | V8 | V9 | V10 | V11 | V12 | V13 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | 4099 | 22 | 3 | 2 | 2.5 | 27.5 | 11 | 2930 | 186 | 40 | 121 | 3.58 |
| 2 | 4749 | 17 | 3 | 1 | 3.0 | 25.5 | 11 | 3350 | 173 | 40 | 258 | 2.53 |
| 3 | 3799 | 22 | NaN | NaN | 3.0 | 18.5 | 12 | 2640 | 168 | 35 | 121 | 3.08 |
| 4 | 9690 | 17 | 5 | 2 | 3.0 | 27.0 | 15 | 2830 | 189 | 37 | 131 | 3.20 |
| 5 | 6295 | 23 | 3 | 3 | 2.5 | 28.0 | 11 | 2070 | 174 | 36 | 97 | 3.70 |
| … | … | … | … | … | … | … | … | … | … | … | … | … |
From Table 22.3 in the textbook, we know that the dataset contains 13 parameters and 74 vehicle types. The description of each parameter is as follows:
| Variable | Symbol | Description |
|---|---|---|
| $X_1$ | P | Price |
| $X_2$ | M | Mileage (in miles per gallon) |
| $X_3$ | R78 | Repair record 1978 (rated on a 5-point scale; 5 best, 1 worst) |
| $X_4$ | R77 | Repair record 1977 (scale as before) |
| $X_5$ | H | Headroom (in inches) |
| $X_6$ | R | Rear seat clearance (distance from front seat back to rear seat, in inches) |
| $X_7$ | Tr | Trunk space (in cubic feet) |
| $X_8$ | W | Weight (in pound) |
| $X_9$ | L | Length (in inches) |
| $X_{10}$ | T | Turning diameter (clearance required to make a U-turn, in feet) |
| $X_{11}$ | D | Displacement (in cubic inches) |
| $X_{12}$ | G | Gear ratio for high gear |
| $X_{13}$ | C | Company headquarter (1 for USA, 2 for Japan, 3 for Europe) |
Boxplot
Below is an example of a boxplot drawn from the QuantLet/MVA repository on GitHub.
| |

Since we only need to draw boxplots of car mileage for different regions, we use only two parameters M = x[, 2] and C = x[, 13]. Here, M represents the miles per gallon, and C represents the company headquarters of the car manufacturer.
The original code was uploaded to GitHub by the author in 2016. We can now achieve the same result with a more concise approach. The updated code is as follows.
| |
Environment
- Operating System: Windows 11 24H2
- Programming Language: R 4.4.2
References
- Wolfgang karl härdle, léopold simar. (2015). Applied Multivariate Statistical Analysis (4th ed.). Springer. https://link.springer.com/book/10.1007/978-3-662-45171-7
- Quantnet. (2025, January 27). MVA. Github. https://github.com/QuantLet/MVA







