“If you are a User, then everything you've done so far has been according to a plan, right?”
Tron, Tron
At the end of this session you should be able to
Correlation meassures the deviation of two (or more) variables from independence. Using correlation coefficients, this deviation can be estimated for random samples. While a variety of correlation coefficients exist, only two should be introduced in this context:
One standard function used in R for computing the correlation is the cor() function which provides all three coefficient options. A minimalistic call of the function looks like
cor(x, y)
and returns pearson's correlation coefficient. If there are missing values in x and/or y, you have to handle them by using the attribute “use” of the cor() function (e.g. use = “complete.obs”). The cor() function can also be applied to entire data frames.
For more information, have a look on the help of the function by typing ?cor
inside your R environment or visit Quick-R's page on correlation.
If you are interested in confidence intervals which give you an idea if the correlation coefficient is actually significant, try the cor.test() function which works analogously but can only be applied to two variables at a time (and not an entire data frame). See ?cor.test
for more information.