Basic doubts about measurements and fitting

  • #1
Felipe Lincoln
Gold Member
99
11

Homework Statement


Let's say I'm doing a experiment in order to measure a resistance of a single resistor of 200 ohm by its V against I graph, where V is the voltage in the resistor's terminal given by and voltmeter and I the current of the circuit, given by and ammeter. The angular coefficient in ##y=ax+b## must be the resistance.
OK, I'll proceed this way: apply a voltage of 0.5V: write down what I read in the voltmeter and the ammter. lift the voltage to 0.75, write down the voltage in resistor and current, and so on until 5V. By doing this I'll get a list o data with uncertainty given by my instruments, let's assume it is 5% of the displayed value. So for every data I have a different error associated.
Now I plot voltage against current and the respective error bars. Now I want to do the linear fitting of these data. When I do this with python I get an array with the coefficients and another which is the covariance matrix. I can get the error of each coefficient through this matrix, but the linear fitting never asked for the error bars, the errors given by the fitting isn't related to the error of my measurements. So my question is what is the relation between the error given by the fitting and the error by the measurement, isn't it related ? If so, why should I care about the measurement uncertainty once the fitting will give it's own error?

Homework Equations




The Attempt at a Solution



[Sorry, I don't know how to apply these kind of question in this formulary...][/B]
 

Answers and Replies

  • #2
tnich
Homework Helper
1,048
336

Homework Statement


Let's say I'm doing a experiment in order to measure a resistance of a single resistor of 200 ohm by its V against I graph, where V is the voltage in the resistor's terminal given by and voltmeter and I the current of the circuit, given by and ammeter. The angular coefficient in ##y=ax+b## must be the resistance.
OK, I'll proceed this way: apply a voltage of 0.5V: write down what I read in the voltmeter and the ammter. lift the voltage to 0.75, write down the voltage in resistor and current, and so on until 5V. By doing this I'll get a list o data with uncertainty given by my instruments, let's assume it is 5% of the displayed value. So for every data I have a different error associated.
Now I plot voltage against current and the respective error bars. Now I want to do the linear fitting of these data. When I do this with python I get an array with the coefficients and another which is the covariance matrix. I can get the error of each coefficient through this matrix, but the linear fitting never asked for the error bars, the errors given by the fitting isn't related to the error of my measurements. So my question is what is the relation between the error given by the fitting and the error by the measurement, isn't it related ? If so, why should I care about the measurement uncertainty once the fitting will give it's own error?

Homework Equations




The Attempt at a Solution



[Sorry, I don't know how to apply these kind of question in this formulary...][/B]
Is this really a hypothetical question, or do you have some results you can show us?
 
  • #3
Ray Vickson
Science Advisor
Homework Helper
Dearly Missed
10,706
1,728

Homework Statement


Let's say I'm doing a experiment in order to measure a resistance of a single resistor of 200 ohm by its V against I graph, where V is the voltage in the resistor's terminal given by and voltmeter and I the current of the circuit, given by and ammeter. The angular coefficient in ##y=ax+b## must be the resistance.
OK, I'll proceed this way: apply a voltage of 0.5V: write down what I read in the voltmeter and the ammter. lift the voltage to 0.75, write down the voltage in resistor and current, and so on until 5V. By doing this I'll get a list o data with uncertainty given by my instruments, let's assume it is 5% of the displayed value. So for every data I have a different error associated.
Now I plot voltage against current and the respective error bars. Now I want to do the linear fitting of these data. When I do this with python I get an array with the coefficients and another which is the covariance matrix. I can get the error of each coefficient through this matrix, but the linear fitting never asked for the error bars, the errors given by the fitting isn't related to the error of my measurements. So my question is what is the relation between the error given by the fitting and the error by the measurement, isn't it related ? If so, why should I care about the measurement uncertainty once the fitting will give it's own error?

Homework Equations




The Attempt at a Solution



[Sorry, I don't know how to apply these kind of question in this formulary...][/B]
In a fairly standard statistical model, the errors in your fit embody information about the errors in your measurements. If we assume that the expected sizes of the errors are independent of ##x## and that different measurements yield statistically independent, zero-mean errors, then the simple linear model is
$$y_i = \alpha + \beta x_i + \epsilon_i, \;\; i = 1,2, \ldots, n.$$
Here, the parameters ##\alpha## and ##\beta## are some unknown values that we want to estimate, and the errors ##\epsilon_1, \epsilon_2, \ldots, \epsilon_n## an independent sample of mean-zero random variables. For example, these might be your measurement errors.

The simplest case is where the statistical distributions of all the different ##\epsilon_i## are the same, so they all come from a single distribution---but are independent random "draws" from that distribution. (Your case of errors that depend on ##x## is a bit more involved, so let's forget about that for now.)

It turns out the the least-squares fit --- the fit that minimizes ##S = \sum_i (a+b x_i - y_i)^2## --- produces unbiased estimates of ##\alpha## and ##\beta.## What does that mean? Well----in any particular run of the experiment you might get a value of ##a## that is too large compared to ##\alpha##, but in some other run you might get a value that is too small. Similarly for ##b## vs. ##\beta.## If you were to repeat the experiment many times (all at the same ##n## values of ##x_i##) you would get a random "sample" of different ##a##-values that would cluster about some central value, and that central value would be ##\alpha## exactly. Therefore, on average, ##a## would estimate ##\alpha## without any systematic bias. Similarly for ##b## vs. ##\beta.## In a single run of the experiment, your best bet is to take ##a## as your estimate of ##\alpha## and ##b## as your estimate of ##\beta.##

So, where do your "original" errors ##\epsilon_i## come in? Well, they are estimated by the "fitted errors" ##e_i = y_i - a - b x_i.## If ##S^* =## minimum value of ##S## above (so is obtained by plugging your solution for ##a,b## into the formula for ##S##), it turns out that ##S^*## is an estimate of ##(n-2) \sigma^2##, where ##\sigma^2## is the variance parameter for the distribution of the errors ##\epsilon##.

As I said already, things are more complicated if the different ##\epsilon_i## are independent, but come from different distributions, as in your conjectured case where the error distribution varies with the value of ##x##.
 
Last edited:
  • Like
Likes Felipe Lincoln
  • #4
haruspex
Science Advisor
Homework Helper
Insights Author
Gold Member
2020 Award
35,577
6,449
the errors in your fit embody information about the errors in your measurements.
Up to a point.
Consider this extreme situation: the changes in current are so small compared with the gradations on the meter that all readings are the same. Now the fit is perfect. Only the error bars embody the information for the accuracy of the result.
While that is extreme it does illustrate the principle.
Likewise, in the heteroscedastic scenario proposed in post #1 (reading error proportional to value in this case), the error bars can handle this but a fit based purely on the readings will not.

Setting the error bar issue aside and just trying to deal with the heteroscedasticity, it might be not that hard to weight the values. It is complicated by the b term in ax+b. Is the uncertainty to be considered as proportional to x or as proportional to y?
 
  • Like
Likes Felipe Lincoln
  • #5
Felipe Lincoln
Gold Member
99
11
I think I got it.
In the case I proposed the error increases with x, so if we get points close to 0 and others too far from origin, the error bar would be greater, so in this case I would have more of an accuracy error than a precision error? Since the error is 5%, we could have the instrument taking the measurements 5% lower than it actually is, right?
 
  • #6
haruspex
Science Advisor
Homework Helper
Insights Author
Gold Member
2020 Award
35,577
6,449
I think I got it.
In the case I proposed the error increases with x, so if we get points close to 0 and others too far from origin, the error bar would be greater, so in this case I would have more of an accuracy error than a precision error? Since the error is 5%, we could have the instrument taking the measurements 5% lower than it actually is, right?
If you are supposing a percentage error in the instrument, it matters whether you consider it to be independent with each measurement or, more likely, systematic. E.g. if one reading is 2% high then it suggests they all are. That would not be representable by error bars in the plot, and certainly would not be hinted at by the goodness of fit of the regression line. You would instead apply that to the coefficient "a" at the end of your calculations.

One practical point relating to this specific experiment: resistance is affected by temperature. Unless you take steps to keep the resistor at constant temperature your readings may be affected by the order in which they are taken and the duration of each test.
 
  • Like
Likes Felipe Lincoln
  • #7
haruspex
Science Advisor
Homework Helper
Insights Author
Gold Member
2020 Award
35,577
6,449
For what it's worth, if we have measurements (xi, yi) and each yi is considered to be independently subject to a normally distributed error with variance σi2 then we can apply standard regression formulae for y=ax+b but using (Σyiwi)/Σwi in place of Σyi, (Σxiyiwi)/Σwi in place of Σxiyi, etc., where wi=1/σi2.
That gives the unbiased estimates for a and b, but I have not tried to estimate the error in these.
 
  • Like
Likes Felipe Lincoln
  • #8
Felipe Lincoln
Gold Member
99
11
It's all more clear now! :biggrin:
Thank you all
 

Related Threads on Basic doubts about measurements and fitting

  • Last Post
Replies
7
Views
183
  • Last Post
Replies
2
Views
1K
  • Last Post
Replies
1
Views
1K
Replies
5
Views
702
Replies
12
Views
284
  • Last Post
Replies
10
Views
932
  • Last Post
Replies
7
Views
1K
  • Last Post
Replies
10
Views
355
  • Last Post
Replies
1
Views
207
Top