RChiSquare 0.2.0

One-dimensional continuous tests and power, plus discrete goodness-of-fit testing.

Public test routines use one requested nbins value and return both ES and EP results. Power routines accept a vector nbins and method = "analytic" or method = "simulation". There is no automatic +r adjustment: nbins = k always requests k initial cells.

GOF example

pnull <- function(x, p) pnorm(x, p[1], p[2])
qnull <- function(u, p) qnorm(u, p[1], p[2])
phat  <- function(x) c(mean(x), sd(x))
ralt  <- function(n) rt(n, 5)
palt  <- function(x) pt(x, 5)

set.seed(1)
x <- ralt(1000)
test_cont_1D_gof(x, pnull, qnull, phat=phat, nbins=10)
power_cont_1D_gof(pnull, qnull, ralt, n=1000, nbins=5:10,
              phat=phat, alt_cdf=palt, method="analytic")
power_cont_1D_gof(pnull, qnull, ralt, n=1000, nbins=5:10,
              phat=phat, method="simulation", B=1000)

Two-sample example

rxy <- function() list(x=rnorm(1000), y=rt(1000,5))
z <- rxy()
test_cont_1D_2sample(z$x, z$y, nbins=10)
power_cont_1D_2sample(rxy, n=1000, m=1000, nbins=5:10,
                  method="analytic", Bref=1000)
power_cont_1D_2sample(rxy, n=1000, m=1000, nbins=5:10,
                  method="simulation", B=1000)

Discrete GOF examples

Raw discrete observations require the support to be stated explicitly.

# Binomial support 0,...,5
x <- rbinom(1000, 5, 0.5)
pnull <- function(q) pbinom(q, 5, 0.5)
test_disc_1D_gof(x, pnull, Range=c(0,5))

# Poisson support 0,1,...
x <- rpois(1000, 1)
pnull <- function(q) ppois(q, 1)
test_disc_1D_gof(x, pnull, Range=c(0,Inf))

# Aggregated value/count input
tab <- cbind(value=0:5, count=as.numeric(table(factor(x, levels=0:5))))

Cressie–Read statistics (0.4.8)

Every test_* routine accepts family and lambda (appended arguments). Available families: pearson (lambda=1), likelihood (0), freeman-tukey (-1/2), modified-likelihood (-1), cressie-read (2/3), neyman (-2), and custom (arbitrary finite lambda). For example, test_disc_MD_2sample(x,y,family="likelihood") or test_disc_MD_2sample(x,y,lambda=0.25). Zero observed counts are handled by continuous limits. For lambda <= -1, zero observed counts with positive expected counts imply infinite divergence.

All power_* wrappers accept the same arguments; non-Pearson families currently require method="simulation". Analytic power is restricted to Pearson until appropriate finite-sample calibration is validated. Discrete 1D/MD analytic two-sample power warns when smaller-sample expected counts fall below five on any reference partition.