Package {Rgof}


Title: 1d Goodness of Fit Tests
Version: 4.0.0
Description: Routines that allow the user to run a large number of goodness-of-fit tests. It allows for data to be continuous or discrete. It includes routines to estimate the power of the tests and display them as a power graph. The routine run.studies allows a user to quickly study the power of a new method and how it compares to some of the standard ones.
License: GPL-2 | GPL-3 [expanded from: GPL (≥ 2)]
Encoding: UTF-8
LinkingTo: Rcpp
Imports: Rcpp, parallel, ggplot2, stats, graphics, microbenchmark, nortest
Suggests: rmarkdown, knitr, testthat (≥ 3.0.0)
VignetteBuilder: knitr
Depends: R (≥ 3.5)
LazyData: true
Config/roxygen2/version: 8.0.0
Config/testthat/edition: 3
NeedsCompilation: yes
Packaged: 2026-09-13 10:41:09 UTC; Wolfgang
Author: Wolfgang Rolke ORCID iD [aut, cre]
Maintainer: Wolfgang Rolke <wolfgang.rolke@upr.edu>
Repository: CRAN
Date/Publication: 2026-09-13 11:10:02 UTC

Rgof: 1d Goodness of Fit Tests

Description

Routines that allow the user to run a large number of goodness-of-fit tests. It allows for data to be continuous or discrete. It includes routines to estimate the power of the tests and display them as a power graph. The routine run.studies allows a user to quickly study the power of a new method and how it compares to some of the standard ones.

Author(s)

Maintainer: Wolfgang Rolke wolfgang.rolke@upr.edu (ORCID)

Authors:


sort vector y by values in vector x

Description

sort vector y by values in vector x

Usage

Cpporder(y, x)

Arguments

y

numeric vector

x

numeric vector

Value

numeric vector


Find test statistics for continuous data

Description

Find test statistics for continuous data

Usage

TS_cont(x, pnull, param, qnull)

Arguments

x

A numeric vector.

pnull

cdf.

param

parameters for pnull in case of parameter estimation.

qnull

An R function, the quantile function under the null hypothesis.

Value

A numeric vector with test statistics


Find test statistics for discrete data

Description

Find test statistics for discrete data

Usage

TS_disc(x, pnull, param, vals)

Arguments

x

An integer vector.

pnull

cdf.

param

parameters for pnull in case of parameter estimation.

vals

A numeric vector with the values of the discrete rv.

Value

A vector with test statistics


Find test statistics for continuous data with weights

Description

Find test statistics for continuous data with weights

Usage

TSw_cont(x, pnull, param, w)

Arguments

x

A numeric vector.

pnull

cdf.

param

parameters for pnull in case of parameter estimation.

w

numeric vector of weights

Value

A numeric vector with test statistics


Find test statistics for discrete data

Description

Find test statistics for discrete data

Usage

TSw_disc(x, pnull, param, vals, w)

Arguments

x

An integer vector.

pnull

cdf.

param

parameters for pnull in case of parameter estimation.

vals

A numeric vector with the values of the discrete rv.

w

weights

Value

A vector with test statistics


Convert adaptive Rgof power output to a data frame

Description

Convert adaptive Rgof power output to a data frame

Usage

## S3 method for class 'Rgof_power_adaptive'
as.data.frame(x, ...)

Arguments

x

Object returned by gof_power_adaptive().

...

Unused.


Convert an Rgof test result to a data frame

Description

Convert an Rgof test result to a data frame

Usage

## S3 method for class 'Rgof_test'
as.data.frame(x, row.names = NULL, optional = FALSE, ...)

Arguments

x

An object of class "Rgof_test".

row.names

Ignored.

optional

Ignored.

...

Currently unused.

Value

A data frame with columns method, statistic, and p.value.


count events in bins. Useful for power calculations. Replaces hist command from R.

Description

count events in bins. Useful for power calculations. Replaces hist command from R.

Usage

bincounter(x, bins)

Arguments

x

numeric vector

bins

numeric vector

Value

Integer vector of counts


This function calculates the test statistics for data

Description

This function calculates the test statistics for data

Usage

calcTS(dta, TS, typeTS, TSextra)

Arguments

dta

data set as a list

TS

routine

typeTS

format of TS

TSextra

list passed to TS function

Value

A vector of numbers


Create case studies

Description

This function creates the functions needed to run the various case studies.

Usage

case_studies(
  which,
  which_diff = "mean",
  data_type = "cont",
  n,
  nbins = 50,
  funs_list,
  ReturnCaseNames = FALSE
)

Arguments

which

name of the case study, or its number in the list.

which_diff

="mean", name of parameter in which data sets differ, or its number in the list.

data_type

="cont", is data continuous or discrete?

n

sample sizes.

nbins

=50, number of bins for discrete data

funs_list

list of alternative functions

ReturnCaseNames

=FALSE, should list of case studies be returned?

Value

a list of functions to create case studies


case_studies_sample_sizes

Description

sample sizes for the various case studies

Usage

case_studies_sample_sizes

Format

'case_studies_sample_sizes'

A list


This function checks whether the inputs have the correct format

Description

This function checks whether the inputs have the correct format

Usage

check.functions(pnull, rnull, phat = function(x) -99, vals, x)

Arguments

pnull

cdf under the null hypothesis

rnull

routine to generate data under the null hypothesis

phat

=function(x) -99, function to estimate parameters from the data, or -99

vals

vector of discrete values

x

data


This function finds the power of various chi-square tests for continuous data

Description

This function finds the power of various chi-square tests for continuous data

Usage

chi_power_cont(
  pnull,
  ralt,
  param_alt,
  qnull = NA,
  phat = function(x) -99,
  w = function(x) -99,
  alpha = 0.05,
  Range = c(-99999, 99999),
  B = 1000,
  nbins = c(50, 10),
  rate = 0,
  minexpcount = 5,
  ChiUsePhat = TRUE
)

Arguments

pnull

function to find cdf under null hypothesis

ralt

function to generate data under alternative hypothesis

param_alt

vector of parameter values for distribution under alternative hypothesis

qnull

=NA function to find quantiles under null hypothesis, if available

phat

=function(x) -99, function to estimate parameters

w

=function(x) -99, optional weight function

alpha

=0.05, the level of the hypothesis test

Range

=c(-99999, 99999) limits of possible observations, if any

B

=1000 number of simulation runs to find power

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

minexpcount

=5 minimal expected bin count required

ChiUsePhat

=TRUE, if TRUE param is estimated parameters and no minimization is used

Value

A numeric matrix of power values.


This function finds the power of various chi-square tests for continuous data

Description

This function finds the power of various chi-square tests for continuous data

Usage

chi_power_disc(
  pnull,
  ralt,
  param_alt,
  phat = function(x) -99,
  alpha = 0.05,
  B = 1000,
  nbins = c(50, 10),
  rate = 0,
  minexpcount = 5,
  ChiUsePhat = TRUE
)

Arguments

pnull

function to find cdf under null hypothesis

ralt

function to generate data under alternative hypothesis

param_alt

vector of parameter values for distribution under alternative hypothesis

phat

=function(x) -99, routine to estimate parameters

alpha

=0.05, the level of the hypothesis test

B

=1000 number of simulation runs to find power

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

minexpcount

=5 minimal expected bin count required

ChiUsePhat

= TRUE, should chi square use minimum chi square method?

Value

A numeric matrix of power values.


This function performs a number of chi-square gof tests for continuous data

Description

This function performs a number of chi-square gof tests for continuous data

Usage

chi_test_cont(
  x,
  pnull,
  w = function(x) -99,
  phat = function(x) -99,
  qnull = NA,
  nbins = c(50, 10),
  rate = 0,
  Range = c(-99999, 99999),
  minexpcount = 5,
  ChiUsePhat = TRUE,
  allbins
)

Arguments

x

data set

pnull

cdf under the null hypothesis

w

function to find weights of observations, returns -99 if data is unweighted

phat

=function(x) -99, estimated parameters, or starting values of multi-D minimum chi square minimization, or -99 if no estimation is done

qnull

=NA quantile function, if available

nbins

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

rate

=0, rate of Poisson if sample size is random

Range

=c(-99999, 99999) limits of possible observations, if any

minexpcount

=5 minimal expected bin count required

ChiUsePhat

=TRUE, if TRUE param is estimated parameters and no minimization is used

allbins

set of bins to use

Value

A numeric matrix of test statistics, degrees of freedom and p.values


This function performs a number of chi-square gof tests for continuous data

Description

This function performs a number of chi-square gof tests for continuous data

Usage

chi_test_disc(
  x,
  pnull,
  phat = function(x) -99,
  nbins = c(50, 10),
  rate = 0,
  minexpcount = 5,
  ChiUsePhat = TRUE,
  allbins
)

Arguments

x

data set

pnull

cdf under the null hypothesis

phat

=function(x) -99, function to estimate parameters, or starting values of multi-D minimum chi square minimization, or -99 if no parameters are estimated

nbins

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

rate

=0, rate of Poisson if sample size is random

minexpcount

=5 minimal expected bin count required

ChiUsePhat

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

allbins

set of bins to use

Value

A numeric matrix of test statistics, degrees of freedom and p.values


funs_list

Description

function definitions for case studies

Usage

funs_list

Format

'funs_list'

A list of functions


helper functions to do p value adjustment

Description

helper functions to do p value adjustment

Usage

gof_adj_C1(dta, rnull, vals, TS, typeTS, TSextra, B = 1000L)

Arguments

dta

data set

rnull

R function (generate data under null hypothesis)

vals

values of discrete random variable

TS

function to calculate test statistics

typeTS

integer indicating type of test statistic

TSextra

list to pass to TS

B

=1000 Number of simulation runs

Value

A matrix of powers


helper functions to do p value adjustment

Description

helper functions to do p value adjustment

Usage

gof_adj_C2(dta, rnull, vals, TS, typeTS, TSextra, A, B = 1000L)

Arguments

dta

data set

rnull

R function (generate data under null hypothesis)

vals

values of discrete random variable

TS

function to calculate test statistics

typeTS

integer indicating type of test statistic

TSextra

list to pass to TS

A

matrix of test statistic values

B

=1000 Number of simulation runs

Value

A matrix of powers


Power estimation of goodness-of-fit tests.

Description

Find the power of various goodness-of-fit tests.

Usage

gof_power(
  pnull,
  vals = NA,
  rnull,
  ralt,
  param_alt,
  w = function(x) -99,
  phat = function(x) -99,
  TS,
  TSextra,
  With.p.value = FALSE,
  alpha = 0.05,
  Range = c(-Inf, Inf),
  B = 1000,
  nbins = c(50, 10),
  rate = 0,
  maxProcessor,
  minexpcount = 5,
  ChiUsePhat = TRUE,
  SuppressMessages = FALSE,
  CI = FALSE,
  conf.level = 0.95,
  seed = NULL,
  list.with.everything
)

Arguments

pnull

function to find cdf under null hypothesis

vals

=NA values of discrete random variable, or NA

rnull

function to generate data under null hypothesis

ralt

function to generate data under alternative hypothesis

param_alt

,vector of parameter values for distribution under alternative 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

TS

user supplied function to find test statistics

TSextra

list provided to TS (optional)

With.p.value

=FALSE does user supplied routine return p values?

alpha

=0.05, the level of the hypothesis test

Range

=c(-Inf, Inf) limits of possible observations, if any

B

=1000 number of simulation runs

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

maxProcessor

maximum of number of processors to use, 1 if no parallel processing is needed or number of cores-1 if missing

minexpcount

=5 minimal expected bin count required

ChiUsePhat

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

SuppressMessages

=FALSE

CI

=FALSE if TRUE, return Monte Carlo standard errors and Wilson confidence intervals for the estimated power.

conf.level

=0.95 confidence level used when CI=TRUE.

seed

=NULL, optional seed for reproducabilty

list.with.everything

A list with all needed info, such as pnull, rnull etc

Details

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

Value

By default, a numeric matrix (or vector for one alternative) of power values. If CI=TRUE, an object of class Rgof_power containing power estimates, Monte Carlo standard errors, and Wilson confidence limits.

Examples

# Power of tests when null hypothesis specifies the standard normal distribution but 
# true data comes from a normal distribution with mean different from 0.
pnull = function(x) pnorm(x)
rnull = function()  rnorm(50)
ralt = function(mu)  rnorm(50, mu)
TSextra = list(qnull=function(x) qnorm(x))
gof_power(pnull, NA, rnull, ralt, c(0.25, 0.5), TSextra=TSextra, B=200)
# Power of tests when null hypothesis specifies normal distribution and 
# mean and standard deviation are estimated from the data. 
# true data comes from a normal distribution with mean different from 0.
pnull = function(x, p=c(0, 1)) pnorm(x, p[1], ifelse(p[2]>0.001, p[2], 0.001))
rnull = function(p=c(0, 1))  rnorm(50, p[1], ifelse(p[2]>0.001, p[2], 0.001))
ralt = function(mu)  rnorm(50, mu)
phat = function(x) c(mean(x), sd(x))
TSextra = list(qnull = function(x, p=c(0, 1)) qnorm(x, p[1],  
               ifelse(p[2]>0.001, p[2], 0.001))) 
pwr=gof_power(pnull, NA, rnull, ralt, c(0, 1), phat=phat, TSextra=TSextra, B=200)
pwr
#' Compare power of a new test based on variants of the Cramer-vonMises
#' criterion to the methods included in the package: 
newTS = function(x, pnull, param) {
   Fx=sort(pnull(x, param))
   n=length(x)
   out = c(sum(abs( (2*1:n-1)/2/n-Fx )), sum(sqrt(abs( (2*1:n-1)/2/n-Fx ))))
   names(out) = c("CvM alt 1","CvM alt 2")
   out
}
#' Compare power to Lilliefors KS test, which finds its own p value:
LLtest=function(x, pnull, param) {
  out=nortest::lillie.test(x)$p.value
  names(out)="KS - Lilliefors"
  out
}
cbind(gof_power(pnull, NA, rnull, ralt, c(0, 1), TS=LLtest, phat=phat, 
       With.p.value=TRUE, TSextra=TSextra, B=200), pwr)
# Power of tests when null hypothesis specifies Poisson rv with rate 100 and 
# true rate is 100.5
vals = 0:250
pnull = function() ppois(0:250, 100)
rnull =function () table(c(0:250, rpois(1000, 100)))-1
ralt =function (p) table(c(0:250, rpois(1000, p)))-1
gof_power(pnull, vals, rnull, ralt, param_alt=100.5,  B=200)
# Power of tests when null hypothesis specifies a Binomial n=10 distribution 
# with the success probability estimated
vals = 0:10
pnull=function(p) pbinom(0:10, 10, ifelse(0<p&p<1, p, 0.001))
rnull=function(p) table(c(0:10, rbinom(1000, 10, ifelse(0<p&p<1, p, 0.001))))-1
ralt=function(p) table(c(0:10, rbinom(1000, 10, p)))-1
phat=function(x) mean(rep(0:10,x))/10
gof_power(pnull, vals, rnull, ralt, c(0.5, 0.6), phat=phat, B=200)


find power of gof tests for continuous data

Description

find power of gof tests for continuous data

Usage

gof_power_C(rnull, vals, ralt, param_alt, TS, typeTS, TSextra, B = 1000L)

Arguments

rnull

R function (generate data under null hypothesis)

vals

values of discrete random variable

ralt

R function to generate data under alternative

param_alt

parameters of ralt

TS

function to calculate test statistics

typeTS

integer indicating type of test statistic

TSextra

list to pass to TS

B

=1000 Number of simulation runs

Value

A matrix of powers


Adaptive power estimation for goodness-of-fit tests

Description

Estimates power in simulation batches and stops when the Monte Carlo standard error of every reported power estimate is no larger than target.mcse, or when B.max is reached.

Usage

gof_power_adaptive(
  pnull,
  vals = NA,
  rnull,
  ralt,
  param_alt,
  w = function(x) -99,
  phat = function(x) -99,
  TS,
  TSextra,
  With.p.value = FALSE,
  alpha = 0.05,
  Range = c(-Inf, Inf),
  nbins = c(50, 10),
  rate = 0,
  maxProcessor,
  minexpcount = 5,
  ChiUsePhat = TRUE,
  SuppressMessages = FALSE,
  target.mcse = 0.01,
  B.min = 500,
  B.max = 10000,
  B.batch = 250,
  B.null = 1000,
  conf.level = 0.95,
  list.with.everything
)

Arguments

pnull

Function to calculate the cdf under the null hypothesis.

vals

=NA values of a discrete random variable, or NA for continuous data.

rnull

Function to generate data under the null hypothesis.

ralt

Function to generate data under the alternative hypothesis.

param_alt

Vector of parameter values under the alternative.

w

Optional weight function; returns -99 if no weights are used.

phat

Function to estimate parameters, or function(x) -99.

TS

Optional user-supplied test statistic or p-value routine.

TSextra

Optional list supplied to TS.

With.p.value

=FALSE; TRUE if a user-supplied TS returns p-values.

alpha

Significance level.

Range

Limits of possible continuous observations.

nbins

Number of bins for chi-square tests.

rate

Poisson rate if sample size is random; 0 for fixed sample size.

maxProcessor

Maximum number of processors used for the statistic-based simulation. P-value and chi-square simulation remains sequential, as in the corresponding existing package routines.

minexpcount

Minimum expected bin count for chi-square tests.

ChiUsePhat

If TRUE, use estimated parameters in chi-square tests.

SuppressMessages

Suppress adaptive progress messages when TRUE. A run-time estimate is still displayed when the estimated maximum run time exceeds 30 seconds.

target.mcse

Target Monte Carlo standard error.

B.min

Minimum number of alternative simulations per parameter.

B.max

Maximum number of alternative simulations per parameter.

B.batch

Number of additional alternative simulations per batch.

B.null

Number of null simulations used once to estimate the fixed critical values for statistic-based tests.

conf.level

Confidence level for Wilson confidence intervals.

list.with.everything

Optional case-study list accepted by the package.

Details

Unlike gof_power(), this routine performs the adaptive simulation directly. For statistic-based tests it estimates the null critical values once using B.null null simulations and holds those critical values fixed while alternative simulations are added in batches.

Statistic-based tests use a two-stage procedure. First, B.null null data sets are simulated and one set of critical values is estimated. Those critical values are then held fixed. Alternative data sets are simulated in batches and exact rejection counts are accumulated.

User tests with With.p.value=TRUE do not require null critical-value simulation; rejection is determined directly from p-value < alpha.

The package's chi-square tests already perform their own bin construction and diagnostics. Their rejection counts are accumulated directly from chi_test_cont() or chi_test_disc(). For discrete data the bin definitions are selected once for each alternative parameter, matching the design of chi_power_disc().

Value

An object of class Rgof_power_adaptive and Rgof_power. It contains power estimates, Monte Carlo standard errors, Wilson confidence intervals, total alternative simulation count, null simulation count, convergence information, and (when applicable) the fixed critical values.


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)


run gof tests for continuous data

Description

run gof tests for continuous data

Usage

gof_test_C(dta, rnull, TS, typeTS, TSextra, B = 5000L)

Arguments

dta

A numeric vector of data

rnull

R function (generate data under null hypothesis)

TS

function that calculates test statistics

typeTS

integer indicating type of test statistic

TSextra

list to pass to TS

B

(=5000) Number of simulation runs

Value

A matrix of numbers


Adjusted p values for simultaneous testing in the goodness-of-fit problem.

Description

This function performs a number of goodness-of-fit tests and finds the adjusted p value for the combined test.

Usage

gof_test_adjusted_pvalue(
  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 = c(5000, 1000),
  minexpcount = 5,
  ChiUsePhat = TRUE,
  maxProcessor,
  doMethods
)

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(100, 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

=c(5000,1000) number of simulation runs for individual and for adjusted p values

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 cores to use

doMethods

a vector of codes for the methods to include. If missing, a default selection of methods are used.

Details

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

Value

None

Examples

# Tests to see whether data comes from a standard normal distribution.
pnull = function(x) pnorm(x)
rnull = function()  rnorm(100)
x = rnorm(100)
gof_test_adjusted_pvalue(x, NA, pnull, rnull, B=c(500, 200), 
                            maxProcessor=1)
# Tests to see whether data comes from a normal distribution with standard deviation 1 
# and the mean estimated.
pnull=function(x, m) pnorm(x, m)
rnull=function(m) rnorm(100, m)
TSextra = list(qnull=function(x, m=0) qnorm(x, m))
phat=function(x) mean(x)
x = rnorm(100, 1, 2)
gof_test_adjusted_pvalue(x, NA, pnull, rnull, phat=phat, 
                        TSextra=TSextra, B=c(500, 200), maxProcessor=1)
# Tests to see whether data comes from a binomial (10, 0.5) distribution.
vals=0:10
pnull = function() pbinom(0:10, 10, 0.5)
rnull = function() table(c(0:10, rbinom(1000, 10, 0.5)))-1
x = rnull() 
gof_test_adjusted_pvalue(x, vals, pnull, rnull, 
                        B=c(500, 200), maxProcessor=1)
# Tests to see whether data comes from a binomial distribution with 
# the success probability estimated from the data.
pnull = function(p=0.5) pbinom(0:10, 10, p)
rnull = function(p=0.5) table(c(0:10, rbinom(1000, 10, p)))-1
phat=function(x) mean(rep(0:10,x))/10 
gof_test_adjusted_pvalue(x, vals, pnull, rnull, phat=phat, 
                        B=c(500, 200), maxProcessor=1) 

makeTSextra

Description

create the TSextra list required by many routines.

Usage

makeTSextra(TSextra, pnull, phat, w, Continuous)

Arguments

TSextra

a user-supplied list

pnull

cdf

phat

estimation routine

w

weight function

Continuous

is data continuous?

Value

a list


This function creates several type of bins for continuous data

Description

This function creates several type of bins for continuous data

Usage

make_bins_cont(
  x,
  pnull,
  qnull = NA,
  phat = function(x) -99,
  DataBased = FALSE,
  nbins = c(50, 10),
  minexpcount = 5,
  Range = c(-99999, 99999)
)

Arguments

x

data set

pnull

cdf under the null hypothesis

qnull

=NA quantile function, if available

phat

=function(x) -99 parameters for pnull

DataBased

=FALSE bins based on data, not expected counts

nbins

=c(50, 10) number of bins

minexpcount

=5 smallest expected count per bin

Range

=c(-99999, 99999) limits of possible observations, if any

Value

A list of bins and bin probabilities


This function creates several types of bins for discrete data

Description

This function creates several types of bins for discrete data

Usage

make_bins_disc(
  x,
  pnull,
  phat = function(x) -99,
  nbins = c(50, 10),
  minexpcount = 5
)

Arguments

x

counts

pnull

cumulative distribution function

phat

=function(x) -99, function to estimated parameters, or -99

nbins

=c(50, 10) number of bins

minexpcount

=5 smallest expected count per bin

Value

A list of indices


maketypeTS

Description

find typeTS and TS

Usage

maketypeTS(TS, Continuous, WithWeights)

Arguments

TS

a function

Continuous

is data continuous?

WithWeights

with weights?

Value

a list


mle of double truncated exponential distribution

Description

This function uses the Newton-Rahson algorithm to find the mle of a doubly truncated exponential distribution

Usage

mledexp(x)

Arguments

x

data set

Value

a vector


MLE of ratio of mixture distributions

Description

This function uses the Newton-Raphson algorithm to find the mle of a mixture distribution

Usage

mlemix(fx, gx, acc = 0.001)

Arguments

fx

density 1 evaluated at data set

gx

density 2 evaluated at data set

Value

a number


mle's of truncated exponential distribution

Description

This function uses the Newton-Rahson algorithm to find the mle's of a truncated exponential distribution

Usage

mletexp(x)

Arguments

x

data set

Value

a vector


Testing routine for continuous data

Description

find test statistic or p value for continuous data

Usage

myTS_cont(x, pnull, p = 0, TSextra)

Arguments

x

data set

pnull

function to find cdf under null hypothesis

p

=0, parameter estimates or 0

TSextra

list with additional info

Value

a number, value fo statistic or p value


Testing routine for discrete data

Description

find test statistic or p value for discrete data

Usage

myTS_disc(x, pnull, p = 0, vals, TSextra)

Arguments

x

data set

pnull

function to find cdf under null hypothesis

p

=0, parameter estimates or 0

vals

=NA values of discrete random variable, or NA

TSextra

list with additional info

Value

a number, value fo statistic or p value


a local function needed for the vignette

Description

a local function needed for the vignette

Usage

newTSdisc(x, pnull, param, vals)

Arguments

x

An integer vector.

pnull

cdf.

param

parameters for pnull in case of parameter estimation.

vals

A numeric vector with the values of the discrete rv.

Value

A vector with test statistics


This function draws the power graph, with curves sorted by the mean power and smoothed for easier reading.

Description

This function draws the power graph, with curves sorted by the mean power and smoothed for easier reading.

Usage

plot_power(pwr, xname = " ", title, Smooth = TRUE, span = 0.25)

Arguments

pwr

a matrix of power values, usually from the twosample_power command

xname

Name of variable on x axis

title

(Optional) title of graph

Smooth

=TRUE lines are smoothed for easier reading

span

=0.25bandwidth of smoothing method

Value

plt, an object of class ggplot.


power.uniform.linear

Description

matrix with power values, for vignette

Usage

power.uniform.linear

Format

'power.uniform.linear'

matrix with power values, for vignette


This function estimates the power of test routines that calculate p value(s)

Description

This function estimates the power of test routines that calculate p value(s)

Usage

power_newtest(
  TS,
  vals = NA,
  pnull,
  ralt,
  param_alt,
  phat,
  TSextra,
  alpha = 0.05,
  B = 1000
)

Arguments

TS

routine to calculate test statistics.

vals

=NA if data is discrete, a vector of possible values

pnull

routine to calculate the cdf under the null hypothesis

ralt

generate data under alternative hypothesis

param_alt

values of parameter under the alternative hypothesis.

phat

function to estimate parameters, function(x) -99 if no parameter estimation

TSextra

list (possibly) passed to TS

alpha

=0.05 type I error.

B

= 1000 number of simulation runs to estimate the power.

Value

A matrix of power values


power_study

Description

the results of the included power studies

Usage

power_study

Format

'power_study'

A list of matrices with powers


Print an adaptive Rgof power object

Description

Print an adaptive Rgof power object

Usage

## S3 method for class 'Rgof_power_adaptive'
print(x, ...)

Arguments

x

Object returned by gof_power_adaptive().

...

Unused.


Print an Rgof goodness-of-fit test result

Description

Print an Rgof goodness-of-fit test result

Usage

## S3 method for class 'Rgof_test'
print(x, ...)

Arguments

x

An object of class "Rgof_test".

...

Further arguments passed to print.data.frame.

Value

x, invisibly.


pvaluecdf

Description

the info needed to draw a graph

Usage

pvaluecdf

Format

'pvaluecdf'

A matrix


Power Comparisons

Description

This function runs the case studies included in the package and compares the power of a new test to those included.

Usage

run.studies(
  studies = 1:60,
  types = 1:5,
  data_type = "cont",
  TS,
  TSextra,
  With.p.value = FALSE,
  n,
  alpha = 0.05,
  B = 1000,
  SuppressMessages = TRUE,
  RerunIncludedCases = FALSE
)

Arguments

studies

=1:50, either the names of the studies, or their numbers. If missing all the studies are run.

types

=1:5, either the types of studies, or their numbers. If missing all types are run.

data_type

="cont", continuous or discrete data

TS

routine to calculate test statistics.

TSextra

list passed to TS.

With.p.value

=FALSE does user supplied routine return p values?

n

desired sample size.

alpha

=0.05 type I error

B

= 1000

SuppressMessages

=TRUE

RerunIncludedCases

=FALSE, set to true to verify powers in Rgof::power_study

Details

For details consult vignette("Rgof","Rgof")

Value

A matrix of power values.

Examples

TSextra=list(nbins=5, statistic=FALSE) # Use 5 bins and calculate p values
run.studies(1:2, 1:2, TS=myTS_cont, TSextra=TSextra, With.p.value=TRUE, B=100)

This function does some rounding to nice numbers

Description

This function does some rounding to nice numbers

Usage

signif_digits(x, d = 4)

Arguments

x

a list of two vectors

d

=4 number of digits to round to

Value

A list with rounded vectors


Summarize an Rgof goodness-of-fit test result

Description

Summarize an Rgof goodness-of-fit test result

Usage

## S3 method for class 'Rgof_test'
summary(object, ...)

Arguments

object

An object of class "Rgof_test".

...

Currently unused.

Value

An object of class "summary.Rgof_test".


This function checks whether the correct methods have been requested

Description

This function checks whether the correct methods have been requested

Usage

test_methods(doMethods, Continuous, WithWeights)

Arguments

doMethods

="all" Which methods should be included?

Continuous

is data continuous

WithWeights

with weights?

Value

TRUE or FALSE


estimate run time function

Description

estimate run time function

Usage

timecheck(dta, TS, typeTS, TSextra)

Arguments

dta

data set

TS

test statistic

typeTS

format of TS

TSextra

additional info TS

Value

Mean computation time


Find counts or sum of weights in bins. Useful for power calculations. Replaces hist command from R.

Description

Find counts or sum of weights in bins. Useful for power calculations. Replaces hist command from R.

Usage

wbincounter(x, bins, w)

Arguments

x

numeric vector

bins

numeric vector

w

numeric vector of weights

Value

sum of weights in bins