Derivation of Line of Best Fit

In summary, the conversation discusses finding the best coefficients A and B for a linear equation that represents a set of data points. This is done by minimizing the sum of squared vertical distances of the data from the line of best fit. The derivatives of the sum are set to zero in order to find expressions for A and B in terms of the data points. This method is known as the least squares method and is used to minimize the deviation of the straight line from the data points. The process involves taking partial derivatives and solving two linear equations for A and B.
  • #1
tmobilerocks
25
0

Homework Statement


Consider a set of data points: (x1, y1), (x2,y2). One seeks to find the best coefficients A and B such that the sum of squared vertical distances of the data f(x) = Ax + B is minimized. Let D = ∑[yi - f(xi]2. By requiring the derivatives of D respect to both A and B each to vanish, find expressions for the values of A and B in terms of the data points. Why are these derivatives made to vanish?

Homework Equations


Line of best fit is a linear equation: f(x) = Ax + B
D must be a minimum

The Attempt at a Solution


I am totally lost by this question. I do not understand how to differentiate D with respect to these parameters (maybe implicit differentiation?)
 
Physics news on Phys.org
  • #2
You have ##D(A, B) = [y_1 - f(A, B, x_1)]^2 + [y_2 - f(A, B, x_2)]^2 ##. ##x_1, x_2, y_1, y_2## are all known and constant, ##A, B## are unknown variables.
 
  • #3
Am I supposed to differentiate D? How would I go about doing that?
 
  • #4
tmobilerocks said:
Am I supposed to differentiate D? How would I go about doing that?

Yes, that is what you are supposed to do. First, though, you need to express ##D## in more explicit form; just use the equation for ##f(x)## at ##x = x_1## and ##x = x_2## to get a sum that contains ##A, B## in fairly simple form. At that point you are supposed to know what to do next, using what you learned in calculus 101.

Are you sure you copied the problem correctly? For just two points you don't need to bother with this "least squares" method; it works, but is unnecessary. However, if you had more than two points you would soon discover the value of the method. BTW: it is almost as easy to do with 1000 points as with two points; all that happens is that you need to evaluate bigger sums. Try it out to see what I mean.
 
  • #5
Consider the following: If f(x) = Ax + B and D = ∑[yi - f(xi]2, then

[tex]D=\sum_{i=1}^n(y_i-Ax_i-B)^2[/tex]
Take the partial derivative of D with respect to A and set it equal to zero.
Take the partial derivative of D with respect to B, and set it equal to zero.
Combine the coefficients of A and of B in the resulting equations.
Solve for A and B.

What you are doing is minimizing the deviation of the straight line from the data points (where the data points have experimental error, and thus do not all lie on anyone straight line).
 
  • #6
Is this correct?

I took the partial of D with respect to A, and set it equal to zero. I obtained the result

0 = -2xiyi + 2Axixi - 2Bxi

I then took the partial of D with respect to B, and set it equal to zero. The result I obtained was

0 = -2yi + 2Axi + 2B

After combining these two expressions, and solving for A and B I obtained:

A = (-xiyi + yi -Bx - B)/(xi-xixi)

B = (-xiyi + yi - Axi + Axixi)/(1+x)
 
  • #7
I do not see how you solved for A and B if both sides of the equation contain them.
 
  • #8
Am I on the right track? Is there a simpler way to solve this? Combining both of them makes it nearly impossible to solve
 
  • #9
What is so impossible about that?

The first equation can be rewritten as ## 0 = p + q A + r B ##, where ##p, q, r ## are all made of the known ##x_i, y_i## values. The second equation can be rewritten as ## 0 = u +v A + w B ## in a similar way. Surely you can then solve two linear equations for A and B.
 
  • #10
tmobilerocks said:
Is this correct?

I took the partial of D with respect to A, and set it equal to zero. I obtained the result

0 = -2xiyi + 2Axixi - 2Bxi

I then took the partial of D with respect to B, and set it equal to zero. The result I obtained was

0 = -2yi + 2Axi + 2B

After combining these two expressions, and solving for A and B I obtained:

A = (-xiyi + yi -Bx - B)/(xi-xixi)

B = (-xiyi + yi - Axi + Axixi)/(1+x)

In the following two equations, you need to have summation signs on each of the terms, where the summations are over all the data points.

0 = -2xiyi + 2Axixi - 2Bxi

0 = -2yi + 2Axi + 2B

Once you get the summations in there, you factor out the A and B, and solve these two equations for the two unknowns A and B.

Chet
 

Related to Derivation of Line of Best Fit

What is the "Line of Best Fit"?

The Line of Best Fit is a straight line that represents the trend or pattern in a set of data points. It is used to show the overall relationship between two variables, usually the independent variable (x) and the dependent variable (y).

Why is it important to find the Line of Best Fit?

Finding the Line of Best Fit allows us to make predictions and draw conclusions about a data set. It also helps to identify any outliers or anomalies in the data that may affect the overall trend.

How is the Line of Best Fit calculated?

The Line of Best Fit is calculated using a method called linear regression, which finds the equation of a straight line that minimizes the distance between the line and all the data points. This equation can then be used to plot the line on a graph.

What is the difference between a positive and negative slope in the Line of Best Fit?

A positive slope means that as the independent variable (x) increases, the dependent variable (y) also increases. A negative slope means that as the independent variable (x) increases, the dependent variable (y) decreases. Both types of slopes indicate a relationship between the two variables, but in opposite directions.

How can you determine the strength of the relationship between two variables using the Line of Best Fit?

The strength of the relationship between two variables can be determined by calculating the correlation coefficient, also known as r. This value ranges from -1 to 1, with 1 indicating a strong positive relationship, 0 indicating no relationship, and -1 indicating a strong negative relationship.

Similar threads

  • Calculus and Beyond Homework Help
Replies
3
Views
444
  • Calculus and Beyond Homework Help
Replies
2
Views
805
  • Calculus and Beyond Homework Help
Replies
22
Views
2K
  • Calculus and Beyond Homework Help
Replies
24
Views
2K
  • Calculus and Beyond Homework Help
Replies
4
Views
2K
  • Precalculus Mathematics Homework Help
Replies
17
Views
1K
  • Calculus and Beyond Homework Help
Replies
1
Views
906
  • MATLAB, Maple, Mathematica, LaTeX
Replies
14
Views
2K
  • Set Theory, Logic, Probability, Statistics
Replies
2
Views
658
  • Calculus and Beyond Homework Help
Replies
12
Views
3K
Back
Top