Giter Site home page Giter Site logo

qddyy / learnnonparam Goto Github PK

View Code? Open in Web Editor NEW
4.0 2.0 0.0 6.11 MB

Implements various nonparametric tests in chapters 1-5 of the book "An introduction to modern nonparametric statistics" by James J. Higgins.

Home Page: https://qddyy.github.io/LearnNonparam/

License: GNU General Public License v2.0

R 80.29% C++ 19.71%
r hypothesis-test nonparametric-statistics permutation-test r-package

learnnonparam's Introduction

LearnNonparam logo

GitHub License GitHub R package version GitHub code size in bytes CodeFactor Grade R CMD check

Overview

This package implements some of the non-parametric tests in chapters 1-5 of Higgins (2003).

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

A few examples in the book can be found here.

Installation

# install.packages("pak")
pak::pkg_install("qddyy/LearnNonparam")

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) function (recommended)
    t <- pmt("twosample.wilcoxon", n_permu = 1e6)
  • Provide it with samples

    t$test(rnorm(20, 1), rnorm(20, 0))
  • Check the results

    t$statistic
    t$p_value
    t$print()
    t$plot(style = "ggplot2", binwidth = 1)
  • Modify some active bindings and see how the results change

    t$type <- "asymp"
    t$p_value
See pmts() for tests implemented in this package.
key class test
onesample.quantile Quantile Quantile Test
onesample.cdf CDF Inference on Cumulative Distribution Function
twosample.difference Difference Two-Sample Test Based on Mean or Median
twosample.wilcoxon Wilcoxon Two-Sample Wilcoxon Test
twosample.scoresum ScoreSum Two-Sample Test Based on Sum of Scores
twosample.ansari AnsariBradley Ansari-Bradley Test
twosample.siegel SiegelTukey Siegel-Tukey Test
twosample.rmd RatioMeanDeviance Ratio Mean Deviance Test
twosample.ks KolmogorovSmirnov Two-Sample Kolmogorov-Smirnov Test
ksample.f KSampleF K-Sample Test Based on F Statistic
ksample.kw KruskalWallis Kruskal-Wallis Test
ksample.jt JonckheereTerpstra Jonckheere-Terpstra Test
multcomp.studentized Studentized Multiple Comparison Based on Studentized Statistic
paired.sign Sign Two-Sample Sign Test
paired.difference PairedDifference Paired Comparison Based on Differences
rcbd.f RCBDF Test for RCBD Based on F Statistic
rcbd.friedman Friedman Friedman Test
rcbd.page Page Page Test
association.corr Correlation Test for Association Between Paired Samples
table.chisq ChiSquare Chi-Square Test on Contingency Table

The define_pmt function allows users to define new permutation tests. Take Cramér-von Mises test as an example:

t <- define_pmt(
    # this is a two-sample permutation test
    inherit = "twosample",
    statistic = function(x, y) {
        # 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 another function to calculate the test statistic
        function(x, y) {
            x <- sort(x)
            y <- sort(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 = "Cramér-von Mises Test",
    alternative = "samples are from different distributions"
)

t$test(rnorm(20, 1), rnorm(20, 0))$print()

References

Higgins, James J. 2003. An Introduction to Modern Nonparametric Statistics. Florence, KY: Brooks/Cole.

learnnonparam's People

Contributors

qddyy avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.