posted 9 years ago

Hi there,

I am trying to implement the Linest function found in Microsoft Excel but in Java. I am not very good in math. I searched on the Internet for a good and deep explanation for this function, but didn't succeed in finding any. I want to find the linest for a chunk of data.

In Excel, it is like this:

=LINEST(C2:C32,D2:K32,TRUE,TRUE)

Have somebody worked with implmenting this function in his/her code?

I will appreciate any help.

Thanks

I am trying to implement the Linest function found in Microsoft Excel but in Java. I am not very good in math. I searched on the Internet for a good and deep explanation for this function, but didn't succeed in finding any. I want to find the linest for a chunk of data.

In Excel, it is like this:

=LINEST(C2:C32,D2:K32,TRUE,TRUE)

Have somebody worked with implmenting this function in his/her code?

I will appreciate any help.

Thanks

posted 9 years ago

Welcome to the JavaRanch.

JavaRanch is Not A Code Mill. We'd love to help you with your problem, but you are going to have to Show Some Effort.

I was able to find a number of descriptions of LINEST with a search. Exactly what is the problem you have?

JavaRanch is Not A Code Mill. We'd love to help you with your problem, but you are going to have to Show Some Effort.

I was able to find a number of descriptions of LINEST with a search. Exactly what is the problem you have?

posted 9 years ago

By reading the doc to which previous poster pointed you, I see that LINEST is a least-squares algorithm for fitting a straight line to some data points.

If you Google for "least squares Java", you are perhaps more likely to come up with hits that will give hints, or maybe even code, for doing it.

I would like to recommend that you try not to slavishly replicate the exact behaviour of LINEST, which is of course a function whose interface is designed to work with a spreadsheet, not in an object-oriented program with exception handling etc. Try to write (or borrow) a proper Java implementation of least-squares algorithm.

When using least-squares in a program, you should include some sort of check for how good the fit was. The least-squares algorithm will produce a straight line, whatever data it is given (within reason). But if the X and Y data do not really have a linear relationship, you will get a terrible fit. Many very bad decisions have been made, based on blindly fitting straight lines (or whatever) to inappropriate data.

If you Google for "least squares Java", you are perhaps more likely to come up with hits that will give hints, or maybe even code, for doing it.

I would like to recommend that you try not to slavishly replicate the exact behaviour of LINEST, which is of course a function whose interface is designed to work with a spreadsheet, not in an object-oriented program with exception handling etc. Try to write (or borrow) a proper Java implementation of least-squares algorithm.

When using least-squares in a program, you should include some sort of check for how good the fit was. The least-squares algorithm will produce a straight line, whatever data it is given (within reason). But if the X and Y data do not really have a linear relationship, you will get a terrible fit. Many very bad decisions have been made, based on blindly fitting straight lines (or whatever) to inappropriate data.

Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.

With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime. |