2. Association and Correlation: Practical 2
Spearman Correlation Coefficient
Spearman's correlation coefficient measures the strength and direction of monotonic relationship between two variables. Monotonicity is 'less restrictive' than linearity; a linear relationship is also a monotonic relationship. Spearman correlation can be calculated for ordinal, interval and ratio variables.
Spearman correlation calculates the correlation between the ranked variables, not between the values of the variables. In R, you can use the same function to calculate Spearman's correlation coefficient as you used to calculate Pearson's correlation coefficient (cor()
). However, by default the cor()
function calculates the Pearson correlation, if you want to calculate the Spearman correlation you have to specify this with the argument method = 'spearman'
.
cor()
function to calculate the correlation coefficient, don't forget to specify that you want to calculate the Spearman correlation.cor(hybrid$ accelrate, hybrid$ mpg, method = 'spearman')Spearmans # \rho # #= Error in file(filename, "r", encoding = encoding) : cannot open the connection to 'http://horizon.science.uva.nl/public/VVA/hybrid_reg.r' Calls: source -> file In addition: Warning message: In file(filename, "r", encoding = encoding) : cannot open URL 'http://horizon.science.uva.nl/public/VVA/hybrid_reg.r': HTTP status was '404 Not Found' Execution halted#