> data(trees, package="datasets") > summary (trees) Girth Height Volume Min. : 8.30 Min. :63 Min. :10.20 1st Qu.:11.05 1st Qu.:72 1st Qu.:19.40 Median :12.90 Median :76 Median :24.20 Mean :13.25 Mean :76 Mean :30.17 3rd Qu.:15.25 3rd Qu.:80 3rd Qu.:37.30 Max. :20.60 Max. :87 Max. :77.00 > attach (trees) > cor.test (Volume, Height, method = "spearman") Spearman's rank correlation rho data: Volume and Height S = 2089.6, p-value = 0.0006484 alternative hypothesis: true rho is not equal to 0 sample estimates: rho 0.5787101 > cor.test (Volume, Height, method = "kendall") Kendall's rank correlation tau data: Volume and Height z = 3.4971, p-value = 0.0004704 alternative hypothesis: true tau is not equal to 0 sample estimates: tau 0.4496306 > data(ToothGrowth, package="datasets") > wilcox.test(len ~ supp, alternative="two.sided", data=ToothGrowth) Wilcoxon rank sum test with continuity correction data: len by supp W = 575.5, p-value = 0.06449 alternative hypothesis: true location shift is not equal to 0 > data(Burt, package="carData") > summary (Burt) IQbio IQfoster class Min. : 63.00 Min. : 68.0 high : 7 1st Qu.: 84.50 1st Qu.: 83.5 low :14 Median : 94.00 Median : 94.0 medium: 6 Mean : 95.11 Mean : 95.3 3rd Qu.:107.50 3rd Qu.:104.5 Max. :132.00 Max. :131.0 > attach (Burt) > wilcox.test (IQbio, IQfoster, paired=TRUE) Wilcoxon signed rank test with continuity correction data: IQbio and IQfoster V = 152, p-value = 0.7877 alternative hypothesis: true location shift is not equal to 0 > summary (ToothGrowth) len supp dose Min. : 4.20 OJ:30 Min. :0.500 1st Qu.:13.07 VC:30 1st Qu.:0.500 Median :19.25 Median :1.000 Mean :18.81 Mean :1.167 3rd Qu.:25.27 3rd Qu.:2.000 Max. :33.90 Max. :2.000 > ToothGrowth <- within(ToothGrowth, { + dose <- as.factor(dose) + }) > kruskal.test (len ~ dose, ToothGrowth) Kruskal-Wallis rank sum test data: len by dose Kruskal-Wallis chi-squared = 40.669, df = 2, p-value = 0.000000001475 > library(dunn.test, pos=18) > attach (ToothGrowth) > dunn.test (len, dose) Kruskal-Wallis rank sum test data: len and dose Kruskal-Wallis chi-squared = 40.6689, df = 2, p-value = 0 Comparison of len by dose (No adjustment) Col Mean-| Row Mean | 0.5 1 ---------+---------------------- 1 | -3.554911 | 0.0002* | 2 | -6.362611 -2.807700 | 0.0000* 0.0025* alpha = 0.05 Reject Ho if p <= alpha/2 > ####Friedman test > summary (CO2) Plant Type Treatment conc uptake Qn1 : 7 Quebec :42 nonchilled:42 Min. : 95 Min. : 7.70 Qn2 : 7 Mississippi:42 chilled :42 1st Qu.: 175 1st Qu.:17.90 Qn3 : 7 Median : 350 Median :28.30 Qc1 : 7 Mean : 435 Mean :27.21 Qc3 : 7 3rd Qu.: 675 3rd Qu.:37.12 Qc2 : 7 Max. :1000 Max. :45.50 (Other):42 > CO2 <- within(CO2, {conc <- as.factor(conc)}) > summary (CO2) Plant Type Treatment conc uptake Qn1 : 7 Quebec :42 nonchilled:42 95 :12 Min. : 7.70 Qn2 : 7 Mississippi:42 chilled :42 175 :12 1st Qu.:17.90 Qn3 : 7 250 :12 Median :28.30 Qc1 : 7 350 :12 Mean :27.21 Qc3 : 7 500 :12 3rd Qu.:37.12 Qc2 : 7 675 :12 Max. :45.50 (Other):42 1000:12 > CO2 <- within(CO2, {conc <- as.factor(conc)}) > attach (CO2) > friedman.test (uptake ~ conc|Plant) Friedman rank sum test data: uptake and conc and Plant Friedman chi-squared = 59.677, df = 6, p-value = 5.236e-11 #######################SCRIPT#################################### ############## RANK CORRELATIONS data(trees, package="datasets") summary (trees) attach (trees) cor.test (Volume, Height, method = "spearman") cor.test (Volume, Height, method = "kendall") #################TWO SAMPLES COMPARISON data(ToothGrowth, package="datasets") wilcox.test(len ~ supp, alternative="two.sided", data=ToothGrowth) data(Burt, package="carData") summary (Burt) attach (Burt) wilcox.test (IQbio, IQfoster, paired=TRUE) ## nonparametric ANOVA summary (ToothGrowth) ToothGrowth <- within(ToothGrowth, { dose <- as.factor(dose) }) kruskal.test (len ~ dose, ToothGrowth) library(dunn.test, pos=18) attach (ToothGrowth) dunn.test (len, dose) ####Friedman test summary (CO2) CO2 <- within(CO2, {conc <- as.factor(conc)}) attach (CO2) friedman.test (uptake ~ conc|Plant)