On Tue, 20 Jun 2017, lily li wrote:

Hi R users,

I have a question about fitting a cosine curve. I don't know how to set the
approximate starting values.

See

        Y.L. Tong (1976) Biometrics 32:85-94

The method is known as `cosinor' analysis. It takes advantage of the *intrinsic* linearity of y = a + b * cos( omega*t - c ), when omega is given.

It you are scratching your head saying 'that thing is not linear', you need to go back to your linear models text and review what `linearity' actually refers to. Also, reading the Tong paper is recomended as you will need the transformations given there in any case.

What you end up doing is fitting

        fit <- lm(y~cos(t.times.omega)+sin(t.times.omega))

and then transforming coef(fit) to get back a, b, and c. So, you only need to have omega. If it is not obvious what value to use, then that will be more of a challenge.

The paper gives asymptotics for the dispersion matrix of (a, b, c), I recall.

Besides, does the method work for sine curve as well?

Seriously? See

https://en.wikipedia.org/wiki/List_of_trigonometric_identities#Shifts_and_periodicity

HTH,

Chuck

______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to