Linear Regression

Page 1 of 1

3 Replies - 10974 Views - Last Post: 28 July 2010 - 10:00 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=183585&amp;s=377afbcb9543b543432f2e1c1ebe095e&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

#1 Sh4d0ws

Reputation: 6
• Posts: 40
• Joined: 23-July 10

Linear Regression

Posted 28 July 2010 - 09:16 AM

Hello, I am currently working on a project, and I have been asked to do lines of best fit for a set of data. I have looked into it slightly and found that what I want to do is called Linear Regression, however I do not know how to do this in Java. If anyone can help me it would be very appreciated. I currently do not even have a start on this, so anything that you can offer would be helpful.

I cannot show you the actual data, however I will do a mock-up so that you understand what I am working with.

1. We have an array of double's which stores the values (these values are typically -0.01 to 0.070). The number of the array (e.g. array[10] is the x-coordinate on the graph.

2. The x-scale values are 250-750, and the values on the y-scale are 0.00-0.10

3. All I need is a straight line (although knowing how to do quadratic/cubic lines would be helpful because I believe it is moving to that next in the project).

4. Everything else (its a GUI) is already done (e.g. actionlistener's, buttons, the actual graph, etc) is already complete and I do not require help with that.

Cheers
Sh4d0ws

This post has been edited by Sh4d0ws: 28 July 2010 - 09:21 AM

Is This A Good Question/Topic? 1

Replies To: Linear Regression

#2 macosxnerd101

• Games, Graphs, and Auctions

Reputation: 12278
• Posts: 45,364
• Joined: 27-December 08

Re: Linear Regression

Posted 28 July 2010 - 09:18 AM

Take a look at this link describing how to calculate Linear Regression. Once you have the formula, it's a matter of plugging in points for a drawLine() invocation on your Graphics object.

#3 Sh4d0ws

Reputation: 6
• Posts: 40
• Joined: 23-July 10

Re: Linear Regression

Posted 28 July 2010 - 09:56 AM

Very helpful, thank you macosxnerd101 for a prompt response.

#4 macosxnerd101

• Games, Graphs, and Auctions

Reputation: 12278
• Posts: 45,364
• Joined: 27-December 08

Re: Linear Regression

Posted 28 July 2010 - 10:00 AM