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 DataFrame within an R session.
How to do it...
Perform the following steps:
- Here, you can get the covariance matrix by inputting the first three variables in
mtcars
to thecov
function:
> cov(mtcars[1:3]) Output: mpg cyldisp mpg 36.324103 -9.172379 -633.0972 cyl -9.172379 3.189516 199.6603 disp -633.097208 199.660282 15360.7998
- To obtain a correlation matrix of the dataset, we input the first three variables of
mtcars
to thecor
function:
...