### Trend Tests Example Data Setup Source: https://cran.r-project.org/web/packages/PMCMRplus/refman/PMCMRplus.html Sets up example data for various trend tests. Ensure factor labels are ordered correctly for dose-response relationships. ```R x <- c(106, 114, 116, 127, 145, 110, 125, 143, 148, 151, 136, 139, 149, 160, 174) g <- gl(3,5) levels(g) <- c("A", "B", "C") ``` -------------------------------- ### Example Data Setup and Multiple Tests Source: https://cran.r-project.org/web/packages/PMCMRplus/refman/PMCMRplus.html Demonstrates setting up sample data and applying various ordered alternative tests like Chacko's, Cuzick's, and Jonckheere-Terpstra. Ensure factor levels are ordered correctly for dose-response. ```R ## Example from Sachs (1997, p. 402) x <- c(106, 114, 116, 127, 145, 110, 125, 143, 148, 151, 136, 139, 149, 160, 174) g <- gl(3,5) levels(g) <- c("A", "B", "C") ## Chacko's test chackoTest(x, g) ## Cuzick's test cuzickTest(x, g) ## Johnson-Mehrotra test johnsonTest(x, g) ## Jonckheere-Terpstra test jonckheereTest(x, g) ## Le's test leTest(x, g) ## Spearman type test spearmanTest(x, g) ## Murakami's BWS trend test bwsTrendTest(x, g) ## Fligner-Wolfe test flignerWolfeTest(x, g) ## Shan-Young-Kang test shanTest(x, g) ``` -------------------------------- ### Example Data Setup and Friedman Test Source: https://cran.r-project.org/web/packages/PMCMRplus/refman/PMCMRplus.html This snippet demonstrates how to set up a data matrix for analysis and perform a Friedman test, which is a precursor to all-pairs comparisons. ```R y <- matrix(c( 3.88, 5.64, 5.76, 4.25, 5.91, 4.33, 30.58, 30.14, 16.92, 23.19, 26.74, 10.91, 25.24, 33.52, 25.45, 18.85, 20.45, 26.67, 4.44, 7.94, 4.04, 4.4, 4.23, 4.36, 29.41, 30.72, 32.92, 28.23, 23.35, 12, 38.87, 33.12, 39.15, 28.06, 38.23, 26.65),nrow=6, ncol=6, dimnames=list(1:6, LETTERS[1:6])) print(y) friedmanTest(y) ``` -------------------------------- ### Data Preparation and Friedman Test Example Source: https://cran.r-project.org/web/packages/PMCMRplus/refman/PMCMRplus.html Demonstrates data setup for a blocked experiment and performs a Friedman test. This is a precursor to all-pairs comparisons. ```R ## Sachs, 1997, p. 675 ## Six persons (block) received six different diuretics ## (A to F, treatment). ## The responses are the Na-concentration (mval) ## in the urine measured 2 hours after each treatment. ## y <- matrix(c( 3.88, 5.64, 5.76, 4.25, 5.91, 4.33, 30.58, 30.14, 16.92, 23.19, 26.74, 10.91, 25.24, 33.52, 26.67, 4.44, 7.94, 4.04, 4.4, 4.23, 4.36, 29.41, 30.72, 32.92, 28.23, 23.35, 12, 38.87, 33.12, 39.15, 28.06, 38.23, 26.65),nrow=6, ncol=6, dimnames=list(1:6, LETTERS[1:6])) print(y) friedmanTest(y) ``` -------------------------------- ### Example Data and Multiple Trend Tests Source: https://cran.r-project.org/web/packages/PMCMRplus/refman/PMCMRplus.html Sets up example data and demonstrates the usage of various trend tests, including Murakami's BWS Trend Test. ```R ## Example from Sachs (1997, p. 402) x <- c(106, 114, 116, 127, 145, 110, 125, 143, 148, 151, 136, 139, 149, 160, 174) g <- gl(3,5) levels(g) <- c("A", "B", "C") ## Chacko's test chackoTest(x, g) ## Cuzick's test cuzickTest(x, g) ## Johnson-Mehrotra test johnsonTest(x, g) ## Jonckheere-Terpstra test jonckheereTest(x, g) ## Le's test leTest(x, g) ## Spearman type test spearmanTest(x, g) ## Murakami's BWS trend test bwsTrendTest(x, g) ## Fligner-Wolfe test flignerWolfeTest(x, g) ## Shan-Young-Kang test shanTest(x, g) ``` -------------------------------- ### Install PMCMRplus on Windows Source: https://cran.r-project.org/web/packages/PMCMRplus/readme/README.html Use this command to install the PMCMRplus package and its dependencies from CRAN on Windows systems. ```r install.packages("PMCMRplus") ``` -------------------------------- ### Install PMCMRplus using Binary Packages on Ubuntu Source: https://cran.r-project.org/web/packages/PMCMRplus/readme/README.html Command to install the PMCMRplus R package using precompiled binary deb packages on Ubuntu, provided the CRAN2deb4ubuntu PPA is added. ```bash sudo apt-get install r-cran-pmcmrplus ``` -------------------------------- ### Example Usage of qcochran Source: https://cran.r-project.org/web/packages/PMCMRplus/refman/PMCMRplus.html Demonstrates how to use the qcochran function to find a specific quantile. ```R qcochran(0.05, 7, 3) ``` -------------------------------- ### Example usage of qmandelk Source: https://cran.r-project.org/web/packages/PMCMRplus/refman/PMCMRplus.html Example of calculating an upper-tail quantile for Mandel's k distribution with specified parameters. ```R qmandelk(0.005, 7, 3, lower.tail=FALSE) ``` -------------------------------- ### Example Usage of pdgrubbs Source: https://cran.r-project.org/web/packages/PMCMRplus/refman/PMCMRplus.html Demonstrates how to use the pdgrubbs function to calculate a probability. ```R pdgrubbs(0.62, 7, 1E4) ``` -------------------------------- ### Data Preparation and Friedman Test Example Source: https://cran.r-project.org/web/packages/PMCMRplus/refman/PMCMRplus.html Demonstrates how to create a matrix for response data and perform a Friedman test. This is often a precursor to post-hoc multiple comparisons. ```R ## Sachs, 1997, p. 675 ## Six persons (block) received six different diuretics ## (A to F, treatment). ## The responses are the Na-concentration (mval) ## in the urine measured 2 hours after each treatment. ## y <- matrix(c( 3.88, 5.64, 5.76, 4.25, 5.91, 4.33, 30.58, 30.14, 16.92, 23.19, 26.74, 10.91, 25.24, 33.52, 25.45, 18.85, 20.45, 26.67, 4.44, 7.94, 4.04, 4.4, 4.23, 4.36, 29.41, 30.72, 32.92, 28.23, 23.35, 12, 38.87, 33.12, 39.15, 28.06, 38.23, 26.65),nrow=6, ncol=6, dimnames=list(1:6, LETTERS[1:6])) print(y) friedmanTest(y) ``` -------------------------------- ### Install/Update PMCMRplus from Source on Linux Source: https://cran.r-project.org/web/packages/PMCMRplus/readme/README.html Commands to update or install the PMCMRplus package from source on Linux systems. Ensure external libraries like libgmp and libmpfr are installed first if compilation errors occur. ```r # update PMCMRplus update.packages("PMCMRplus") ``` ```r # or install install.packages("PMCMRplus") ``` -------------------------------- ### Example: Dunnett Quantile and Distribution Source: https://cran.r-project.org/web/packages/PMCMRplus/refman/PMCMRplus.html Demonstrates the usage of qDunnett and pDunnett for calculating quantiles and p-values for Dunnett's test with specified parameters. Note the use of set.seed for reproducibility. ```R ## Table gives 2.34 for df = 6, m = 2, one-sided set.seed(112) qval <- qDunnett(p = 0.05, n0 = 3, n = rep(3,2)) round(qval, 2) set.seed(112) pDunnett(qval, n0=3, n = rep(3,2), lower.tail = FALSE) ``` ```R ## Table gives 2.65 for df = 20, m = 4, two-sided set.seed(112) qval <- qDunnett(p = 0.05/2, n0 = 5, n = rep(5,4)) round(qval, 2) set.seed(112) 2 * pDunnett(qval, n0= 5, n = rep(5,4), lower.tail= FALSE) ``` -------------------------------- ### Data Setup and Basic Tests in PMCMRplus Source: https://cran.r-project.org/web/packages/PMCMRplus/refman/PMCMRplus.html Initializes a matrix for Na-concentration data and performs Friedman's test and Skillings-Mack test. Ensure data is correctly formatted as a matrix. ```R y <- matrix(c( 3.88, 5.64, 5.76, 4.25, 5.91, 4.33, 30.58, 30.14, 16.92, 23.19, 26.74, 10.91, 25.24, 33.52, 25.45, 18.85, 20.45, 26.67, 4.44, 7.94, 4.04, 4.4, 4.23, 4.36, 29.41, 30.72, 32.92, 28.23, 23.35, 12, 38.87, 33.12, 39.15, 28.06, 38.23, 26.65),nrow=6, ncol=6, dimnames=list(1:6, LETTERS[1:6])) print(y) friedmanTest(y) skillingsMackTest(y) ``` -------------------------------- ### Data Preparation and Multiple Tests in PMCMRplus Source: https://cran.r-project.org/web/packages/PMCMRplus/refman/PMCMRplus.html This example demonstrates how to prepare data and apply several non-parametric tests from the PMCMRplus package, including the global Friedman test, Demsar's many-one test, Exact many-one test, Nemenyi's many-one test, and the House test. It assumes 'A' is the control group. ```R y <- matrix(c( 3.88, 5.64, 5.76, 4.25, 5.91, 4.33, 30.58, 30.14, 16.92, 23.19, 26.74, 10.91, 25.24, 33.52, 25.45, 18.85, 20.45, 26.67, 4.44, 7.94, 4.04, 4.4, 4.23, 4.36, 29.41, 30.72, 32.92, 28.23, 23.35, 12, 38.87, 33.12, 39.15, 28.06, 38.23, 26.65),nrow=6, ncol=6, dimnames=list(1:6, LETTERS[1:6])) ## Global Friedman test friedmanTest(y) ## Demsar's many-one test summary(frdManyOneDemsarTest(y=y, p.adjust = "bonferroni", alternative = "greater")) ## Exact many-one test summary(frdManyOneExactTest(y=y, p.adjust = "bonferroni", alternative = "greater")) ## Nemenyi's many-one test summary(frdManyOneNemenyiTest(y=y, alternative = "greater")) ## House test frdHouseTest(y, alternative = "greater") ``` -------------------------------- ### Check/Install GMP and MPFR Development Libraries on Ubuntu/Debian Source: https://cran.r-project.org/web/packages/PMCMRplus/readme/README.html Commands to check for and install the GMP and MPFR development header files required for compiling R packages on Ubuntu and Debian-based systems. ```bash dpkg -p libgmp-dev ``` ```bash dpkg -p libmpfr-dev ``` ```bash sudo apt-get install libgmp-dev ``` ```bash sudo apt-get install libmpfr-dev ``` -------------------------------- ### Example Data for Quade's Test Source: https://cran.r-project.org/web/packages/PMCMRplus/refman/PMCMRplus.html Sets up a matrix of Na-concentration data for six persons receiving six different diuretics, used for demonstrating Quade's test. ```R y <- matrix(c( 3.88, 5.64, 5.76, 4.25, 5.91, 4.33, 30.58, 30.14, 16.92, 23.19, 26.74, 10.91, 25.24, 33.52, 25.45, 18.85, 20.45, 26.67, 4.44, 7.94, 4.04, 4.4, 4.23, 4.36, 29.41, 30.72, 32.92, 28.23, 23.35, 12, 38.87, 33.12, 39.15, 28.06, 38.23, 26.65),nrow=6, ncol=6, dimnames=list(1:6, LETTERS[1:6])) print(y) ``` -------------------------------- ### Perform AD-Test, BWS-Test, Kruskal-Test, and Median Test Source: https://cran.r-project.org/web/packages/PMCMRplus/refman/PMCMRplus.html Demonstrates how to perform several statistical tests using sample data. Includes examples for Anderson-Darling, Bickel-Rosenberg-Schach, Kruskal-Wallis (with different distribution approximations), and Median tests. Also shows how to compare results with base R functions. ```R x <- c(2.9, 3.0, 2.5, 2.6, 3.2) # normal subjects y <- c(3.8, 2.7, 4.0, 2.4) # with obstructive airway disease z <- c(2.8, 3.4, 3.7, 2.2, 2.0) # with asbestosis g <- factor(x = c(rep(1, length(x)), rep(2, length(y)), rep(3, length(z))), labels = c("ns", "oad", "a")) dat <- data.frame( g = g, x = c(x, y, z)) ## AD-Test adKSampleTest(x ~ g, data = dat) ## BWS-Test bwsKSampleTest(x ~ g, data = dat) ## Kruskal-Test ## Using incomplete beta approximation kruskalTest(x ~ g, dat, dist="KruskalWallis") ## Using chisquare distribution kruskalTest(x ~ g, dat, dist="Chisquare") ## Not run: ## Check with kruskal.test from R stats kruskal.test(x ~ g, dat) ## End(Not run) ## Using Conover's F kruskalTest(x ~ g, dat, dist="FDist") ## Not run: ## Check with aov on ranks anova(aov(rank(x) ~ g, dat)) ## Check with oneway.test oneway.test(rank(x) ~ g, dat, var.equal = TRUE) ## End(Not run) ## Median Test asymptotic medianTest(x ~ g, dat) ## Median Test with simulated p-values set.seed(112) medianTest(x ~ g, dat, simulate.p.value = TRUE) ``` -------------------------------- ### K-Sample Rank Test Examples Source: https://cran.r-project.org/web/packages/PMCMRplus/refman/PMCMRplus.html Demonstrates the usage of k-sample rank tests including AD-Test, BWS-Test, Kruskal-Test, and Median Test with different distribution assumptions and simulation options. ```R ## Hollander & Wolfe (1973), 116. ## Mucociliary efficiency from the rate of removal of dust in normal ## subjects, subjects with obstructive airway disease, and subjects ## with asbestosis. x <- c(2.9, 3.0, 2.5, 2.6, 3.2) # normal subjects y <- c(3.8, 2.7, 4.0, 2.4) # with obstructive airway disease z <- c(2.8, 3.4, 3.7, 2.2, 2.0) # with asbestosis g <- factor(x = c(rep(1, length(x)), rep(2, length(y)), rep(3, length(z))), labels = c("ns", "oad", "a")) dat <- data.frame( g = g, x = c(x, y, z)) ## AD-Test adKSampleTest(x ~ g, data = dat) ## BWS-Test bwsKSampleTest(x ~ g, data = dat) ## Kruskal-Test ## Using incomplete beta approximation kruskalTest(x ~ g, dat, dist="KruskalWallis") ## Using chisquare distribution kruskalTest(x ~ g, dat, dist="Chisquare") ## Not run: ## Check with kruskal.test from R stats kruskal.test(x ~ g, dat) ## End(Not run) ## Using Conover's F kruskalTest(x ~ g, dat, dist="FDist") ## Not run: ## Check with aov on ranks anova(aov(rank(x) ~ g, dat)) ## Check with oneway.test oneway.test(rank(x) ~ g, dat, var.equal = TRUE) ## End(Not run) ## Median Test asymptotic medianTest(x ~ g, dat) ## Median Test with simulated p-values set.seed(112) medianTest(x ~ g, dat, simulate.p.value = TRUE) ``` -------------------------------- ### Shirley's Williams Test Example Source: https://cran.r-project.org/web/packages/PMCMRplus/refman/PMCMRplus.html Demonstrates Shirley's one-sided test using a look-up table for reaction times of mice. ```R ## Example from Shirley (1977) ## Reaction times of mice to stimuli to their tails. x <- c(2.4, 3, 3, 2.2, 2.2, 2.2, 2.2, 2.8, 2, 3, 2.8, 2.2, 3.8, 9.4, 8.4, 3, 3.2, 4.4, 3.2, 7.4, 9.8, 3.2, 5.8, 7.8, 2.6, 2.2, 6.2, 9.4, 7.8, 3.4, 7, 9.8, 9.4, 8.8, 8.8, 3.4, 9, 8.4, 2.4, 7.8) g <- gl(4, 10) ## Shirley's test ## one-sided test using look-up table shirleyWilliamsTest(x ~ g, alternative = "greater") ``` -------------------------------- ### Steel's Test Example (Sachs) Source: https://cran.r-project.org/web/packages/PMCMRplus/refman/PMCMRplus.html Demonstrates Steel's test for comparing multiple groups against a control, using data from Sachs (1997). Requires the kSamples package. ```R x <- c(106, 114, 116, 127, 145, 110, 125, 143, 148, 151, 136, 139, 149, 160, 174) g <- gl(3,5) levels(g) <- c("0", "I", "II") ## Steel's Test steelsKSampleTest(x ~ g, alternative = "greater") ``` -------------------------------- ### Check/Install GMP and MPFR Development Libraries on Fedora/Redhat Source: https://cran.r-project.org/web/packages/PMCMRplus/readme/README.html Commands to check for and install the GMP and MPFR development header files required for compiling R packages on Fedora, Redhat, CentOS, and similar distributions. ```bash dnf info gmp-devel ``` ```bash dnf info mpfr-devel ``` ```bash sudo dnf install gmp-devel ``` ```bash sudo dnf install mpfr-devel ``` -------------------------------- ### Kruskal-Wallis Test Examples Source: https://cran.r-project.org/web/packages/PMCMRplus/refman/PMCMRplus.html Demonstrates the usage of the kruskalTest function with different p-value distribution options. Includes checks against base R functions for verification. ```R ## Hollander & Wolfe (1973), 116. ## Mucociliary efficiency from the rate of removal of dust in normal ## subjects, subjects with obstructive airway disease, and subjects ## with asbestosis. x <- c(2.9, 3.0, 2.5, 2.6, 3.2) # normal subjects y <- c(3.8, 2.7, 4.0, 2.4) # with obstructive airway disease z <- c(2.8, 3.4, 3.7, 2.2, 2.0) # with asbestosis g <- factor(x = c(rep(1, length(x)), rep(2, length(y)), rep(3, length(z))), labels = c("ns", "oad", "a")) dat <- data.frame( g = g, x = c(x, y, z)) ## AD-Test adKSampleTest(x ~ g, data = dat) ## BWS-Test bwsKSampleTest(x ~ g, data = dat) ## Kruskal-Test ## Using incomplete beta approximation kruskalTest(x ~ g, dat, dist="KruskalWallis") ## Using chisquare distribution kruskalTest(x ~ g, dat, dist="Chisquare") ## Not run: ## Check with kruskal.test from R stats kruskal.test(x ~ g, dat) ## End(Not run) ## Using Conover's F kruskalTest(x ~ g, dat, dist="FDist") ## Not run: ## Check with aov on ranks anova(aov(rank(x) ~ g, dat)) ## Check with oneway.test oneway.test(rank(x) ~ g, dat, var.equal = TRUE) ## End(Not run) ## Median Test asymptotic medianTest(x ~ g, dat) ## Median Test with simulated p-values set.seed(112) medianTest(x ~ g, dat, simulate.p.value = TRUE) ``` -------------------------------- ### Friedman Test and Post-Hoc Tests in R Source: https://cran.r-project.org/web/packages/PMCMRplus/refman/PMCMRplus.html Demonstrates the usage of friedmanTest and various post-hoc all-pairs comparison tests for a matrix of data. Includes examples for exact tests, Conover's, Nemenyi's, Miller's, Siegel-Castellan's, and Nemenyi's test using a formula interface. ```R ## Sachs, 1997, p. 675 ## Six persons (block) received six different diuretics ## (A to F, treatment). ## The responses are the Na-concentration (mval) ## in the urine measured 2 hours after each treatment. ## y <- matrix(c( 3.88, 5.64, 5.76, 4.25, 5.91, 4.33, 30.58, 30.14, 16.92, 23.19, 26.74, 10.91, 25.24, 33.52, 25.45, 18.85, 20.45, 26.67, 4.44, 4.04, 4.4, 4.23, 4.36, 29.41, 30.72, 32.92, 28.23, 23.35, 12, 38.87, 33.12, 39.15, 28.06, 38.23, 26.65),nrow=6, ncol=6, dimnames=list(1:6, LETTERS[1:6])) print(y) friedmanTest(y) ## Eisinga et al. 2017 frdAllPairsExactTest(y=y, p.adjust = "bonferroni") ## Conover's test frdAllPairsConoverTest(y=y, p.adjust = "bonferroni") ## Nemenyi's test frdAllPairsNemenyiTest(y=y) ## Miller et al. frdAllPairsMillerTest(y=y) ## Siegel-Castellan frdAllPairsSiegelTest(y=y, p.adjust = "bonferroni") ## Irrelevant of group order? x <- as.vector(y) g <- rep(colnames(y), each = length(x)/length(colnames(y))) b <- rep(rownames(y), times = length(x)/length(rownames(y))) xDF <- data.frame(x, g, b) # grouped by colnames frdAllPairsNemenyiTest(xDF$x, groups = xDF$g, blocks = xDF$b) o <- order(xDF$b) # order per block increasingly frdAllPairsNemenyiTest(xDF$x[o], groups = xDF$g[o], blocks = xDF$b[o]) o <- order(xDF$x) # order per value increasingly frdAllPairsNemenyiTest(xDF$x[o], groups = xDF$g[o], blocks = xDF$b[o]) ## formula method (only works for Nemenyi) frdAllPairsNemenyiTest(x ~ g | b, data = xDF) ``` -------------------------------- ### Williams Test Example Source: https://cran.r-project.org/web/packages/PMCMRplus/refman/PMCMRplus.html Demonstrates the application of Williams' test for comparing treatment means against a zero dose control. Requires data and a factor defining treatment groups. ```R ## Example from Sachs (1997, p. 402) x <- c(106, 114, 116, 127, 145, 110, 125, 143, 148, 151, 136, 139, 149, 160, 174) g <- gl(3,5) levels(g) <- c("0", "I", "II") ## Williams Test williamsTest(x ~ g) ``` -------------------------------- ### Anderson-Darling All-Pairs Test Example Source: https://cran.r-project.org/web/packages/PMCMRplus/refman/PMCMRplus.html Performs the Anderson-Darling all-pairs comparison test using a formula interface. The p-value adjustment method is set to 'holm'. ```R out <- adAllPairsTest(count ~ spray, InsectSprays, p.adjust="holm") summary(out) summaryGroup(out) ``` -------------------------------- ### Check Kruskal-Test with R's kruskal.test Source: https://cran.r-project.org/web/packages/PMCMRplus/refman/PMCMRplus.html This example demonstrates how to verify the results of kruskalTest against the standard kruskal.test function from the R stats package. It is commented out with '## Not run:' and should be executed manually if needed. ```R ## Check with kruskal.test from R stats kruskal.test(x ~ g, dat) ``` -------------------------------- ### Comparing Power Estimation for One-Way ANOVA Source: https://cran.r-project.org/web/packages/PMCMRplus/refman/PMCMRplus.html Compares power estimation for one-way ANOVA using R's built-in functions and the PMCMRplus package. This example demonstrates how to calculate necessary parameters like Cohen's f and R-squared for comparison. ```R groupmeans <- c(120, 130, 140, 150) SEsq <- 500 # within-variance n <- 10 k <- length(groupmeans) df <- n * k - k SSQ.E <- SEsq * df SSQ.A <- n * var(groupmeans) * (k - 1) sd.errfn <- sqrt(SSQ.E / (n * k - 1)) R2 <- c("R-squared" = SSQ.A / (SSQ.A + SSQ.E)) cohensf <- sqrt(R2 / (1 - R2)) names(cohensf) <- "Cohens f" ## R stats power function power.anova.test(groups = k, between.var = var(groupmeans), within.var = SEsq, n = n) ## pwr power function pwr.anova.test(k = k, n = n, f = cohensf, sig.level=0.05) ``` -------------------------------- ### Check Kruskal-Test with aov on ranks Source: https://cran.r-project.org/web/packages/PMCMRplus/refman/PMCMRplus.html This example shows how to compare the Kruskal-Test results with an ANOVA performed on the ranks of the data. It is part of a 'Not run' block and requires manual execution. ```R ## Check with aov on ranks anova(aov(rank(x) ~ g, dat)) ``` -------------------------------- ### Chen's Test Example with Default p-value Adjustment Source: https://cran.r-project.org/web/packages/PMCMRplus/refman/PMCMRplus.html Demonstrates the usage of chenJanTest for analyzing dose-response data with the default p-value adjustment method. This is useful for identifying the minimum effective dose in experiments. ```R y <- c(0.2, 6.2, 0.3, 0.3, 4.9, 1.8, 3.9, 2, 0.3, 2.5, 5.4, 2.3, 12.7, -0.2, 2.1, 6, 1.8, 3.9, 1.1, 3.8, 2.5, 1.3, -0.8, 13.1, 1.1, 12.8, 18.2, 3.4, 13.5, 4.4, 6.1, 2.8, 4, 10.6, 9, 4.2, 6.7, 35, 9, 12.9, 2, 7.1, 1.5, 10.6) groups <- gl(4,11, labels = c("0", "0.25", "0.5", "1.0")) blocks <- structure(rep(1:11, 4), class = "factor", levels = c("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11")) summary(chenJanTest(y, groups, blocks, alternative = "greater")) ``` -------------------------------- ### Grubbs Double Outlier Test Example Source: https://cran.r-project.org/web/packages/PMCMRplus/refman/PMCMRplus.html Example of performing Grubbs double outlier test on a subset of Pentosan data, testing for a 'less' alternative hypothesis. ```R data(Pentosan) labMeans <- tapply(dat$value, dat$lab, mean) doubleGrubbsTest(x = labMeans, alternative = "less") ``` -------------------------------- ### Update PMCMRplus or All Packages Source: https://cran.r-project.org/web/packages/PMCMRplus/readme/README.html Commands to update the PMCMRplus package specifically or all installed R packages. ```r # update PMCMRplus update.packages("PMCMRplus") ``` ```r # or update all update.packages() ``` -------------------------------- ### Shirley-Williams Test Example Source: https://cran.r-project.org/web/packages/PMCMRplus/refman/PMCMRplus.html Performs a one-sided Shirley-Williams test using a lookup table. Requires a formula interface for data and group specification. ```R x <- c(2.4, 3, 3, 2.2, 2.2, 2.2, 2.2, 2.8, 2, 3, 2.8, 2.2, 3.8, 9.4, 8.4, 3, 3.2, 4.4, 3.2, 7.4, 9.8, 3.2, 5.8, 7.8, 2.6, 2.2, 6.2, 9.4, 7.8, 3.4, 7, 9.8, 9.4, 8.8, 8.8, 3.4, 9, 8.4, 2.4, 7.8) g <- gl(4, 10) shirleyWilliamsTest(x ~ g, alternative = "greater") ``` -------------------------------- ### Compare with BWStest Package Implementation (Less Alternative) Source: https://cran.r-project.org/web/packages/PMCMRplus/refman/PMCMRplus.html Compares the 'less' alternative hypothesis result with the implementation in the BWStest package. ```R BWStest::bws_test(x=x[g==1], y=x[g==2], alternative = "less") ``` -------------------------------- ### Tamhane-Dunnett Test Example with ANOVA Object Source: https://cran.r-project.org/web/packages/PMCMRplus/refman/PMCMRplus.html Performs Tamhane-Dunnett's test on residuals from an ANOVA model. Assumes data is normally distributed with unequal variances. ```R set.seed(245) mn <- c(1, 2, 2^2, 2^3, 2^4) x <- rep(mn, each=5) + rnorm(25) g <- factor(rep(1:5, each=5)) fit <- aov(x ~ g - 1) shapiro.test(residuals(fit)) bartlett.test(x ~ g - 1) anova(fit) ## works with object of class aov summary(tamhaneDunnettTest(fit, alternative = "greater")) ``` -------------------------------- ### Nemenyi's All-Pairs Test Source: https://cran.r-project.org/web/packages/PMCMRplus/refman/PMCMRplus.html Performs Nemenyi's all-pairs comparison test for Friedman rank sums. No specific p-value adjustment is shown in this example. ```R ## Nemenyi's test frdAllPairsNemenyiTest(y=y) ``` -------------------------------- ### Ordered Alternatives Tests in R Source: https://cran.r-project.org/web/packages/PMCMRplus/refman/PMCMRplus.html Demonstrates various tests for ordered alternatives using sample data. Ensure factor labels for 'g' are ordered increasingly from zero-dose control to the highest dose level. ```r x <- c(106, 114, 116, 127, 145, 110, 125, 143, 148, 151, 136, 139, 149, 160, 174) g <- gl(3,5) levels(g) <- c("A", "B", "C") ## Chacko's test chackoTest(x, g) ## Cuzick's test cuzickTest(x, g) ## Johnson-Mehrotra test johnsonTest(x, g) ## Jonckheere-Terpstra test jonckheereTest(x, g) ## Le's test leTest(x, g) ## Spearman type test spearmanTest(x, g) ## Murakami's BWS trend test bwsTrendTest(x, g) ## Fligner-Wolfe test flignerWolfeTest(x, g) ## Shan-Young-Kang test shanTest(x, g) ``` -------------------------------- ### Compare with BWStest Package Implementation (Greater Alternative) Source: https://cran.r-project.org/web/packages/PMCMRplus/refman/PMCMRplus.html Compares the 'greater' alternative hypothesis result with the implementation in the BWStest package. ```R BWStest::bws_test(x=x[g==1], y=x[g==2], alternative = "greater") ``` -------------------------------- ### Data Preparation and Global Friedman Test Source: https://cran.r-project.org/web/packages/PMCMRplus/refman/PMCMRplus.html Prepares sample data in a matrix format and performs a global Friedman test. This is a foundational step before conducting pairwise comparisons. ```R y <- matrix(c( 3.88, 5.64, 5.76, 4.25, 5.91, 4.33, 30.58, 30.14, 16.92, 23.19, 26.74, 10.91, 25.24, 33.52, 25.45, 18.85, 20.45, 26.67, 4.44, 7.94, 4.04, 4.4, 4.23, 4.36, 29.41, 30.72, 32.92, 28.23, 23.35, 12, 38.87, 33.12, 39.15, 28.06, 38.23, 26.65),nrow=6, ncol=6, dimnames=list(1:6, LETTERS[1:6])) ## Global Friedman test friedmanTest(y) ``` -------------------------------- ### Perform Dunn's All-Pairs Comparison Test Source: https://cran.r-project.org/web/packages/PMCMRplus/refman/PMCMRplus.html Conduct Dunn's all-pairs comparison test with Dunn's original Bonferroni p-adjustment method using kwAllPairsDunnTest. ```R ## Dunn's all-pairs comparison test ans <- kwAllPairsDunnTest(count ~ spray, data = InsectSprays, p.adjust.method = "bonferroni") summary(ans) ``` -------------------------------- ### Perform Grubbs Outlier Test Source: https://cran.r-project.org/web/packages/PMCMRplus/refman/PMCMRplus.html This snippet shows how to perform Grubbs' single outlier test on a numeric vector. Ensure the data is pre-processed as needed, for example, by calculating group means. ```R data(Pentosan) dat <- subset(Pentosan, subset = (material == "A")) labMeans <- tapply(dat$value, dat$lab, mean) grubbsTest(x = labMeans, alternative = "two.sided") ``` -------------------------------- ### Compare Friedman Test with friedman.test Source: https://cran.r-project.org/web/packages/PMCMRplus/refman/PMCMRplus.html Compares the results of the `friedmanTest` function with the base R `friedman.test` function for verification. ```R ## check with friedman.test from R stats friedman.test(RoundingTimes) ``` -------------------------------- ### Chen's Test Example with SD1 p-value Adjustment Source: https://cran.r-project.org/web/packages/PMCMRplus/refman/PMCMRplus.html Illustrates using chenJanTest with the 'SD1' p-value adjustment method, which is specifically designed for accounting for alpha-error inflation in dose-response trend tests. ```R summary(chenJanTest(y, groups, blocks, alternative = "greater", p.adjust = "SD1")) ``` -------------------------------- ### NPMTest: All-Pairs Comparisons for Simply Ordered Mean Ranksums Source: https://cran.r-project.org/web/packages/PMCMRplus/refman/PMCMRplus.html Performs Nashimoto and Wright's all-pairs comparison procedure for simply ordered mean ranksums. Supports different methods including look-up, bootstrap, and asymptotic tests. ```APIDOC ## All-Pairs Comparisons for Simply Ordered Mean Ranksums ### Description Performs Nashimoto and Wright's all-pairs comparison procedure for simply ordered mean ranksums. ### Usage ```R NPMTest(x, ...) ## Default S3 method: NPMTest(x, g, alternative = c("greater", "less"), method = c("look-up", "boot", "asympt"), nperm = 10000, ...) ## S3 method for class 'formula' NPMTest(formula, data, subset, na.action, alternative = c("greater", "less"), method = c("look-up", "boot", "asympt"), nperm = 10000, ...) ``` ### Arguments `x` | a numeric vector of data values, or a list of numeric data vectors. `g` | a vector or factor object giving the group for the corresponding elements of `"x"`. Ignored with a warning if `"x"` is a list. `alternative` | the alternative hypothesis. Defaults to `greater`. `method` | a character string specifying the test statistic to use. Defaults to `"look-up"` that uses published Table values of Williams (1972). `nperm` | number of permutations for the asymptotic permutation test. Defaults to `1000`. Ignored, if `method = "look-up"`. `formula` | a formula of the form `response ~ group` where `response` gives the data values and `group` a vector or factor of the corresponding groups. `data` | an optional matrix or data frame (or similar: see `model.frame`) containing the variables in the formula `formula`. By default the variables are taken from `environment(formula)`. `subset` | an optional vector specifying a subset of observations to be used. `na.action` | a function which indicates what should happen when the data contain `NA`s. Defaults to `getOption("na.action")`. `...` | further arguments to be passed to or from methods. ``` -------------------------------- ### S3 Method for Formula Interface of steelsKSampleTest Source: https://cran.r-project.org/web/packages/PMCMRplus/refman/PMCMRplus.html S3 method for steelsKSampleTest using a formula interface. Allows specifying response, group, and optional arguments like subset and na.action. ```R steelsKSampleTest( formula, data, subset, na.action, alternative = c("two.sided", "greater", "less"), ... ) ``` -------------------------------- ### Fit ANOVA Model for Scheffe's Test Source: https://cran.r-project.org/web/packages/PMCMRplus/refman/PMCMRplus.html Fit an ANOVA model using aov() before applying Scheffe's test. This example uses the 'chickwts' dataset to model 'weight' based on 'feed'. ```R fit <- aov(weight ~ feed, chickwts) shapiro.test(residuals(fit)) bartlett.test(weight ~ feed, chickwts) anova(fit) ``` -------------------------------- ### hsAllPairsTest Formula Method Signature Source: https://cran.r-project.org/web/packages/PMCMRplus/refman/PMCMRplus.html Illustrates the S3 method for hsAllPairsTest when using a formula interface, specifying formula, data, and subset arguments. ```R ## S3 method for class 'formula': hsAllPairsTest( formula, data, subset, na.action, alternative = c("greater", "less"), method = c("look-up", "boot", "asympt"), nperm = 10000, ... ) ``` -------------------------------- ### Steel's Test Example (USEPA) Source: https://cran.r-project.org/web/packages/PMCMRplus/refman/PMCMRplus.html Applies Steel's test to reproduction data from a Ceriodaphnia dubia chronic test, excluding a specific dose level. Useful for identifying No Observed Effect Concentrations (NOEC). ```R x <- c(20, 26, 26, 23, 24, 27, 26, 23, 27, 24, 13, 15, 14, 13, 23, 26, 0, 25, 26, 27, 18, 22, 13, 13, 23, 22, 20, 22, 23, 22, 14, 22, 20, 23, 20, 23, 25, 24, 25, 21, 9, 0, 9, 7, 6, 10, 12, 14, 9, 13, rep(0,10)) g <- gl(6, 10) levels(g) <- c("Control", "3%", "6%", "12%", "25%", "50%") ## NOEC at 3%, LOEC at 6% steelsKSampleTest(x ~ g, subset = g != "50%", alternative = "less") ``` -------------------------------- ### leTest Source: https://cran.r-project.org/web/packages/PMCMRplus/refman/PMCMRplus.html Performs Le's test for ordered alternatives. ```APIDOC ## leTest ### Description Performs Le's test for ordered alternatives. ### Usage ```R leTest(x, g, ...) ``` ### Arguments * `x`: A numeric vector of data values. * `g`: A vector or factor object giving the group for the corresponding elements of `x`. * `...`: Further arguments to be passed to or from methods. ``` -------------------------------- ### ChaAllPairsNashimotoTest with Default and H-distribution Source: https://cran.r-project.org/web/packages/PMCMRplus/refman/PMCMRplus.html Compares ChaAllPairsNashimotoTest with default standard normal distribution and with h-distribution for post-hoc testing. ```R ## post-hoc test, default is standard normal distribution (NPT'-test) summary(chaAllPairsNashimotoTest(x, g, p.adjust.method = "none")) ## same but h-distribution (NPY'-test) chaAllPairsNashimotoTest(x, g, dist = "h") ``` -------------------------------- ### Nemenyi's All-Pairs Rank Comparison Test - Default Method Source: https://cran.r-project.org/web/packages/PMCMRplus/refman/PMCMRplus.html The default S3 method for kwAllPairsNemenyiTest takes a numeric vector and a grouping vector. The 'dist' argument specifies the distribution for p-value calculation. ```R ## Default S3 method: kwAllPairsNemenyiTest(x, g, dist = c("Tukey", "Chisquare"), ...) ``` -------------------------------- ### Perform Median Test with asymptotic distribution Source: https://cran.r-project.org/web/packages/PMCMRplus/refman/PMCMRplus.html Conducts a Median Test using asymptotic distribution. This is suitable for general use when sample sizes are adequate. ```R medianTest(x ~ g, dat) ```