# Determining a correction factor and applying it to a second set of numbers

1st- I would like to figure out the correction factor between two sets of numbers (time series).

2nd- I want to apply that correction factor to a second set of numbers.

As an example- say I have two temperature sensors, and I place them in the same exact environment. Even though they should be reading the same temperature, I can expect a little bit of offset due to error between the sensors. Something like:

Sensor 1 Sensor 2
10            10
10             9
11            11
12            11.8
13            12.9
14            13.9


It looks like Sensor 2 consistently reads a little low (or conversely that Sensor 1 reads a little high). Since I don't know the actual temperature this is a relative problem.

So start, I'm not sure about the best way to figure out the correction factor. It's pretty easy to run a regression analysis or a correlation analysis by plotting an x y scatter plot and calculating a best fit line. But, I'm not sure if this is the way to go.

But the real question is that once I figure out this correction factor, how do I apply it to a second set of numbers in a way that will reflect the error associated with the first set of numbers (basically that sensor 2 is reading slightly lower than sensor 1).

To continue the above example, say I take the same two sensors, but now place them in different environments where they will be exposed to different temperatures. Now I have a second set of numbers (below) from the same instruments but no longer reading the same temperature. How do I relate the original correction factor to a set of numbers from different environments.

Sensor 1 Sensor 2
10            13
11            14
12            14
12            14
13            14


For the first set of numbers the regression analysis yields the equation y=1.0925x -1.3125.

My initial thoughts were that I could use the regression equation from the first set of numbers as my correction factor, and then apply that to the second set of numbers in order to adjust them to account for the inherent error of the sensors.

But since the sensors are now in two different environments, I can no longer just plug numbers into a y=mx+b type linear regression equation.

I also thought about adjusting the second set of data by just adding the y intercept value to sensor 2, but this obviously does not work as the y intercept is too large in this case. So I think I have been barking up the wrong tree.

So I'm not sure if a regression analysis is the way to go. But in the end, all I'm looking for is a way to quantify the error between the two sensors (as found in the first set of numbers) and then apply that to all future deployments.

-
I think you should start with examining how the disagreement between the sensors depend on the temperature. Plot the difference between the two readings against the sum of them. –  ttnphns Aug 18 '12 at 16:39

I am not sure whether you are interested in estimating the temperature or whether you want to know what the value of sensor 2 would be for a given value of sensor 1.

Still, I think that the tool you need is total least squares (TLS), also known as orthogonal regression. Contrary to normal linear regression, where you assume that all the error is the $Y$ variable, in orthogonal regression, you assume there is an error on both variables. This picture from the Wikipedia link above shows the difference: the error is assumed to be orthogonal to the regression line (and not vertical). If you are familiar with Principal Component Analysis (PCA), the orthogonal regression line is the first principal component of your dataset.

There seems to be no TLS function in R, so the easiest is actually to do it by PCA. It can go like this.

X <- c(10, 10, 11, 12, 13, 14)
Y <- c(10, 9, 11, 11.8, 12.9, 13.9)
pca <- prcomp(cbind(X,Y))
# Error (residual variance).
pca[['sdev']][2]^2  # 0.05581165
PC1 <- pca[['rotation']][,1]
# Estimated temperatures.
cbind(X,Y) %*% PC1
# Y / X slope from the point (mean(X), mean(Y)).
PC1[['Y']] / PC1[['X']]  # 1.115854


This means that you can model your system as $(Y - \bar{Y}) = 1.116 \cdot (X - \bar{X})$ or $Y = 1.116 \cdot X + (\bar{Y} - 1.116 \cdot \bar{X})$ if you need $Y$ as a function of $X$.

-
If the regression only involves one independent variable x then orthogonal regression assumes the error variance in both x and y are the same. Otherwise for the error in variables model the direction to minimize the squared difference is in a different direction than orthogonal to the line. –  Michael Chernick Aug 18 '12 at 18:00
Thanks for the answer. And I apologize if this seems like a simplistic question, but what should I do with the answer (the 1.115854 value) should I add it to one of the columns of data? Or should I do something else with it? Thanks! –  Vinterwoo Aug 27 '12 at 19:21
Sorry for answering late. I added the last line to clarify how you can use the result. –  gui11aume Sep 27 '12 at 18:24