gof_power: Find the power of various gof tests for continuous data.

View source: R/gof_power.R

gof_powerR Documentation

Find the power of various gof tests for continuous data.

Description

Find the power of various gof tests for continuous data.

Usage

gof_power(
  pnull,
  vals = NA,
  rnull,
  ralt,
  param_alt,
  w = function(x) -99,
  phat = function(x) -99,
  TS,
  TSextra = NA,
  alpha = 0.05,
  Range = c(-Inf, Inf),
  B = c(1000, 1000),
  nbins = c(50, 10),
  rate = 0,
  maxProcessors,
  minexpcount = 5,
  ChiUsePhat = TRUE
)

Arguments

pnull

function to find cdf under null hypothesis

vals

=NA, values of rv, if data is discrete, NA if data is continuous

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

=NA, list provided to TS

alpha

=0.05, the level of the hypothesis test

Range

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

B

=c(1000, 1000), number of simulation runs to find power and null distribution

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

maxProcessors

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.

Value

A numeric matrix of power values.

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=c(500, 500))
# Power of tests when null hypothesis specifies normal distribution and 
# mean and standard deviation are estimated from the data. 
# Example is not run because it takes several minutes.
# 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))
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))) 
gof_power(pnull, NA, rnull, ralt, c(0, 1), phat=phat, TSextra=TSextra, 
          B=c(200, 200), maxProcessor=2)
# 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=c(500,500))
# 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=c(200, 200), maxProcessor=2)


Rgof documentation built on Oct. 21, 2024, 5:07 p.m.