HarryStevens/d3-regression

regressionExponential and regressionPower break for negative y values

toja opened this issue · 2 comments

toja commented

Probably because of Math.log(dy) that will return NaN

Hello @toja

That is correct.

The exponential regression formula looks like ln(y) = ln(a) + b * x and hence does not support negative y values.

The power regression formula looks like ln(y) = ln(a) + b * ln(x) and hence does not support neither negative x or y values.

You can circumvent the issue by filtering your points.

The question then becomes if this should be left to application level to be handled, or if the library should handle it?

BR Anton

The documentation for regressionExp says ignoring points with invalid values (null, undefined, NaN, Infinity). so ignoring negative values would also be ok. Not that the documentation seems to be true because at least null also results in a NaN output.