Message-ID: <alpine.OSX.2.20.1706202046300.1717@charles-berrys-macbook.local>
Date: 2017-06-21T04:24:18Z
From: Charles C. Berry
Subject: fitting cosine curve
In-Reply-To: <CAN5afy8_J-nZz0jrr0=O4s=6r5iTMTaypg19jPgtfveOgMDw6g@mail.gmail.com>
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