d3-regression
d3-regression copied to clipboard
regressionExponential and regressionPower break for negative y values
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.