2. Association and Correlation: Practical 2
Introduction
Objectives
Learn how to do the following in R
- explore the relation between numerical variables through scatter plots
- calculate the covariance for two vectors by using cov()
- calculate the Pearson correlation coefficient and Spearman correlation coefficient using the function cor()
- practically investigate the visual appearance of a bi-variate relationship and the correlation coefficient
Instruction
- Read through the text
- Execute code-examples and compare your results with what is explained in the text
- Make the exercises
- Time: 120 minutes
Introduction
The Toyota Prius was first introduced in 1997 and in the following 15 years, more than 150 hybrid cars have been introduced to the world market. This was spurred by a major interest in the future of cars using ‘alternative fuel’ to address environmental and fuel dependency concerns. In this practical, we will use a dataset that was created to study the technological advancements in different hybrid cars market segments between 1997 and 2013.
You can load the dataset through the following command:
source("http://horizon.science.uva.nl/public/VVA/hybrid_reg.R")
If everything went well, an object hybrid should have been loaded in the global environment. You can check this in the upper-right pane of RStudio (in the Environment Tab). The hybrid dataset contains #9# variables:
- carid: a unique identifier for each observation
- vehicle: the car model
- year: year of introduction
- msrp: manufacturer's suggested retail price in dollars in 2013
- accelrate: acceleration rate in km/hour/second
- mpg: fuel efficiency in miles/gallon
- mpgmpge: maximum of MPG and MPG equivalent. MPG equivalent is based on the gasoline-equivalent energy of electricity. MPGe is calculated as 33.7*driverange/battery capacity. This value is only different from mpg for plug-in hybrids.
- carclass: model class:
- C = Compact,
- M = Midsize,
- TS = 2 Seater,
- L = Large,
- PT = Pickup Truck,
- MV = Minivan,
- SUV = Sport Utility Vehicle
- carclassid: model class id, hence, the same information as the variable carclass, but in a numerical encoding.
If you are interested in the study, you can find the article at https://doi.org/10.1016/j.techfore.2014.05.008.