The td_independence function tests the independence of terminal digits from
preceding digits by constructing a contingency table of counts where rows constitute
unique preceding digits and columns constitute unique terminal digits. A test of
independence for a contingency tables is then implemented via Monte Carlo
simulation.
td_independence(
x,
decimals,
reps = 10000,
test = "Chisq",
tolerance = 64 * .Machine$double.eps
)a numeric vector
an integer specifying the number of decimals. This can be zero if the terminal digit is not a decimal.
a positive integer specifying the number of Monte Carlo simulations. The default is set to 10,000 which may be appropriate for exploratory analysis. A higher number of simulation should be selected for more precise results.
a string specifying the test of independence. The default is Pearson's chi-squared statistic ("Chisq"). Also available is the log-likelihood ratio statistic ("G2"), the Freeman-Tukey statistic ("FT"), and the Root-mean-square statistic ("RMS").
sets an upper bound for rounding errors when evaluating
whether a statistic for a simulation is greater than or equal to the
statistic for the observed data. The default is identical to the tolerance
set for simulations in the chisq.test function from the stats
package in R.
A list with class "htest" containing the following components:
the value of the test statistic
the simulated p-value for the test
a character string describing the test
a character string give the name of the data
Monte Carlo simulations are implemented for contingency tables with fixed margins using algorithm ASA 144 (Agresti, Wackerly, and Boyett, 1979; Boyett 1979).
Agresti, A., Wackerly, D., & Boyett, J. M. (1979). Exact conditional tests for cross-classifications: approximation of attained significance levels. Psychometrika, 44(1), 75-83.
Boyett, J. M. (1979). Algorithm AS 144: Random r <U+00D7> c tables with given row and column totals. Journal of the Royal Statistical Society. Series C (Applied Statistics), 28(3), 329-332.
# NOT RUN {
td_independence(decoy$weight, decimals = 2, reps = 2000)
# }
Run the code above in your browser using DataLab