# How to find correlation between two functions?

Let's say I have two functions, $f$ and $g$. Both take the same normally distributed random variable ($X$) as an input.

\begin{align} f(X) &= X \\ g(X) &= X^2 \end{align}

How does one find the correlation between these two functions, or any two functions in general?

I'd like to do so closed form. No simulation, no interpolation.

Edit: Specified normal distribution.

• What kind of correlation? Pearson? Pearson assumes normal distributions, and X^2 is not normally distributed, so I'm not sure what the value would be. Pearson would also make no sense if X has both positive and negative values, as the relationship of X and X^2 will be a non-monotonic curve. Also to note, any rank correlations will be perfect if all numbers of X are positive (or negative). Commented Dec 14, 2015 at 22:49
• Pearson correlation, and not necessarily monotonic. The "base" function is definitely normally distributed here, and therein is the basis for comparison. Commented Dec 14, 2015 at 23:20
• Think of it this way... Let's assume X is from the standard normal. I can simulate f(X) and g(X) and find a Pearson's correlation of 0. If I have a third function h(X)=X + .5X^2, I can find around an 80% correlation. This value is meaningful in the sense that I would want to hedge an asset h(X) with the asset f(X). Commented Dec 14, 2015 at 23:26

If you apply a function to a random variable you get a new random variable (the function should be measurable for this to hold). Then you can proceed to calculate correlation in the usual manner. So if you take any $f$ and $g$ and normal variable $X$, the desired correlation is

$$cor(f(X),g(X))=\frac{cov(f(X),g(X))}{\sqrt{Var(f(X))}\sqrt{Var(g(X))}}$$

Now

\begin{align} cov(f(X),g(X))&=E[f(X)g(X)]-E[f(X)]E[g(X)]\\ Var(f(X))&= E[f^2(X)]-E[f(X)]^2\\ Var(g(X))& = E[g^2(X)]-E[g(X)]^2 \end{align}

so you need to calculate 5 integrals: $E[(f\cdot g)(X)]$, $E[f(X)]$, $E[f^2(X)]$, $E[g(X)]$, $E[g^2(X)]$ to get the correlation. Even if the $X$ distribution is known and normal, there is no closed form solution for general $f$ and $g$. The particular case of $f(x)=x$ and $g(x)=x^2$ is covered by the answer of Dilip Sarwate. Since you can find closed formulas for moments of normal variables, it would be possible to derive the closed formula in the case of polynomial $f$ and $g$.

• Both mpiktas and dilip sarwate had the answer I was looking for. I found mpiktas to have just a little bit more information, so I marked their answer as the correct one. Commented Dec 16, 2015 at 20:31

For the given functions $X$ and $X^2$ with $X \sim(\mu,\sigma^2)$ being a normal random variable, finding $\operatorname{cov}(X,X^2)$ is relatively easy, and then the (Pearson) correlation coefficient can be found as $$\rho = \frac{\operatorname{cov}(X,X^2)}{\sqrt{\operatorname{var}(X) \operatorname{var}(X^2)}}.$$ Note that $\operatorname{cov}(X,X^2) = E[X\cdot X^2]-E[X]E[X^2] = E[X^3]-E[X]E[X^2]$ where the values of all three expectations can be found in numerous texts and tables as well as on Wikipedia. For example, $E[X^3] = \mu^3 + 3\mu\sigma^2$. Similarly, $\operatorname{var}(X^2) = E[X^4]-\left(E[X^2]\right)^2$ also can be calculated using the known formulas for the moments of a normal random variable.