Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find a "best fit" equation

Tags:

php

math

It's been a while since I was in college and knew how to calculate a best fit line, but I find myself needing to. Suppose I have a set of points, and I want to find the line that is the best of those points.

What is the equation to determine a best fit line? How would I do that with PHP?

like image 633
davethegr8 Avatar asked Dec 13 '08 00:12

davethegr8


People also ask

What is the fit equation?

Fitting an equation to data is the process of finding a linear, quadratic, exponential, or any other sort of function whose graph includes, or comes as close as possible to, a given set of data in the form of ordered pairs.

What does the equation of line of best fit mean?

The line of best fit estimates a straight line that minimizes the distance between itself and where observations fall in some data set. The line of best fit is used to show a trend or correlation between the dependent variable and independent variable(s). It can be depicted visually, or as a mathematical expression.


1 Answers

Here's an article comparing two ways to fit a line to data. One thing to watch out for is that there is a direct solution that is correct in theory but can have numerical problems. The article shows why that method can fail and gives another method that is better.

like image 52
John D. Cook Avatar answered Oct 21 '22 15:10

John D. Cook