# Least-square fitting to data (sine function) : what is the error of the derived fit parameters?

I have a set of data. I want to fit it to a sine function of the form : $$$$f(x)=A sin(\omega x+B)+C$$$$ I use the least-square method to find the appropriate fit-parameters which are $$A$$, $$B$$ and $$C$$. In this method, each term of the cost-function has a weight calculated from the error-bar of each point in my dataset.

Now I want to calculate the visibility $$V$$ for the fitting curve. The visibility is defined by : $$$$V=\frac{A}{C}$$$$

I obtain a good value of $$V=0.95$$, but now I want to know how to calculate $$\Delta V$$, the error of the visibility. To get it, I need to know $$\Delta A$$ and $$\Delta C$$.

Do you know how to do it ?

EDIT : Some people suggested to post the data, so here is the figure on the link below. Figure representing the data

Basically, each point has a poissonnian error bar $$\Delta Y= \sqrt{Y}$$. I did the weighted least-square method to obtain my fit-function which is the solid line you can see on this plot (there is two data-set actually, red and blue). The area in red/blue represent standard deviation of the distance in errorbar unit from the datapoints to the fit, multiplied by the poissonian error $$\sqrt{Y}$$ [I don't know if this is okay, maybe it's false to do like that].

• Basically I need to know how to get the uncertainties on A and C (because $V=A/C$). I will edit my question. Jun 3, 2019 at 14:40
• Would you mind post your example of data. Concret example is useful to evaluate the difficulty of your problem and well understand it. Jun 3, 2019 at 15:24
• Yes I edited my question Jun 4, 2019 at 8:59
• If this is not a school work, I suggest you use a professional tool. Jun 4, 2019 at 9:42

This fitting problem can be equivalently rewritten as fitting function of form:

$$f(x) = K \sin(\omega x) + L \cos(\omega x) + C$$

And your original $$A$$ is just $$A =\sqrt{K^2+L^2}$$

This reduces it to just ordinary least squares problem. We get least squares estimators for $$K,L$$ from the equation

$$\begin{bmatrix} K \\ L \\ C \end{bmatrix} = (X^TX)^{-1}X^{T}y$$

Where $$X$$ is matrix formed by values of $$\sin(\omega x),\cos(\omega x), 1$$ evaluated at consecutive values of $$x$$ coordinate of your observations and $$y$$ are values of said observations.

This way you can see that $$K,L$$ are some linear functions of $$y_i$$. I'm not sure what Poissonian error bar is but in general finding variance of sum of variables can be done if we know variance of individual variables.

Assuming $$y_i$$ uncorrelated we get:

$${Var}(K) = (1,0,0) . (X^TX)^{-1}X^{T} . Var(y_i)$$

and analog for $$L$$.

And $$C$$ is even simpler as it is just the mean value of the observations.

This way we have found $$Var(K),Var(L),Var(C)$$ assuming these are small enough you can just propagate error in the formula

$$V = \frac{\sqrt{K^2+L^2}}{C}$$

either by direct computation or using this helpful lookup.

• $X$ is called design matrix. Maybe that will help with the coding part. Jun 4, 2019 at 9:55
• That is exactly what I was looking for, thank you ! Jun 4, 2019 at 12:30
• Your linear method is not convenient. You use an unknown value of $\omega$ to compute the matrix $X$. With this method one cannot compute the value of $\omega$. In fact the equation $f(x) = K \sin(\omega x) + L \cos(\omega x) + C$ is not linear with respect to $\omega$. One have to use a more sophisticated method in case of non-linear equation. Jun 4, 2019 at 18:44
• @JJacquelin OP literally said that only the amplitude was unknown implying that $\omega$ was known and fixed. If you want to fit $\omega$ it is a completely different problem. (Indeed a non-linear, and by some measure harder one). Jun 4, 2019 at 19:09
• From the picture uploaded looks like the domain of $x$ is $[0,2\pi)$ so $\omega$ is probably just $1$. Jun 4, 2019 at 19:10