Hi! I would like to fit a function to my data, and the function comprises two parts: a Gaussian component, and then a more complicated background component. The overall form looks like this:
Gaussian component is typically quite narrow, but the second component (beginning from parameter [3]) starts beneath the Gaussian and then extends quite far beyond. I would like to set the function to have parameter [4] equal to parameter [1] plus a constant. However, I also want parameter 1 to be varied only within the Gaussian component, so I think I cannot simply re-write the formula replacing [4] with [1]+const. If I do the replacing, I think it will adjust parameter [1] outside of the Gaussian fit, based on the quality of the fit in the second component. Is there a way to impose such a constraint?
Thanks to everyone in advance for any help!
P.S. I had a look at other threads on these forums, but I think they don’t answer the last part of my question, which is how to keep the fitting changes to parameter [1] constrained only to the first part of the function.
Hello @Nsos,
thanks for reaching out!
I am not sure that want you want to do makes sense, all the parameters are real valued and the relation is linear, you can you do the fit without introducing the constraint and then compute your const as [1]-[4]…
Monica
Hi, thanks for getting back to me! To clarify, I don’t want to compute the constant, as I know what it is. It’s more that I want to vary the mean of the Gaussian fit (among other parameters), but I want to set parameter [4] to always be a constant (known) offset relative to that mean (i.e. parameter [1]). However, I suspect that if I re-write the above formula, replacing [4] with, for example, [1] + 2, then the fit of the Gaussian mean will be adjusted to reflect fit quality outside of the Gaussian based on the performance of the second half of the function.
To add further context, I am actually fitting this complicated function to two different regions of my data, and there is a component of the first-region fit under the second-region fit. For this reason, I want to fix the fit parameters as much as possible relative to the more easily-accessible Gaussian component, which I want to vary freely.
I am not sure if I have well understood your situation, I would say in this case you would use a piecewise function as model for your fitting so you can separate the two regions.
Anyway, I add in the loop our fitting expert @jonas
Perhaps a diagram would help. I show in black my data, which I am fitting. My fitting function produces a Gaussian component in red and also a background component in blue, which I want to be offset relative to Gaussian fit mean by a constant c (which is known). As mentioned, I repeat the fit twice (hence two red parts and two blue parts in the diagram). For the first Gaussian with a mean mu-1, I cannot directly fit the blue component, since it’s obscured by the second Gaussian with mean mu-2. For this reason, blue component fit of the first part of the function has to be heavily-constrained, and I want its x-coordinate (parameter [4]) to depend on parameter [1] (i.e. mu-1) without affecting the parameter-[1] fit.
I don’t want to compute the constant, as I know what it is
However, I suspect that if I re-write the above formula, replacing [4] with, for example, [1] + 2, then the fit of the Gaussian mean will be adjusted to reflect fit quality outside of the Gaussian based on the performance of the second half of the function.
here is where you’re contradicting yourself. You first say that you don’t know the constant, but then you rightfully say that you don’t know it exactly because it depends on the quality of the fit.
So, how much do you really know about this constant? If it’s really constant because your theory tells you so, then your model should implement that, and it’s correct that the second half of the function will impact the Gaussian peak best fit value.
But if there are some experimental effects that result in systematic uncertainties which “smear” this constant a bit, then you can’t treat it as fixed anymore, at least if you want to treat your systematic uncertainties correctly. Are there some control measurements that you can do to assess this systematic effect? If yes, you can consider adding a Gaussian constraint term for the offset. This is very common for such experimental “nuisance parameters”. Or even a box constraint.
If you have no way to assess the systematic effect, then maybe you have to bite the bullet and keep the offset parameter floating. Ultimately it’s a decision that should also be impacted by what other systematic effects you have, and if you expect this one to play a non-negligible role compared to the other already-considered effects.
Hi jonas, thank you very much for your reply and your considerations. Perhaps I am not sure I convey my issue accurately here. I have posted a diagram of my issue in a comment above, but I think that happened shortly before your post. In the diagram above, you can see that the blue component corresponding to the first Gaussian (i.e. the one on the left with mean of mu-1) is completely covered by the second Gaussian, and therefore cannot be fit reliably. However, as you say, from other measurements I know the value of constant c by which I need to offset accurately. Furthermore, I have similar knowledge of other parameters pertaining to the blue curve relative to the Gaussian (I discussed parameter [4] specifically only as a convenient example). Therefore, I would like to constrain the parameters of the blue component of the fit relative to the red component based on these a priori known conditions. However, I do not want the fit of the Gaussia to in any way reflect how well the fit does for the blue component. Is this addressing what you suggest? My apologies if not.