cor()

cor()

The cor() function will compute the covariance or correlation of x and y if these are vectors. If x and y are matrices then the covariances (or correlations) between the columns of x and the columns of y are computed.

The default method will compute the Pearson correlation coefficient (r), but you may opt to include the 'method' argument to indicate one of "pearson" (default), "kendall", or "spearman". See the link below for additional information:


Example:

# Calculate the correlation between Height and Thumb
cor(Thumb ~ Height, data = Fingers)

Example output:
Output of cor() function


    • Related Articles

    • correlation coefficient

      Correlation coefficient is a special case of slope in which both the outcome and explanatory variables are transformed into z scores prior to analysis; also known as Pearson's r.
    • correlational study

      Correlational study is a research design that involves taking a random sample from a population and then measuring some variables; also known as an observational study.
    • Bonferroni Adjustment

      A Bonferroni adjustment (also known as a Bonferroni correction) is used when making simultaneous comparisons, to make sure that your overall error rate is reduced. You simply divide your acceptable alpha (e.g., .05) by the number of simultaneous ...
    • Type I and Type II Error

      Type I and II Error describe the possible errors we might make when drawing conclusions about the DGP based on our data.  Type I error is when we should adopt the empty model but we adopt the complex model in error.  Type II error is when we should ...
    • Pearson’s r

      Pearson’s r is a special case of slope in which both the outcome and explanatory variables are transformed into z scores prior to analysis; also known as the correlation coefficient.