###LESSON 5 CORRELATION COEFFICIENT (27/4/2021) library(ISwR) data(thuesen) attach(thuesen) thuesen ### # blood.glucose short.velocity #1 15.3 1.76 #2 10.8 1.34 #3 8.1 1.27 #4 19.5 1.47 #5 7.2 1.27 #6 5.3 1.49 #7 9.3 1.31 #8 11.1 1.09 #9 7.5 1.18 #10 12.2 1.22 #11 6.7 1.25 #12 5.2 1.19 #13 19.0 1.95 #14 15.1 1.28 #15 6.7 1.52 #16 8.6 NA #17 4.2 1.12 #18 10.3 1.37 #19 12.5 1.19 #20 16.1 1.05 #21 13.3 1.32 #22 4.9 1.03 #23 8.8 1.12 #24 9.5 1.70 ###PEARSON CORR. shapiro.test(blood.glucose) shapiro.test(short.velocity) plot(blood.glucose,short.velocity) cor(blood.glucose,short.velocity) cor(blood.glucose,short.velocity,use="complete.obs") #[1] 0.4167546 cor.test(blood.glucose,short.velocity) ##Pearson's correlation #data: blood.glucose and short.velocity #t = 2.101, df = 21, p-value = 0.0479 #alternative hypothesis: true correlation is not equal to 0 #95 percent confidence interval: #0.005496682 0.707429479 #sample estimates: # cor #0.4167546 ###SPEARMAN CORR. cor(blood.glucose,short.velocity,method="spearman") cor(blood.glucose,short.velocity,method="spearman",use="complete.obs") cor.test(blood.glucose,short.velocity,method="spearman") ##Spearman's rank correlation rho #data: blood.glucose and short.velocity #S = 1380.4, p-value = 0.1392 #alternative hypothesis: true rho is not equal to 0 #sample estimates: # rho #0.318002 #Warning message: #In cor.test.default(blood.glucose, short.velocity, method = "spearman") : # Cannot compute exact p-value with ties