Correlation in R programming
Correlation coefficient can be computed using the functions cor() or cor.test():
1. cor() computes the correlation coefficient
2. cor.test() test for association/correlation between paired samples. It returns both the correlation coefficient and the significance level(or p-value) of the correlation.
cor(x, y, method = c("pearson", "kendall", "spearman"))
cor.test(x, y, method=c("pearson", "kendall", "spearman"))
For example in comparing 178 wines to determine the Flavin and Phenol content correlation we use the code;
cor.test(array1, array 2)
The R-code above depicts that the two contents has a correlation of 0.8645635 meaning they are highly positive correlated.
Was this Helpful?