# 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

## 2 Answers

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

If the difference between the sensors is basically a constant plus an independent error term the regression model could be applied. What is not clear though is whether or not the difference changes in magnitude as a function of the actual temperature. This would probably show up as a change in the residual variance as a function of temperature or the slope of the line.

The fact that the slope is slightly greater than 1 indicates that the difference increases a little as the temperature increases. However even if the assumptions required for the regression approach to be valid you should use a lot more than 5 observations to fit the model and estimate the offset (correction) for sensor 2 assuming sensor 1 is correct.

-
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 5, "mathjax_display_tex": 0, "mathjax_asciimath": 0, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "github"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "english_confidence": 0.9214383959770203, "perplexity_flag": "head"}