Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Weighted linear regression #48

Open
FasterPHP opened this issue Oct 19, 2013 · 5 comments
Open

Weighted linear regression #48

FasterPHP opened this issue Oct 19, 2013 · 5 comments

Comments

@FasterPHP
Copy link

Hi

Do you, by any chance, know where I can find a Javascript library for weighted linear regression? If not, would you consider adding it to simple-statistics?

Thanks

Marcus

@FasterPHP
Copy link
Author

Thanks for the incredibly fast reply, but I'm not sure I understand. Is there some way to use code written in R with javascript??

@tmcw
Copy link
Member

tmcw commented Oct 19, 2013

Sorry, not enough context; I was just adding references, since it takes a little while to figure out what weighted linear regression is. I'm not aware of any js implementations, I'll look into doing it or would accept a patch.

@FasterPHP
Copy link
Author

I see, thanks for clarifying :)

So far, the only implementation I've found in a language I understand is this: http://www.codeproject.com/Articles/25335/An-Algorithm-for-Weighted-Linear-Regression. I've actually already converted this to Javascript, which I can supply if you like, but there are a couple of issues at present: it's not clear to me what I'm supposed to put in the array X that's passed to the Regress method; also, in its current form, I'd have to re-calculate every time a new item of data becomes available. The ideal implementation, in my opinion, would allow for a moving window of data values over which to apply the regression analysis. This would allow me to use it something like this:

var lrObj = new WeightedLinearRegression(lookbackPeriod);

var returnVal;
for (var i = 0; i < someMassiveNumber; i++) {
returnVal = lrObj.getNext(newValue, newWeight);
}

Hope this makes sense!

@tmcw
Copy link
Member

tmcw commented Oct 19, 2013

simple-statistics is pretty committed to vanilla input; I don't plan on supporting generators, streams, etc., because these make it less readable and more complex. A more tuned implementation could be placed in stream-statistics. Though it doesn't look like online methods for linear regression can be implemented with identical behavior to offline.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants