Learn R Programming

⚠️There's a newer version (1.2.7) of this package.Take me there.

LearnNonparam

Overview

This R package implements several non-parametric tests in chapters 1-5 of Higgins (2004).

It depends on R6 for object oriented design and Rcpp for integration of R and C++.

Installation

For the latest bug fixes and improvements, please install the development version of this R package using

# install.packages("remotes")
remotes::install_github("qddyy/LearnNonparam")

Feedback and contributions are welcome. Please feel free to report bugs or request new features by opening an issue.

Usage

library(LearnNonparam)
options(LearnNonparam.pmt_progress = TRUE)
  • Construct a test object

    • from some R6 class directly
    t <- Wilcoxon$new(n_permu = 1e6)
    • using the pmt (permutation test) wrapper
    # recommended for a unified API
    t <- pmt("twosample.wilcoxon", n_permu = 1e6)
  • Provide it with samples

    set.seed(-1)
    
    t$test(rnorm(10, 1), rnorm(10, 0))
  • Check the results

    t$statistic
    t$p_value
    options(digits = 3)
    
    t$print()
    ggplot2::theme_set(ggplot2::theme_minimal())
    
    t$plot(style = "ggplot2", binwidth = 1)
  • Modify some settings and observe the change

    t$type <- "asymp"
    t$p_value
keyclasstest
onesample.quantileQuantileQuantile Test
onesample.cdfCDFInference on Cumulative Distribution Function
twosample.differenceDifferenceTwo-Sample Test Based on Mean or Median
twosample.wilcoxonWilcoxonTwo-Sample Wilcoxon Test
twosample.scoresumScoreSumTwo-Sample Test Based on Sum of Scores
twosample.ansariAnsariBradleyAnsari-Bradley Test
twosample.siegelSiegelTukeySiegel-Tukey Test
twosample.rmdRatioMeanDevianceRatio Mean Deviance Test
twosample.ksKolmogorovSmirnovTwo-Sample Kolmogorov-Smirnov Test
ksample.onewayOneWayOne-Way Test for Equal Means
ksample.kwKruskalWallisKruskal-Wallis Test
ksample.jtJonckheereTerpstraJonckheere-Terpstra Test
multcomp.studentizedStudentizedMultiple Comparison Based on Studentized Statistic
paired.signSignTwo-Sample Sign Test
paired.differencePairedDifferencePaired Comparison Based on Differences
rcbd.onewayRCBDOneWayOne-Way Test for Equal Means in RCBD
rcbd.friedmanFriedmanFriedman Test
rcbd.pagePagePage Test
association.corrCorrelationTest for Association Between Paired Samples
table.chisqChiSquareChi-Square Test on Contingency Table

define_pmt allows users to define new permutation tests. Take the two-sample Cramér-Von Mises test as an example:

t <- define_pmt(
    # this is a two-sample permutation test
    inherit = "twosample",
    statistic = function(x, y) {
        # (optional) pre-calculate certain constants that remain invariant during permutation
        n_x <- length(x)
        n_y <- length(y)
        F_x <- seq_len(n_x) / n_x
        G_y <- seq_len(n_y) / n_y
        # return a closure to calculate the test statistic
        function(x, y) {
            x <- sort.int(x)
            y <- sort.int(y)
            F <- approxfun(x, F_x, "constant", 0, 1, ties = "ordered")
            G <- approxfun(y, G_y, "constant", 0, 1, ties = "ordered")
            sum(c(F_x - G(x), G_y - F(y))^2)
        }
    },
    # reject the null hypothesis when the test statistic is large
    rejection = "r",
    scoring = "none", n_permu = 1e4,
    name = "Two-Sample Cramér-Von Mises Test",
    alternative = "samples are from different continuous distributions"
)

t$test(rnorm(10), runif(10))$print()

References

Higgins, J. J. 2004. An Introduction to Modern Nonparametric Statistics. Duxbury Advanced Series. Brooks/Cole. https://books.google.com.hk/books?id=vhmFQgAACAAJ.

Copy Link

Version

Install

install.packages('LearnNonparam')

Monthly Downloads

199

Version

1.2.3

License

GPL (>= 2)

Issues

Pull Requests

Stars

Forks

Maintainer

Yan Du

Last Published

October 15th, 2024

Functions in LearnNonparam (1.2.3)

RCBDTest

RCBDTest Class
Table1.2.1

Cycles Until Failure
Studentized

Multiple Comparison Based on Studentized Statistic
Table1.1.1

Sodium Contents
Table2.3.1

Runoff Minutes
Table4.1.1

Caloric Intake
SiegelTukey

Siegel-Tukey Test
Sign

Two-Sample Sign Test
Table2.1.1

Test Scores
Table3.4.1

Phosphorus Contents
TwoSamplePairedTest

TwoSamplePairedTest Class
TwoSampleTest

TwoSampleTest Class
Table5.1.2

Heterophils and Lymphocytes
Table3.3.1

Percentages of Clay
Table2.8.1

Ounces Of Beverage
Table3.2.3

Saltiness Scores
Table4.1.3

Cholesterol Reduction
Table2.6.2

Cerium Amounts
Table4.5.3

Randomized Complete Block with Ties
Table2.6.1

Hours Until Recharge
Table4.4.3

Yield Data
TwoSampleLocationTest

TwoSampleLocationTest Class
TwoSampleAssociationTest

TwoSampleAssociationTest Class
Wilcoxon

Two-Sample Wilcoxon Test
pmt

Syntactic Sugar for Object Construction
Table5.2.2

Scores of Projects
MultipleComparison

MultipleComparison Class
ScoreSum

Two-Sample Test Based on Sum of Scores
RatioMeanDeviance

Ratio Mean Deviance Test
Table3.2.2

Logarithms of Bacteria Counts
Table3.1.2

Normal Samples
Table5.4.2

Satisfaction with Pain-Relief Treatment
KSampleTest

KSampleTest Class
Difference

Two-Sample Test Based on Mean or Median
Friedman

Friedman Test
JonckheereTerpstra

Jonckheere-Terpstra Test
Correlation

Test for Association Between Paired Samples
ContingencyTableTest

ContingencyTableTest Class
CDF

Inference on Cumulative Distribution Function
KolmogorovSmirnov

Two-Sample Kolmogorov-Smirnov Test
AnsariBradley

Ansari-Bradley Test
ChiSquare

Chi-Square Test on Contingency Table
KruskalWallis

Kruskal-Wallis Test
RCBDOneWay

One-Way Test for Equal Means in RCBD
PairedDifference

Paired Comparison Based on Differences
PermuTest

PermuTest Class
OneSampleTest

OneSampleTest Class
Page

Page Test
OneWay

One-Way Test for Equal Means
Quantile

Quantile Test