gof_test: Tests for the univariate goodness-of-fit problem

View source: R/gof_test.R

gof_testR Documentation

Tests for the univariate goodness-of-fit problem

Description

This function runs a number of goodness-of-fit tests using Rcpp and parallel computing. The result is an object of class "Rgof_test". The object retains the traditional $statistics and $p.values components and also contains a data-frame representation and metadata about the test.

Usage

gof_test(
  x,
  vals = NA,
  pnull,
  rnull,
  w = function(x) -99,
  phat = function(x) -99,
  TS,
  TSextra,
  nbins = c(50, 10),
  rate = 0,
  Range = c(-Inf, Inf),
  B = 5000,
  minexpcount = 5,
  ChiUsePhat = TRUE,
  maxProcessor,
  doMethods = "all"
)

Arguments

x

Data set.

vals

=NA, values of discrete RV, or NA if data is continuous.

pnull

CDF under the null hypothesis.

rnull

Routine to generate data under the null hypothesis.

w

Optional function to calculate weights, returns -99 if no weights.

phat

=function(x) -99, function to estimate parameters from the data, or -99 if no parameters are estimated.

TS

User supplied function to find test statistics, if any.

TSextra

List passed to TS, if desired, or missing.

nbins

=c(50, 10), number of bins for chi-square tests.

rate

=0, rate of Poisson if sample size is random, 0 if sample size is fixed.

Range

=c(-Inf, Inf), limits of possible observations, if any, for chi-square tests.

B

=5000, number of simulation runs. If B=0, only test statistics are calculated and p-values are returned as NA.

minexpcount

=5 minimal expected bin count required.

ChiUsePhat

=TRUE, if TRUE param is estimated parameter, otherwise minimum chi square method is used.

maxProcessor

Number of processors to use in parallel processing.

doMethods

="all", a vector of codes for the methods to include or all of them.

Details

For details on the usage of this routine consult the vignette with vignette("Rgof", "Rgof").

Value

An object of class "Rgof_test". Its main components are results, a data frame with method, statistic and p-value; statistics and p.values, retained for backward compatibility; parameters, the parameter estimates when present; and metadata, information about the calculation.

Examples

pnull <- function(x) pnorm(x)
rnull <- function() rnorm(100)
x <- rnorm(100)
z <- gof_test(x, NA, pnull, rnull, B=500)
z
z$results
summary(z)
as.data.frame(z)


Rgof documentation built on Sept. 13, 2026, 5:06 p.m.