numbers / numbers.js

Advanced Mathematics Library for Node.js and JavaScript
Apache License 2.0
1.76k stars 168 forks source link

Add basic.range & statistical regression functions #33

Closed zikes closed 11 years ago

zikes commented 11 years ago

basic.range based on underscore.js's range function, except that it will handle reverse ranges and is inclusive rather than exclusive.

For the statistic.exponentialRegression function I went with option 2 on Issue #32.

zikes commented 11 years ago

I'd like to implement Coefficient of Determination next, and while I'd definitely want to include it as a function in number.statistic, I'd also like to have it automatically calculated and returned as a result of regression functions. Since I'm returning a function object, I'm thinking of including it as a property of that function, so it would look something like this:

var regression_function = numbers.statistic.exponentialRegression(data);
console.log(regression_function.rSquared); // 0.9525786476263817

Thoughts/preferences?

zikes commented 11 years ago

I made a gist that uses the exponential regression function and d3.js, to illustrate: http://bl.ocks.org/4279121/b40e188b3faf7ed76e8662cee0631d51ba48157d

I had some difficulty creating a "build" of the updated numbers.js, and had to piece it together manually. Is there documentation on how to do this?

sjkaliski commented 11 years ago

@zikes that's such an awesome use case. I'll be merging this in, certainly. I use https://github.com/substack/node-browserify to "build" numbers.js. I need to include some tool to do that locally. That'll come shortly. Thanks so much!

bengotow commented 11 years ago

@Zikes This looks awesome! I'm actually refactoring a large Node.js project that does regression analysis to use Number.js, and this just made it 10x better suited for what I need. Thank you for contributing this stuff!

thebyrd commented 11 years ago

@Zikes Looks awesome!

zikes commented 11 years ago

Thanks! I'm hitting the limits of my maths knowledge so I don't know how much more I'll be able to contribute there, but I can certainly work on more d3 examples for the documentation. If there are any other numbers.js functions you'd like me to try to graph just let me know.