Skip to main content
Became Hot Network Question
edited title
Link
user64494
  • 1
  • 4
  • 29
  • 60

measurement Measurement error propagation onto fitting-parameters (using NonLinearModelFit)

added 6 characters in body
Source Link

I have a dataset consisting of (t,y) Tuples, where each y has a known measurement error (standard deviation). I would like to fit a trapaze-function into the data and obtain the fitting paramaters and propagate the measurement errors onto those paramters. I was able to do the fitting but I can't managage to do the error propagation and I don't understand the methods used by NonLinearModelFit to calculate such errors, since the documentation is very vague. Since error propagation is a very standard procedure in exactphysical sciences I think that there shoud be some way to accomplish this with mathematica (for fits).

I found this guide: https://reference.wolfram.com/language/howto/FitModelsWithMeasurementErrors.html[enter link description here]3https://reference.wolfram.com/language/howto/FitModelsWithMeasurementErrors.html[FitModelsWithMeasurementErrors][3] which fits to my problem reletivelyrelatively well.

I have a dataset consisting of (t,y) Tuples, where each y has a known measurement error (standard deviation). I would like to fit a trapaze-function into the data and obtain the fitting paramaters and propagate the measurement errors onto those paramters. I was able to do the fitting but I can't managage to do the error propagation and I don't understand the methods used by NonLinearModelFit to calculate such errors, since the documentation is very vague. Since error propagation is a very standard procedure in exact sciences I think that there shoud be some way to accomplish this with mathematica (for fits).

I found this guide: https://reference.wolfram.com/language/howto/FitModelsWithMeasurementErrors.html[enter link description here]3 which fits to my problem reletively well.

I have a dataset consisting of (t,y) Tuples, where each y has a known measurement error (standard deviation). I would like to fit a trapaze-function into the data and obtain the fitting paramaters and propagate the measurement errors onto those paramters. I was able to do the fitting but I can't managage to do the error propagation and I don't understand the methods used by NonLinearModelFit to calculate such errors, since the documentation is very vague. Since error propagation is a very standard procedure in physical sciences I think that there shoud be some way to accomplish this with mathematica (for fits).

I found this guide: https://reference.wolfram.com/language/howto/FitModelsWithMeasurementErrors.html[FitModelsWithMeasurementErrors][3] which fits to my problem relatively well.

Source Link

measurement error propagation onto fitting-parameters (using NonLinearModelFit)

I have a dataset consisting of (t,y) Tuples, where each y has a known measurement error (standard deviation). I would like to fit a trapaze-function into the data and obtain the fitting paramaters and propagate the measurement errors onto those paramters. I was able to do the fitting but I can't managage to do the error propagation and I don't understand the methods used by NonLinearModelFit to calculate such errors, since the documentation is very vague. Since error propagation is a very standard procedure in exact sciences I think that there shoud be some way to accomplish this with mathematica (for fits).

An overview over the data: (the time values on the x-Axis are not displayed properly, the total time interval in which the data was aquired is about 0.5) data with errors

The fitted function and the parameters used: fitted function and the used parameters What I was able to do/find out:

I was able to do the fitting using NonLinearModelFit using the following model:

model=Piecewise[{{F+(FTransit-F)/(t2-t1)*(x-t1),t1<=x<t2}, {FTransit,t2<=x<t3},{FTransit+(F-FTransit)/(t4-t3)*(x-t3),t3<=x<t4}},F]; nlmVC=NonlinearModelFit[lightDataVCGraph,{model,{2.4597044744907`*^6<=t1<=2.4597046155903`*^6},{2.4597044744907`*^6<=t2<=2.4597046155903`*^6},{2.4597044744907`*^6<=t3<=2.4597046155903`*^6},{2.4597044744907`*^6<=t4<=2.4597046155903`*^6}},{{F,3.65},{FTransit,3.59},{t1,2.4597045370702376`*^6},{t2,2.4597045465046*10^6 +0.4},{t3,2.4597045465046*10^6 +0.2},{t4,2.45970457042957`*^6 +0.8}},x ]; 

In my understanding the "standard error" from the parameter table given by NonLinearModelFit via nlmVC[{"BestFit","ParameterTable"}]is the estimated standard deviation of the particular parameter from the model which I am interested in(correct?). Since I didn't give the fitting algorithm any measurement errors I assume that the "standard errors" are solely based on the goodness of the fit of the model and the sensitivity of the model considering the particular parameter.

Now I want to take into account that the y-part of each data touple has a measurement error/uncertainty, which should be propagated into the errors of the fitted parameters (and probably increase them according to th size of the errors).

What I found about how this is suggested to be done(optional if you know how it's done;D)

I found this guide: https://reference.wolfram.com/language/howto/FitModelsWithMeasurementErrors.html[enter link description here]3 which fits to my problem reletively well.

They suggest two things to incorporate the errors from the measurement:

  1. They input the measurement errors as weights into NonLinearModelFit by putting Weights -> 1/errors^2 into the options. In my understanding this weights the squared errors in the least squares-error function according to theire standard deviation/variance but does not change the way the "standard errors" of the parameters are computed. It minimally improves the fit(my errors are reletively constant) but does not change the obtained parameter errors from the fitting very much.

  2. They suggest setting VarianceEstimatorFunction->(1&) as an option in NonLinearModelFit.

To treat the weights as being computed from measurement errors, you can use the VarianceEstimatorFunction option in addition to Weights. VarianceEstimatorFunction explicitly defines the variance scale estimator that is used. For measurement errors, you want standard errors to be computed only from the weights and so the variance estimate should be the constant 1:<

According to this second guide: http://www.columbia.edu/~nas2173/tutorial.pdf this option "activates" the error propagation of the measurement errors (page 10 top) but doesnt explain how/why this works.

Now I dont understand what the variance estimator is in theory, why it should be set to constant 1 and how NonLinearModelFit should even get any information about the measurement errors since I only give it the weights which contain the errors only implicitely. I also dont understand why I would want the parameter errors to depend only on the measurement errors (which is apparently accomplished by this option). Shouldn't the parameter errors be influenced both by the measurement errors and the goodness of the fit of the model to this particular set of data?

The documentation of NonLinearModelFit and VarianceEstimatorFunction also do not explain how the error is propagated/what the VarianceEstimatorFunction does in this context. In the latter documentation the VarianceEstimatorFunction is defined:

With the setting VarianceEstimatorFunction->f, the variance scale is estimated by f[res,w] where res={y1-,y2-,…} is the list of residuals and w is the list of weights, as specified by the setting for the Weights option.` and they also suggest for data with measurement errors:

With VarianceEstimatorFunction->(1&) and Weights->{1/Δy12,1/Δy22,…}, Δyi is treated as the known uncertainty of measurement yi and parameter standard errors are effectively computed only from the weights.

but I still theoretically don't understand, why the second this is the option that makes NonLinearModelFit compute the parameter errors also from the measurement errors as I explained above.

I tried it out and it did not work: Also in practice the results are not convincing: I just tried out what the parameter errors are with not considering measurement errors, with weights, and with weights plus VarianceEstimatorFunction and they did not really change and even decreased in the last option, which is not plausile at all (they should increase due to added errors). In general the errors computed for "F","FTransit" should be way bigger since the data varies by about 0.2 on the y axis and the parameter error for FTransit is only 0.00326725 (have a look at the plot to see what I mean).

The parameters from the fit trying all 3 options (in the described order):

parameters with default options parameters with weighted fit parameters with weighted fit and using VarianceEstimatorFunction->(1&)

What I want to find out: So how is error propagation onto parameters done with mathematica for fitting nonlinear model functions? Why does the suggested method make sense (is it correct)? Why are the obtained errors so small and dont dont really change depending on if weights/VarianceEstimatorFunction is used? Is there any other way to solve this problem using Mathematica/another language?

TLDR: Managed to do a fit to measered data using NonLinearModelFit, now I want to propagate the measurement errors onto the parameters returned from the fit. As suggested by the documntation I tried using the options Weights -> 1/errors^2 and setting VarianceEstimatorFunction -> (1 &) which resulted in parameter errors that are propably too small. I also theoretically don't understand why this should do what I want.

How is error propagation onto fitting parameters done in mathematica, when using data with measurement errors?

Thanks in advance for helping me and all other people trying to do error analysis and fittings in mathematica.

I really appreciate your comments and the time you invest to help!