MyNixOS website logo
Description

Some Additional Distributions.

Provides the density, distribution, quantile and generation functions of some obscure probability distributions, including the doubly non-central t, F, Beta, and Eta distributions; the lambda-prime and K-prime; the upsilon distribution; the (weighted) sum of non-central chi-squares to a power; the (weighted) sum of log non-central chi-squares; the product of non-central chi-squares to powers; the product of doubly non-central F variables; the product of independent normals.

sadists

Build Status codecov.io CRAN Downloads Total

Some Additional Distributions apparently not available in R.

-- Steven E. Pav, [email protected]

Installation

This package can be installed from CRAN, via drat, or from github:

# via CRAN:
install.packages("sadists")
# via drat:
if (require(drat)) {
    drat:::add("shabbychef")
    install.packages("sadists")
}
# via devtools (typically 'master' is stable):
if (require(devtools)) {
    install_github("shabbychef/sadists")
}

Testing distributions

First some functions to test the 'dpqr' functions:

testf <- function(dpqr, nobs, ...) {
    require(ggplot2)
    require(grid)
    
    set.seed(3940071)
    rv <- sort(dpqr$r(nobs, ...))
    data <- data.frame(draws = rv, pvals = dpqr$p(rv, 
        ...))
    text.size <- 8  # sigh
    
    # http://stackoverflow.com/a/5688125/164611
    p1 <- ggplot(data, aes(x = draws)) + geom_line(aes(y = ..density.., 
        colour = "Empirical"), stat = "density") + 
        stat_function(fun = function(x) {
            dpqr$d(x, ...)
        }, aes(colour = "Theoretical")) + geom_histogram(aes(y = ..density..), 
        alpha = 0.3) + scale_colour_manual(name = "Density", 
        values = c("red", "blue")) + theme(text = element_text(size = text.size)) + 
        labs(title = "Density (tests dfunc)")
    
    # Q-Q plot
    p2 <- ggplot(data, aes(sample = draws)) + stat_qq(distribution = function(p) {
        dpqr$q(p, ...)
    }) + geom_abline(slope = 1, intercept = 0, colour = "red") + 
        theme(text = element_text(size = text.size)) + 
        labs(title = "Q-Q plot (tests qfunc)")
    
    # empirical CDF of the p-values; should be uniform
    p3 <- ggplot(data, aes(sample = pvals)) + stat_qq(distribution = qunif) + 
        geom_abline(slope = 1, intercept = 0, colour = "red") + 
        theme(text = element_text(size = text.size)) + 
        labs(title = "P-P plot (tests pfunc)")
    
    # Define grid layout to locate plots and print each
    # graph
    pushViewport(viewport(layout = grid.layout(2, 2)))
    print(p1, vp = viewport(layout.pos.row = 1, layout.pos.col = 1:2))
    print(p2, vp = viewport(layout.pos.row = 2, layout.pos.col = 1))
    print(p3, vp = viewport(layout.pos.row = 2, layout.pos.col = 2))
}

Weighted sum of (non-central) chi-squares to power

This distribution is the weighted sum of independent (non-central) chi-square variates taken to some powers. The special case where the powers are all one half is related to the upsilon distribution. The special case where the powers are all one could be used to compute the distribution of the (doubly non-central) F distribution.

require(sadists)
wts <- c(-1, 1, 3, -3)
df <- c(100, 200, 100, 50)
ncp <- c(0, 1, 0.5, 2)
pow <- c(1, 0.5, 2, 1.5)
testf(list(d = dsumchisqpow, p = psumchisqpow, q = qsumchisqpow, 
    r = rsumchisqpow), nobs = 2^14, wts, df, ncp, pow)
plot of chunk sumchisqpow

K-prime distribution

The K-prime distribution is the weighted sum of a standard normal and an independent central chi, all divided by another independent central chi. Depending on the degrees of freedom and the weights, the K-prime can appears as a Lambda-prime, a normal, or a central t.

require(sadists)
v1 <- 50
v2 <- 80
a <- 0.5
b <- 1.5
testf(list(d = dkprime, p = pkprime, q = qkprime, r = rkprime), 
    nobs = 2^14, v1, v2, a, b)
plot of chunk kprime

Lambda prime distribution

A Lambda prime random variable is the sum of a standard normal and an independent, scaled central chi random variable.

require(sadists)
df <- 70
ts <- 2
testf(list(d = dlambdap, p = plambdap, q = qlambdap, 
    r = rlambdap), nobs = 2^14, df, ts)
plot of chunk lambdap

Upsilon distribution

An upsilon random variable is the sum of a standard normal and the weighted sum of several indpendent central chis.

require(sadists)
df <- c(30, 50, 100, 20, 10)
ts <- c(-3, 2, 5, -4, 1)
testf(list(d = dupsilon, p = pupsilon, q = qupsilon, 
    r = rupsilon), nobs = 2^14, df, ts)
plot of chunk upsilon

Doubly non-central t distribution

The doubly non-central t distribution generalizes the t distribution to the case where the denominator chi-square is non-central.

require(sadists)
df <- 75
ncp1 <- 2
ncp2 <- 3
testf(list(d = ddnt, p = pdnt, q = qdnt, r = rdnt), 
    nobs = 2^14, df, ncp1, ncp2)
plot of chunk dnt

Doubly non-central F distribution

The doubly non-central F distribution generalizes the F distribution to the case where the denominator chi-square is non-central.

require(sadists)
df1 <- 40
df2 <- 80
ncp1 <- 1.5
ncp2 <- 2.5
testf(list(d = ddnf, p = pdnf, q = qdnf, r = rdnf), 
    nobs = 2^14, df1, df2, ncp1, ncp2)
plot of chunk dnf

Doubly non-central Beta distribution

The doubly non-central Beta distribution can be viewed as a transformation of the doubly non-central F distribution.

require(sadists)
df1 <- 40
df2 <- 80
ncp1 <- 1.5
ncp2 <- 2.5
testf(list(d = ddnbeta, p = pdnbeta, q = qdnbeta, r = rdnbeta), 
    nobs = 2^14, df1, df2, ncp1, ncp2)
plot of chunk dnbeta

Doubly non-central Eta distribution

The doubly non-central Eta distribution can be viewed as the square root of the doubly non-central Beta distribution. It is a transform of the doubly non-central t distribution.

require(sadists)
df <- 100
ncp1 <- 0.5
ncp2 <- 2.5
testf(list(d = ddneta, p = pdneta, q = qdneta, r = rdneta), 
    nobs = 2^14, df, ncp1, ncp2)
plot of chunk dneta

Weighted sum of logs of (non-central) chi-squares

This distribution is the weighted sum of logs of independent (non-central) chi-square variates.

require(sadists)
wts <- c(5, -4, 10, -15)
df <- c(100, 200, 100, 50)
ncp <- c(0, 1, 0.5, 2)
testf(list(d = dsumlogchisq, p = psumlogchisq, q = qsumlogchisq, 
    r = rsumlogchisq), nobs = 2^14, wts, df, ncp)
plot of chunk sumlogchisq

Product of doubly non-central F variates

This distribution is the product of independent doubly non-central F variates. The PDQ functions are computed by transformation on the sum of log chi-squares distribution.

require(sadists)
df1 <- c(10, 20, 5)
df2 <- c(1000, 500, 150)
ncp1 <- c(1, 0, 2.5)
ncp2 <- c(0, 1.5, 5)
testf(list(d = dproddnf, p = pproddnf, q = qproddnf, 
    r = rproddnf), nobs = 2^14, df1, df2, ncp1, ncp2)
plot of chunk proddnf

Product of (non-central) chi-squares to power

This distribution is the product of independent (non-central) chi-square variates taken to some powers. The PDQ functions are computed by transformation on the sum of log chi-squares distribution.

require(sadists)
df <- c(100, 200, 100, 50)
ncp <- c(0, 1, 0.5, 2)
pow <- c(1, 0.5, 2, 1.5)
testf(list(d = dprodchisqpow, p = pprodchisqpow, q = qprodchisqpow, 
    r = rprodchisqpow), nobs = 2^14, df, ncp, pow)
plot of chunk prodchisqpow

Product of independent normals

This distribution is the product of independent normal variates. Warning: when the coefficient of variation is large for some of the factors, this approximation can be terrible.

require(sadists)
mu <- c(100, -50, -10)
sigma <- c(10, 5, 10)
testf(list(d = dprodnormal, p = pprodnormal, q = qprodnormal, 
    r = rprodnormal), nobs = 2^14, mu, sigma)
plot of chunk prodnormal
Metadata

Version

0.2.5

License

Unknown

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows