Description Usage Arguments Details Value Author(s) References See Also Examples
View source: R/Benford_tests.R
signifd.analysis
takes any numerical vector reduces the sample to the specified number of significant digits. The (relative) frequencies are then plotted so that a subjective analysis may be performed.
1 2 | signifd.analysis(x = NULL, digits = 1, graphical_analysis = TRUE, freq = FALSE,
alphas = 20, tick_col = "red", ci_col = "darkgreen", ci_lines = c(.05))
|
x |
A numeric vector. |
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. |
graphical_analysis |
Boolean value indicating if results should be plotted. |
freq |
Boolean value indicating if absolute frequencies should be used. |
alphas |
Either a vector containing the significance levels([0,1]) that will be shaded, or an integer defining the number of evenly spaced confidence intervals. |
tick_col |
Color code or name that will be passed to " |
ci_col |
Color code or name that will be passed to " |
ci_lines |
Boolean or fractional value(s) indicating significance levels where lines are drawn |
Confidence intervals are calculated from the normal distribution with μ_i = np_i and σ^2 = np_i(1-p_i), where i represents the considered digit. Be aware that the normal approximation only holds for "large" n.
A list containing the following components:
summary |
the summary printed below the graph, a matrix of digits, their (relative) frequencies and individual p-values |
CIs |
confidence intervals used for plotting as defined by parameter " |
Dieter William Joenssen Dieter.Joenssen@googlemail.com
Benford, F. (1938) The Law of Anomalous Numbers. Proceedings of the American Philosophical Society. 78, 551–572.
Freedman, L.S. (1981) Watson's Un2 Statistic for a Discrete Distribution. Biometrika. 68, 708–711.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | #Set the random seed to an arbitrary number
set.seed(421)
#Create a sample satisfying Benford's law
X<-rbenf(n=20)
#Analyze the first digits using the the defaults
signifd.analysis(X)
#Turn off plot
signifd.analysis(X,graphical_analysis=FALSE)
#Use absolute frequencies
signifd.analysis(X,graphical_analysis=FALSE,freq=TRUE)
#Use five evenly spaced confidence intervals, no lines
#alphas is used for shadeing
signifd.analysis(X,graphical_analysis=TRUE,alphas=5,freq=TRUE,ci_lines=FALSE)
#Use fifty evenly spaced, gray confidence intervals, blue ticks, and lines at
#the 1 and 5 percent confidence intervals
signifd.analysis(X,graphical_analysis=TRUE,alphas=50,freq=TRUE,tick_col="blue",
ci_col="gray",ci_lines=c(.01,.05))
|
$summary
1 2 3 4 5 6 7
freq 0.2000000 0.2500000 0.1500000 0.0500000 0.1500000 0.1000000 0.1000000
pvals 0.3246297 0.3855228 0.7346389 0.4782389 0.2408315 0.5542258 0.4215249
8 9
freq 0.0000000 0.0000000
pvals 0.2990998 0.3274307
$CIs
1 2 3 4 5 6
0.025 0.09999704 0.009158509 -0.0199721 -0.03274310 -0.03915869 -0.04258777
0.5 0.30103000 0.176091259 0.1249387 0.09691001 0.07918125 0.06694679
0.975 0.50206295 0.343024009 0.2698496 0.22656312 0.19752118 0.17648135
7 8 9
0.025 -0.04444208 -0.04540027 -0.04582102
0.5 0.05799195 0.05115252 0.04575749
0.975 0.16042597 0.14770531 0.13733600
$summary
1 2 3 4 5 6 7
freq 0.2000000 0.2500000 0.1500000 0.0500000 0.1500000 0.1000000 0.1000000
pvals 0.3246297 0.3855228 0.7346389 0.4782389 0.2408315 0.5542258 0.4215249
8 9
freq 0.0000000 0.0000000
pvals 0.2990998 0.3274307
$CIs
1 2 3 4 5 6
0.025 0.09999704 0.009158509 -0.0199721 -0.03274310 -0.03915869 -0.04258777
0.5 0.30103000 0.176091259 0.1249387 0.09691001 0.07918125 0.06694679
0.975 0.50206295 0.343024009 0.2698496 0.22656312 0.19752118 0.17648135
7 8 9
0.025 -0.04444208 -0.04540027 -0.04582102
0.5 0.05799195 0.05115252 0.04575749
0.975 0.16042597 0.14770531 0.13733600
$summary
1 2 3 4 5 6 7
freq 4.0000000 5.0000000 3.0000000 1.0000000 3.0000000 2.0000000 2.0000000
pvals 0.3246297 0.3855228 0.7346389 0.4782389 0.2408315 0.5542258 0.4215249
8 9
freq 0.0000000 0.0000000
pvals 0.2990998 0.3274307
$CIs
1 2 3 4 5 6
0.025 1.999941 0.1831702 -0.3994421 -0.6548619 -0.7831738 -0.8517555
0.5 6.020600 3.5218252 2.4987747 1.9382003 1.5836249 1.3389358
0.975 10.041259 6.8604802 5.3969916 4.5312624 3.9504237 3.5296270
7 8 9
0.025 -0.8888416 -0.9080053 -0.9164204
0.5 1.1598389 1.0230504 0.9151498
0.975 3.2085195 2.9541062 2.7467200
$summary
1 2 3 4 5 6 7
freq 4.0000000 5.0000000 3.0000000 1.0000000 3.0000000 2.0000000 2.0000000
pvals 0.3246297 0.3855228 0.7346389 0.4782389 0.2408315 0.5542258 0.4215249
8 9
freq 0.0000000 0.0000000
pvals 0.2990998 0.3274307
$CIs
1 2 3 4 5
0.0416666666666667 2.468273 0.5720618 -0.06185339 -0.3528181 -0.50748551
0.0833333333333333 3.183534 1.1659960 0.45372856 0.1084780 -0.08644086
0.125 3.660780 1.5622893 0.79774249 0.4162705 0.19449456
0.166666666666667 4.036037 1.8738934 1.06823954 0.6582868 0.41539317
0.208333333333333 4.354421 2.1382717 1.29774078 0.8636238 0.60281298
0.5 6.020600 3.5218252 2.49877473 1.9382003 1.58362492
0.791666666666667 7.686779 4.9053787 3.69980869 3.0127768 2.56443686
0.833333333333333 8.005163 5.1697569 3.92930993 3.2181137 2.75185667
0.875 8.380420 5.4813610 4.19980697 3.4601300 2.97275529
0.916666666666667 8.857666 5.8776543 4.54382091 3.7679225 3.25369070
0.958333333333333 9.572926 6.4715886 5.05940285 4.2292186 3.67473536
6 7 8 9
0.0416666666666667 -0.59658040 -0.65020817 -0.68307302 -0.70307630
0.0833333333333333 -0.20686461 -0.28575556 -0.33954541 -0.37724681
0.125 0.05316711 -0.04258029 -0.11033202 -0.15984221
0.166666666666667 0.25762921 0.14862764 0.06989772 0.01110233
0.208333333333333 0.43110359 0.31085660 0.22281233 0.15613897
0.5 1.33893579 1.15983894 1.02305045 0.91514981
0.791666666666667 2.24676800 2.00882128 1.82328856 1.67416066
0.833333333333333 2.42024237 2.17105024 1.97620317 1.81919729
0.875 2.62470448 2.36225817 2.15643292 1.99014183
0.916666666666667 2.88473620 2.60543344 2.38564631 2.20754643
0.958333333333333 3.27445199 2.96988605 2.72917392 2.53337592
$summary
1 2 3 4 5 6 7
freq 4.0000000 5.0000000 3.0000000 1.0000000 3.0000000 2.0000000 2.0000000
pvals 0.3246297 0.3855228 0.7346389 0.4782389 0.2408315 0.5542258 0.4215249
8 9
freq 0.0000000 0.0000000
pvals 0.2990998 0.3274307
$CIs
1 2 3 4 5 6
0.005 0.7365583 -0.8659113 -1.3101278 -1.4696611 -1.5268759 -1.5401205
0.025 1.9999409 0.1831702 -0.3994421 -0.6548619 -0.7831738 -0.8517555
0.5 6.0205999 3.5218252 2.4987747 1.9382003 1.5836249 1.3389358
0.975 10.0412589 6.8604802 5.3969916 4.5312624 3.9504237 3.5296270
0.995 11.3046416 7.9095616 6.3076773 5.3460616 4.6941257 4.2179921
7 8 9
0.005 -1.5325837 -1.5147870 -1.4919415
0.025 -0.8888416 -0.9080053 -0.9164204
0.5 1.1598389 1.0230504 0.9151498
0.975 3.2085195 2.9541062 2.7467200
0.995 3.8522616 3.5608879 3.3222411
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.