views:

105

answers:

2

Given the following 2d points:

213 106.8

214 189

214 293.4

213 324

223 414

I want to find an equation for the least squares vertical axis line that runs through them. My plan is to get a line equation so I can test subsequent points for their distances to that least squares line.

Thanks

A: 

If you want the line of best fit to be vertical (i.e. x = constant), the y-values are irrelevant. Simply take the square root of the mean of the squares of the x-values.

Mick Sharpe
That's not correct. Suppose all the X-es are negative...
Jim Lewis
Oops! You're quite right.
Mick Sharpe
+2  A: 

Strictly speaking, a least squares fit is not defined for a vertical line (since the error for each point is measured parallel to the Y axis).

However, if you swap X and Y, you can find the horizontal line with the best least squares fit. It works out to simply the mean of the Y coordinate values:

The equation for a horizontal line is simply y = b.

The error at each point (xi, yi) is (yi - b).

The sum of the squares of the errors is SSE = sum( (yi - b)2). We wish to find the value of b that minimizes SSE. Take the partial derivative of SSE with respect to b and set it to zero:

sum(-2(yi - b)) = 0

Simplifying,

sum(yi) - Nb = 0

and

b = sum(yi)/N

So in your case, averaging the X coordinates gives you the X coordinate of the vertical line that best fits your points.

Jim Lewis
thank you very much!
Glad to help, and welcome to StackOverflow!
Jim Lewis