# Minimisation of specific residuals

#### humic

##### New Member
Hello,

I hope that I can finde someone here to help me with the following problem:

I have 11 points with x and y values. Those points are following more or less a linear trend. What I would like to do now is to choose two of those points and perform a linear regression on those two points plus three other points (choosen in a way that the residuals of those two points are minimised). I am performing this task with the solver-addIn from excel. Afterwards I am trying to minimise those residuals even further by trying different weighing factors for the regression (1/sqrt(x), 1/x,.. ).

The question is now if I can from a mathematical point of view really find the lowest residuals this way? Or would I have to test the different weighing factors for all possible combinations of points? Or is there somehow an even better way to do this?

From the beginning I would like to say that I am not a mathematician but a chemist, so pardon if I said/asked something stupid.

humic

#### humic

##### New Member
I hope I was able to explain my problem in an understandable way,..

humic

#### Dason

I didn't quite understand what you're trying to do and audio why you're trying to do it

#### humic

##### New Member
Ok I will try to make it clearer.

As I said I have 11 points with known x and y values which follow approximately a linear distribution (calibration points). additionally I have some data in the form of just y values, for which i would like to find out the according x value (data).
I could now just perform a linear regression on my 11 points and put the y values of my data into the linear equation. However, that would not give me necessarily the most precise solution as there can be systematic and random errors in the calibration points e.g. the relative error will be bigger for lower x values or the the fitted calibration line might not be linear over the whole calibration-range (x-value-range). Additionally I don't need all 11 points in my calibration line.
So what I would like to try now is to come up with a linear calibration which is most suitable for each of my data (given in y-values). My idea is to take the two calibration points which are closest to my y-value of interest (one below one above) and try to minimise their residual^2 under the preassumption that they are no spikes (by the way I am not sure yet how to test for the case of one of those two beeing a spike).
I would like to perform this minimisation by choosing 5 points out of my 11 calibration points. I am doing that in a way that the residual's of those two calibration points is the smallest possible. The second way I would like to minimise them is to weight the regression by a weighing faktor (like 1/x, 1/x^2,..).
What I do not understand is if it makes more sense to try all the different weighted regressions first on all 11 calibration points and choose afterwards 5 points with the regressionmodel which turned out beeing the best (judged by the two residuals of interest) or if it is better to do it the other way around (first choose points and then a weighing faktor for those points)

Hope I could make it more clear
humic

#### Dason

So you want to use y to predict x? Typically we talk about using x to predict y. It's a silly matter of notation but I just want to make sure we're on the same page. If that's the case you would want to fit the regression x = ay+b+e if your goal is to minimize the residuals with respect to x.

I'm not touching the weighting issue yet because I'm not sure I completely understand what you're doing there.

#### humic

##### New Member
Yes exactly (where my x values are those on the abscissa and my y values are those on the ordinate (to exclude misunderstanding))

I would like to fit the regression y=kx+d (as I have learned it with slope k and intercept d) then i would calculate the residual^2 for the two points of interest from the fitted line and try to minimise them

#### humic

##### New Member
As an example:
if those are my calibration points:
x y
16 0.000284823
31 0.000565006
63 0.000761496
125 0.001493622
250 0.002524203
500 0.005001656
1000 0.009350613
1250 0.012722195
2500 0.02281249
5000 0.043519136
10000 0.096365585

and I am interested in the prediction of x for the y-value 0.041245861, I would choose the calibration points with the x values 2500 and 5000 and try to reduce their residuals^2.

Therefore I would either perform a simple linear regression model (like excel fits it by default) on 5 of those points which lead to lowest residual^2 for those two points and then try if I can further minimise the resiual^2 by using weighting factors for the regression or I would do it the other way around.