Preamble: When testing goodness of fit with null distribution with atoms using an EDF-based statistics $T_n$, random variable $n\sqrt{T_n}$ converges in law.
Empirically, the law observed with absolutely continuous null is different, than with purely discrete null.
I was assessing whether, given position of atoms (say integers 0 through 10), the distribution is the same for different weight assignments. So I generated samples from different discrete distributions, computed KS statistics, binned it, and was trying to compare counts to see if I can detect statistically significant differences.
Using Mathematica:
KolmogorovSmirnovStatisticFiniteBoundDiscrete[
vec_ /; VectorQ[vec, IntegerQ],
{kmin_Integer, kmax_Integer},
pvec_
] /; Min[pvec] >= 0 && Total[pvec] == 1 :=
Module[{cnt, pdfList, ecdf, ncdf},
cnt = KeySort[Counts[vec]];
pdfList = AssociationThread[Range[kmin, kmax] -> pvec];
ecdf = Accumulate[
Normalize[Values[KeySort[Merge[{cnt, 0 pdfList}, Total]]], Total]];
ncdf = Accumulate[Values[pdfList]];
Max[
Abs[Most[ecdf] - Most[ncdf]],
If[First[Keys[cnt]] == kmin, 0,
Part[ncdf, First[Keys[cnt]] - kmin]],
If[Last[Keys[cnt]] == kmax, 0,
1 - Part[ncdf, First[Keys[cnt]] - kmin + 1]]
]
]
Generate KS statistics for discrete uniform nulls on $[0,5]$
With[{dist = DiscreteUniformDistribution[{0, 5}], n = 1600},
stat1 = Sqrt[n] Table[
KolmogorovSmirnovStatisticFiniteBoundDiscrete[
RandomVariate[dist, n], {0, 5},
PDF[dist][Range[0, 5]]], {100000}];]
Generate KS statistics for binomial null $\mathrm{Bin}\left(5,\frac{2}{3}\right)$
With[{dist = BinomialDistribution[5, 2/3], n = 1600},
stat2 = Sqrt[n] Table[
KolmogorovSmirnovStatisticFiniteBoundDiscrete[
RandomVariate[dist, n], {0, 5},
PDF[dist][Range[0, 5]]], {100000}];]
Plot histograms of statistics under different nulls:
Histogram[{stat1, stat2}, Automatic, "Probability",
ChartLegends -> {"DiscreteUniform", "Binomial"}]
These statistics have discrete values, for finite $n$, but in the large $n$ limit their cumulative distribution function should converge to an asymptotic continuous CDF.
I was investigating whether these limiting laws are going to be different for different discrete nulls, given both have the same support, as in the above example.
For this I partitioned the positive semi-axis into disjoint intervals, and recorded counts for statistics values in these experiments.
For example:
In[232]:= HistogramList[stat1, {{0, 0.4, 0.9, 100}}]
Out[232]= {{0, 0.4, 0.9, 100}, {19528, 65074, 15398}}
In[233]:= HistogramList[stat2, {{0, 0.4, 0.9, 100}}]
Out[233]= {{0, 0.4, 0.9, 100}, {32064, 58338, 9598}}
Now, given vectors of integer counts, under the null hypothesis that they arose as samples of the same unknown multinomial distribution, I would like to check if data contain evidence against it.
Hence my question:
I have two independent datasets of equal size, and for each of them I compute bin-counts for the common bins.
I hence get two multinomial samples $\{r_1, \ldots, r_n\}$ and $\{t_1, \ldots, t_n\}$. My null hypothesis is that these vectors are samples from the same population distribution.
What test would be appropriate to assess whether differences between $R$ and $T$ vectors can be attributed to randomness.
I am interested in the math part of the question, rather than in actual test computation.
Thank you.
P.S. Feel free to respond using R, Python or any other software package.