Performing correlations and multivariate analysis

To analyze the relationship of more than two variables, you would need to conduct multivariate descriptive statistics, which allows the comparison of factors. Additionally, it prevents the effect of a single variable from distorting the analysis. In this recipe, we will discuss how to conduct multivariate descriptive statistics using a correlation and covariance matrix.

Getting ready

Ensure that mtcars has already been loaded into a data frame within an R session.

How to do it...

Perform the following steps:

  1. Here, you can get the covariance matrix by inputting the first three variables in mtcars to the cov function:
    > cov(mtcars[1:3])
                 mpg        cyl       disp
    mpg    36.324103  -9.172379  -633.0972
    cyl -9.172379 3.189516 ...

Get R: Recipes for Analysis, Visualization and Machine Learning 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.