3

Mathematically, in case of a constant function (`f(x) = c`

) the correlation coefficient of a constant function with function input is not defined. Neverthless, from the function plot, we see that there is no correlation between the function input and output, so it must be returning 0.

There are at least two indeterminations. The "mean" on the $x$-axis is not defined either – Laurent Duval – 2016-02-17T04:46:09.927

Possible duplicate of http://stats.stackexchange.com/questions/18333/what-is-the-correlation-if-the-standard-deviation-of-one-variable-is-0

– Laurent Duval – 2016-02-17T04:48:12.643@LaurentDuval yes the question is similar, but there isn't a convincing answer. The answers suggest that the correlation is 0. Yes the correlation must be 0, but the mathematical equation i guess should include this. I mean as two values, one is the usual computation and the other 0 when the standard deviation of one of the variable is 0. – prashanth – 2016-02-17T09:29:25.533

To me, the answer is in the limit. If you take $y=c+ \epsilon x$, compute the correlation, and take $\epsilon\to 0$, you reach $0$, because a term on the numerator, and the counterpart on the denominator converge to $0$ with the same speed. – Laurent Duval – 2016-02-17T09:33:13.670

@LaurentDuval yes I understand it. But the thing is, I was carrying out correlation analysis between variables and I observed many values returning NaN. Then I closely checked the inputs, they were constant functions. I was wondering why they were returning NaN when it should be returning 0. – prashanth – 2016-02-17T09:43:27.827