Do we have a built-in tests to check for the independence of two variables? I’m testing an rng function, one case where the variables, X and Y, are fully correlated (easy to check) and one where their correlation is 0. For the latter, you can compute

\begin{eqnarray*}
\bar x \bar y = \frac{1}{N} \sum x_i \frac{1}{N} \sum y_i \\
\bar{xy} = \frac{1}{N} \sum x_i y_i
\end{eqnarray*}

and see if they’re close enough. I can code in the proper hypothesis test but I wanted to check if the work had already been done.

1 Like

I think, you can calculate the means with build-in functions for the mean: https://mc-stan.org/docs/2_23/functions-reference/array-reductions.html, then to implement the hypothesis test by yourself (personally, I have not seen the latter implemented)

Sorry to not get back to you sooner.

Right now we’re using chi-squared tests for RNG quantiles. There is a framework for that. It’s not set up directly to calculate a correlation as you are requesting.

Since I had the marginal probabilities, I ended up using a chi-square test for the joint probabilities (which I could work analytically under the assumption of independence).

1 Like