simulateH0: Function for Simulating the H0-Distributions needed for...

Description Usage Arguments Details Value Author(s) References See Also Examples

View source: R/Benford_tests.R

Description

simulateH0 is a wrapper function that calculates the specified test statistic under the null hypothesis a certain number of times.

Usage

1
simulateH0(teststatistic="chisq", n=10, digits=1, pvalsims=10)

Arguments

teststatistic

Which test statistic should be used: "chisq", "edist", "jpsq", "ks", "mdist", "meandigit", or "usq".

n

Sample size of interest.

digits

An integer determining the number of first digits to use for testing, i.e. 1 for only the first, 2 for the first two etc.

pvalsims

An integer specifying the number of replicates to be used in simulation.

Details

Wrapper function that directly outputs the distributions of the specified test statistic under the null hypothesis.

Value

A vector of length equal to "pvalsims".

Author(s)

Dieter William Joenssen Dieter.Joenssen@googlemail.com

References

Benford, F. (1938) The Law of Anomalous Numbers. Proceedings of the American Philosophical Society. 78, 551–572.

Joenssen, D.W. (2013) Two Digit Testing for Benford's Law. Proceedings of the ISI World Statistics Congress, 59th Session in Hong Kong. [available under http://www.statistics.gov.hk/wsc/CPS021-P2-S.pdf]

See Also

pbenf, chisq.benftest, edist.benftest, jpsq.benftest, ks.benftest, mdist.benftest, \ meandigit.benftest, usq.benftest

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
#Set the random seed to an arbitrary number
set.seed(421)

#calculate critical value for chisquare test via simulation
quantile(simulateH0(teststatistic="chisq", n=100,digits=1,pvalsims=100000),probs=.95)

#calculate the "real" critical value
qchisq(.95,df=8)

#alternatively look at critical values for the jpsq statistic
#for different sample sizes (notice the low value for pvalsims)
set.seed(421)
apply(sapply((1:9)*10,FUN=simulateH0,teststatistic="jpsq", digits=1, pvalsims=100),
MARGIN=2,FUN=quantile,probs=.05)

BenfordTests documentation built on May 1, 2019, 8:07 p.m.