########################################################## #############PERMUTATION TESTS############################## > library(survival, pos=21) > library(coin, pos=21) > summary (ToothGrowth) len supp dose Min. : 4.20 OJ:30 0.5:20 1st Qu.:13.07 VC:30 1 :20 Median :19.25 2 :20 Mean :18.81 3rd Qu.:25.27 Max. :33.90 > oneway_test(len ~ supp, data = ToothGrowth, distribution = "approximate") Approximative Two-Sample Fisher-Pitman Permutation Test data: len by supp (OJ, VC) Z = 1.8734, p-value = 0.0609 alternative hypothesis: true mu is not equal to 0 > oneway_test(len ~ dose, data = ToothGrowth, distribution = "approximate") Approximative K-Sample Fisher-Pitman Permutation Test data: len by dose (0.5, 1, 2) chi-squared = 41.469, p-value < 0.0001 > 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 > spearman_test(Volume ~ Height, data = trees, distribution = "approximate") Approximative Spearman Correlation Test data: Volume by Height Z = 3.1697, p-value = 0.0014 alternative hypothesis: true rho is not equal to 0 ######################LINEAR MODELS############### > library(lmPerm, pos=23) > 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 > tree1 <- lmp (Volume ~ Girth + Height, data = trees, perm = "Prob") [1] "Settings: unique SS : numeric variables centered" > summary (tree1) Call: lmp(formula = Volume ~ Girth + Height, data = trees, perm = "Prob") Residuals: Min 1Q Median 3Q Max -6.4065 -2.6493 -0.2876 2.2003 8.4847 Coefficients: Estimate Iter Pr(Prob) Girth 4.7082 5000 <2e-16 *** Height 0.3393 4549 0.0215 * --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 3.882 on 28 degrees of freedom Multiple R-Squared: 0.948, Adjusted R-squared: 0.9442 F-statistic: 255 on 2 and 28 DF, p-value: < 2.2e-16 > data(ToothGrowth, package="datasets") > ToothGrowth <- within(ToothGrowth, { + dose <- as.factor(dose) + }) > summary (ToothGrowth) len supp dose Min. : 4.20 OJ:30 0.5:20 1st Qu.:13.07 VC:30 1 :20 Median :19.25 2 :20 Mean :18.81 3rd Qu.:25.27 Max. :33.90 > gp1 <- aovp (len ~ dose, data = ToothGrowth, perm = "Prob") [1] "Settings: unique SS " > summary (gp1) Component 1 : Df R Sum Sq R Mean Sq Iter Pr(Prob) dose 2 2426.4 1213.2 5000 < 2.2e-16 *** Residuals 57 1025.8 18.0 --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 > library(rcompanion, pos=25) > pairwisePermutationTest (len ~ dose, data = ToothGrowth, method = "fdr") Comparison Stat p.value p.adjust 1 0.5 - 1 = 0 -4.524 0.00000608 0.0000091200 2 0.5 - 2 = 0 -5.535 0.0000000311 0.0000000933 3 1 - 2 = 0 -3.886 0.0001018 0.0001018000 ############################################### ###SCRIPT ########################################################## #############PERMUTATION TESTS############################## library(survival, pos=21) library(coin, pos=21) summary (ToothGrowth) oneway_test(len ~ supp, data = ToothGrowth, distribution = "approximate") oneway_test(len ~ dose, data = ToothGrowth, distribution = "approximate") summary (trees) spearman_test(Volume ~ Height, data = trees, distribution = "approximate") ######################LINEAR MODELS############### library(lmPerm, pos=23) summary (trees) tree1 <- lmp (Volume ~ Girth + Height, data = trees, perm = "Prob") summary (tree1) ToothGrowth <- within(ToothGrowth, { dose <- as.factor(dose) }) summary (ToothGrowth) gp1 <- aovp (len ~ dose, data = ToothGrowth, perm = "Prob") summary (gp1) ###########POST HOC library(rcompanion, pos=25) pairwisePermutationTest (len ~ dose, data = ToothGrowth, method = "fdr")