# Notes on the Random-Random Term in Autocorrelations¶

The following discussion is adapted from this notebook by Lehman Garrison.

When computing a two-point correlation function estimator like

the \(\RR\) term can be computed analytically if the domain is a periodic box. Often, this is done as

where \(\RR_i\) is the expected number of random-random pairs in bin \(i\), \(N\) is the total number of points, \(V_i\) is the volume (or area if 2D) of bin \(i\), \(L\) is the box size, and \(\bar\rho\) is the average density in the box.

However, using \(\bar\rho = \frac{N}{L^3}\) is only correct for continuous fields, not sets of particles. When sitting on a particle, only \(N-1\) particles are available to be in a bin at some non-zero distance. The remaining particle is the particle you’re sitting on, which is always at distance \(0\). Thus, the correct expression is

See this notebook for an empirical demonstration of this effect; specifically, that computing the density with \(N-1\) is correct, and that using \(N\) introduces bias of order \(\frac{1}{N}\) into the estimator. This is a tiny correction for large \(N\) problems, but important for small \(N\).

Any `Corrfunc`

function that returns a clustering statistic (not just raw pair counts) implements this correction.
Currently, this includes `Corrfunc.theory.xi`

and `Corrfunc.theory.wp`

.

Cross-correlations of two different particle sets don’t suffer from this problem; the particle you’re sitting on is never part of the set of particles under consideration for pair-making.

`Corrfunc`

also allows bins of zero separation, in which “self-pairs” are included in the pair counting. \(\RR_i\) must reflect this by simply adding \(N\) to any such bin.

## RR in Weighted Clustering Statistics¶

We can extend the above discussion to weighted correlation functions in which each particle is assigned a weight, and the pair weight is taken as the product of the particle weights (see Computing Weighted Correlation Functions).

Let \(w_j\) be the weight of particle \(j\), and \(W\) be the sum of the weights. We will define the “unclustered” particle distribution to be the case of \(N\) particles uniformly distributed, where each is assigned the mean weight \(\bar w\). We thus have

When the particles all have \(w_j = 1\), then \(W = N\) and we recover the unweighted result from above.

There are other ways to define the unclustered distribution. If we were to redistribute the particles uniformly but preserve their individual weights, we would find

This is not what we use in `Corrfunc`

, but this should help illuminate some of the considerations that
go into defining the “unclustered” case when writing a custom weight function (see Implementing Custom Weight Functions).