I need to interpolate a linear trend surface through a number of points but with the condition that the surface has to pass exactly through one of them. Can somebody give me any advice?

  • $\begingroup$ I would like to know what criterion for "best fit" you are using (or what application requirements are imposed). Doing a least squares fit and finding the nearest point to the trend surface would be one way to pick the point. You then can redo the least squares fit with one fewer parameter to get "an answer". $\endgroup$ – hardmath Dec 28 '12 at 13:32
  • 1
    $\begingroup$ Thank you hardmath for your quick reply. I am using least squares fit, can you explain me your advice with an example? $\endgroup$ – fparaggio Dec 28 '12 at 13:45
  • $\begingroup$ @hardmath: Suppose the free best fit happens to pass through more than one point. You decide somehow that one particular one among them is the one. Do you then just rotate the entire solution about that point by adding independent infinitesimals to each coefficient? The clearer you avoid the additional points, the worse will the overall fit be. $\endgroup$ – Henning Makholm Dec 28 '12 at 14:04
  • $\begingroup$ @HenningMakholm: If the free (we're assuming ordinary least squares ) best fit happens to pass through one or more observations, then we are done, at least in terms I outlined above. As I understand it, the requirement is only to have a plane passing through any one of the points. $\endgroup$ – hardmath Dec 28 '12 at 14:18
  • $\begingroup$ @hardmath: Edit: Oops, I see now it says "exactly through one", not "through exactly one". Forget I said anything, then. $\endgroup$ – Henning Makholm Dec 28 '12 at 14:20

Let me begin with the usual cautionary note about least-squares fitting, that it is unduly sensitive to data points that have larger errors.

A special case (to which the general case is easily reduced) of forcing a fitted plane to pass through a point is to make it pass through the origin. The phrase "regression through the origin" is often used to describe this case. An erudite but readable account is here.

The ordinary least-squares fit would use a model that includes a constant term:

$$ f(x,y) = ax + by + c $$

and our objective would be to minimize for given observations $(x_i,y_i,z_i)$ the sum of squared errors $\sum_i (z_i - f(x_i,y_i))^2$.

Regression through the origin means omitting the parameter $c$ (setting the constant term to zero). Naturally with one less parameter we typically would have a larger least-squares error.

If we know which data point we want the trend plane to pass through, say $(x_0,y_0,z_0)$, then we can transform the data by subtracting that point from every other observation:

$$ (u_i,v_i,w_i) = (x_i,y_i,z_i) - (x_0,y_0,z_0) $$

and performing "regression through the origin" (RTO) on this transformed data set.

Because the suggestion is to do ordinary least-squares (OLS) fitting first in order to pick a "base point", we will derive the normal equations for that case and note that for RTO these reduce (simplify) by essentially omitting the constant term. That is, the OLS objective function:

$$ \sum (z_i - ax_i - by_i - c)^2 $$

gives by partial differentiation wrt the model parameters $a,b,c$ a system of three linear equations in those unknowns:

$$ \begin{pmatrix} \sum x_i^2 & \sum x_i y_i & \sum x_i \\ \sum x_i y_i & \sum y_i^2 & \sum y_i \\ \sum x_i & \sum y_i & \sum 1 \end{pmatrix} \begin{pmatrix} a \\ b \\ c \end{pmatrix} = \begin{pmatrix} \sum x_i z_i \\ \sum y_i z_i \\ \sum z_i \end{pmatrix} $$

Once the OLS parameters are found, we check to see which observation $(x_i,y_i,z_i)$ has the least error $| z_i - f(x_i,y_i) |$. Using that as our base point, the transformed data described above by subtracting the base point from the other observations would give an RTO problem for two equations in two unknowns:

$$ \begin{pmatrix} \sum u_i^2 & \sum u_i v_i \\ \sum u_i v_i & \sum v_i^2 \end{pmatrix} \begin{pmatrix} a \\ b \end{pmatrix} = \begin{pmatrix} \sum u_i w_i \\ \sum v_i w_i \end{pmatrix} $$

Of course this RTO solution would then get translated back to the original coordinates by adding the base point to its formula.

If there is a small data set you'd like to see me use, post a Comment. Otherwise I can make one up for the sake of illustration.

Example: Suppose we wish to fit these data points:

(59, 64, 10.91) (75, 52, 10.38) (86, 73, 10.6) (88, 53, 10.56)

with a plane passing through (69, 76, 10.00). Translating the latter to the origin transforms the other four points into:

(-10, -12, 0.91) ( 6, -24, 0.38) (17, -3, 0.6) (19, -23, 0.56)

Using an ad hoc Excel spreadsheet I calculated the appropriate sums to compute RTO for these transformed data:

$$ \begin{pmatrix} 786 & -512 \\ -512 & 1258 \end{pmatrix} \begin{pmatrix} a \\ b \end{pmatrix} = \begin{pmatrix} 14.02 \\ -34.72 \end{pmatrix} $$

Solving this system gives (to display accuracy) $a = -0.00019, b = -0.02768$. Putting things back in terms of the original coordinates means this is the best (least squares) fit with a plane through (69, 76, 10.00):

$$ z_{fit} = 10.00 - 0.00019(x - 69) - 0.02768(y - 76) $$

The fit doesn't seem very good, although adding 10 to each z-coordinate tends to obscure that. The fitting errors in z at the four data points are:

$$ z_i - z_{fit} = 0.575951, -0.28311, 0.520231, -0.07294 $$

and the sum of squared errors is $0.687829$.

  • $\begingroup$ @hardmah thank you for your explanation. A small set of data could be this one: { 59, 64, 10.91 }; { 75, 52, 10.38 };{ 86, 73, 10.6 }; { 88, 53, 10.56 }. the plane should pass through {69, 76, 10.00 } $\endgroup$ – fparaggio Dec 28 '12 at 18:52
  • $\begingroup$ @fparaggio: Okay, I didn't understand that you would already have picked out a base point. That saves a step. $\endgroup$ – hardmath Dec 28 '12 at 19:13
  • $\begingroup$ @hardmah sorry for that.. let's say { 59, 64, 10.91 }; { 75, 52, 10.38 };{ 86, 73, 10.6 }; { 88, 53, 10.56 },{69, 76, 10.00 } the plane should pass through {69, 76, 10.00 } $\endgroup$ – fparaggio Dec 28 '12 at 19:14
  • $\begingroup$ i understand that my english caused some misunderstanding. Sorry and thank you for your very helpful reply. $\endgroup$ – fparaggio Dec 28 '12 at 21:34

For a given point as the one the line passes through, you have a single parameter of solutions, the slope. If the given point is $(x_0,y_0)$, the lines passing through it are $y=y_0+m(x-x_0)$ If you want the best fit in a least squares sense, let the data be $(x_i,y_i)$ with $i$ ranging from $1$ to $n$. We want to minimize $\sum_{i=1}^n (y_i-y_0-m(x_i-x_0))^2$ Taking the derivative and setting to zero gives $0=2\sum_{i=1}^n (y_i-y_0-m(x_i-x_0))(x_i-x_0)$ so $$m=\frac{\sum_{i=1}^n (y_i-y_0)(x_i-x_0)}{\sum_{i=1}^n (x_i-x_0)^2}$$

I would just do this calculation for each point, and take the answer with the lowest sum squared error.

  • $\begingroup$ thank you or your reply. The problem i am trying to solve is into three dimension. The plane have to pass through the point $(x_0,y_0,z_0)$ $\endgroup$ – fparaggio Dec 28 '12 at 16:02
  • $\begingroup$ @fparaggio: The same approach works. You can define the slope of $z$ vs $x$ at constant $y$ and the slope of $y$ vs $x$ at constant $z$. These two parameters will give you two equations in two unknowns that you can solve. $\endgroup$ – Ross Millikan Dec 28 '12 at 17:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.