Section 9.3 The Cars Data Set
Statistical inference is applied to data in order to address specific research questions. We will demonstrate different inferential procedures using a specific data set with the aim of making the discussion of the different procedures more concrete. The same data set will be used for all procedures that are presented in Chapters Chapter 10—Chapter 15. This data set contains information on various models of cars and is stored in the CSV file “ The file can be found on the internet at
1
Other data sets will be used in a Case Studies chapter and in the quizzes and assignments.
cars.csv”.2
The original “Automobiles” data set is accessible at the UCI Machine Learning Repository (
archive.ics.uci.edu/ml). This data was assembled by Jeffrey C. Schlimmer, using as source the 1985 Model Import Car and Truck Specifications, 1985 Ward’s Automotive Yearbook. The current file “cars.csv” is based on all 205 observations of the original data set. We selected 17 of the 26 variables available in the original source.
pluto.huji.ac.il/~msby/StatThink/Datasets/cars.csv. You are advised to download this file to your computer and store it in the working directory of R.
Let us read the content of the CSV file into an
R data frame and produce a brief summary:
cars <- read.csv("_data/cars.csv")
summary(cars)
## make fuel.type num.of.doors body.style drive.wheels ## toyota : 32 diesel: 20 four:114 convertible: 6 4wd: 9 ## nissan : 18 gas :185 two : 89 hardtop : 8 fwd:120 ## mazda : 17 NA's: 2 hatchback :70 rwd: 76 ## honda : 13 sedan :96 ## mitsubishi: 13 wagon :25 ## subaru : 12 ## (Other) :100 ## engine.location wheel.base length width ## front:202 Min. : 86.60 Min. :141.1 Min. :60.30 ## rear : 3 1st Qu.: 94.50 1st Qu.:166.3 1st Qu.:64.10 ## Median : 97.00 Median :173.2 Median :65.50 ## Mean : 98.76 Mean :174.0 Mean :65.91 ## 3rd Qu.:102.40 3rd Qu.:183.1 3rd Qu.:66.90 ## Max. :120.90 Max. :208.1 Max. :72.30 ## ## height curb.weight engine.size horsepower ## Min. :47.80 Min. :1488 Min. : 61.0 Min. : 48.0 ## 1st Qu.:52.00 1st Qu.:2145 1st Qu.: 97.0 1st Qu.: 70.0 ## Median :54.10 Median :2414 Median :120.0 Median : 95.0 ## Mean :53.72 Mean :2556 Mean :126.9 Mean :104.3 ## 3rd Qu.:55.50 3rd Qu.:2935 3rd Qu.:141.0 3rd Qu.:116.0 ## Max. :59.80 Max. :4066 Max. :326.0 Max. :288.0 ## NA's :2 ## peak.rpm city.mpg highway.mpg price ## Min. :4150 Min. :13.00 Min. :16.00 Min. : 5118 ## 1st Qu.:4800 1st Qu.:19.00 1st Qu.:25.00 1st Qu.: 7775 ## Median :5200 Median :24.00 Median :30.00 Median :10295 ## Mean :5125 Mean :25.22 Mean :30.75 Mean :13207 ## 3rd Qu.:5500 3rd Qu.:30.00 3rd Qu.:34.00 3rd Qu.:16500 ## Max. :6600 Max. :49.00 Max. :54.00 Max. :45400 ## NA's :2 NA's :4
Observe that the first 6 variables are factors, i.e. they contain qualitative data that is associated with categorization or the description of an attribute. The last 11 variable are numeric and contain quantitative data.
Factors are summarized in
R by listing the attributes and the frequency of each attribute value. If the number of attributes is large then only the most frequent attributes are listed. Numerical variables are summarized in R with the aid of the smallest and largest values, the three quartiles (Q1, the median, and Q3) and the average (mean).
The third factor variable, “
num.of.doors”, as well as several of the numerical variables have a special category titled “NA's”. This category describes the number of missing values among the observations. For a given variable, the observations for which a value for the variable is not recorded, are marked as missing. R uses the symbol “NA” to identify a missing value.3
Indeed, if you scan the CSV file directly by opening it with a spreadsheet then every now and again you will encounter this symbol.
Missing observations are a concern in the analysis of statistical data. If the relative frequency of missing values is substantial and the reason for not obtaining the data for specific observations is related to the phenomena under investigation than naïve statistical inference may produce biased conclusions. In the “
cars” data frame missing values are less of a concern since their relative frequency is low.
One should be on the lookout for missing values when applying
R to data since the different functions may have different ways for dealing with missing values. One should make sure that the appropriate way is applied for the specific analysis.
Consider the variables of the data frame “
cars”:
-
make -
The name of the car producer (a factor).
-
fuel.type -
The type of fuel used by the car, either diesel or gas (a factor).
-
num.of.doors -
The number of passenger doors, either two or four (a factor).
-
body.style -
The type of the car (a factor).
-
drive.wheels -
The wheels powered by the engine (a factor).
-
engine.location -
The location in the car of the engine (a factor).
-
wheel.base -
The distance between the centers of the front and rear wheels in inches (numeric).
-
length -
The length of the body of the car in inches (numeric).
-
width -
The width of the body of the car in inches (numeric).
-
height -
The height of the car in inches (numeric).
-
curb.weight -
The total weight in pounds of a vehicle with standard equipment and a full tank of fuel, but with no passengers or cargo (numeric).
-
engine.size -
The volume swept by all the pistons inside the cylinders in cubic inches (numeric).
-
horsepower -
The power of the engine in horsepowers (numeric).
-
peak.rpm -
The top speed of the engine in rounds-per-minute (numeric).
-
city.mpg -
The fuel consumption of the car in city driving conditions, measured as miles per gallon of fuel (numeric).
-
highway.mpg -
The fuel consumption of the car in highway driving conditions, measured as miles per gallon of fuel (numeric).
-
price -
The retail price of the car in US Dollars (numeric).
