Book Image

R for Data Science

By : Dan Toomey
Book Image

R for Data Science

By: Dan Toomey

Overview of this book

Table of Contents (19 chapters)


In R, there are several packages that provide the correlation functionality to the programmer. We will be using the following packages in this chapter:

  • corrgram: This is the tool to graphically display correlations

  • Hmisc: This contains a variety of miscellaneous R functions

  • polycor: This contains functions to compute polychoric correlations

  • ggm: This contains functions for analyzing and fitting graphical Markov models


Basic correlation is performed in R using the cor function. The cor function is defined as follows:

cor(x, y = NULL, 
  use = "everything", 
  method = c("pearson", "kendall", "spearman"))

The various parameters of this function are described in the following table:




This is the dataset.


This is the dataset that is compatible with x.


This is the optional method for computing the covariance of missing values assigned. The choices are:

  • everything

  • all.obs

  • complete.obs

  • na.or.complete

  • pairwise.complete.obs