I have 2000 samples of unevenly sampled timeseries data collected at 2 hour intervals over the course of 24 hours. Working in Python, I used scipy.optimize.curve_fit, which returned a sinusoidal function of the form $y = a * \sin({\pi \over 12} * x - b)+c$. I want to know how well this function fits the data using an F-test and use the F-statistic to return a p-value, which I would use to determine whether or not the data significantly follows a cyclical pattern over the course of 24 hours. I am unsure of how to run an F-test between the function and my data. What are the steps/calculations that would return to me an F value and eventually a P-value?

  • $\begingroup$ Your fitted model is non-linear so F-test assumptions are not applicable. Also can you check how is the model estimated? That might give some ways to explore about the inference methods applicable for such methods. $\endgroup$
    – Dayne
    Dec 27, 2021 at 4:43

1 Answer 1


You could try to use the following method.

$$y=a\sin \left[\dfrac{\pi}{12}x-b\right]+ c$$ $$=a\left[\sin \dfrac{\pi}{12}x \cos b - \sin b \cos \dfrac{\pi}{12}x \right] +c$$ $$=a\sin \dfrac{\pi}{12}x \cos b - a \sin b \cos \dfrac{\pi}{12}x +c$$

The last equation indicates that we can switch to new parameters $w_1 = a\cos b$, $w_2=-a\sin b$, and $w_0=c$. Additionally, we will introduce new basis functions $\Phi_1(x)= \sin \dfrac{\pi}{12}x$ and $\Phi_2(x)=\cos \dfrac{\pi}{12}x$.

Both modifications will lead to a multiple linear regression


with nonlinear basis functions $\Phi_1(x)$ and $\Phi_2(x)$. This type of regression will allow you to use everything that you know from linear regression. We can even write down the analytic least squares regression coefficients.

Note, that if you recover the $w$-coefficients with a least squares fit you will not obtain the coefficients for the initial nonlinear equation.

  • $\begingroup$ This still involves a nonlinear (trig) function of a regression parameter, so the regression is nonlinear. I do not see how this helps. Could you please clarify? $\endgroup$
    – Dave
    Dec 27, 2021 at 16:36
  • 1
    $\begingroup$ @Dave I do not imply to solve the original nonlinear regression problem. I rewrote the regression into a linearized form which permits a simple solution as it is linear. See the transformed regression in my edited post. It is linear in the $w$-parameters. $\endgroup$ Dec 27, 2021 at 23:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.