# [Limdep Nlogit List] Fitting a constrained sin function

Bjorn Lardner lardnerb at usgs.gov
Tue Jul 20 13:07:41 EST 2010

```Dear LIMDEP users,

I’m looking for advice on how to fit a sinusoidal function to a data set.

Here’s an outline of our problem. We have a dependent variable explained
by several variables, and we have collected data over several years. In
addition to the independent variables that are clearly defined, we suspect
that there might be a regular, seasonal (time-of-year) effect that could
be modeled as a sinusoidal function. The min (or max) of that function
could occur at any time of the year – we have no preconceived notion about
that – and to incorporate a seasonality in our main model, we need to know
what sin phases translate to what time-of-year (lunar dates). Think of it
as sliding a sin function along the x-axis to find the best fit.

Perhaps the simplest way to address the possibility of such a seasonal
effect would be to first find a good linear multiple regression model with
only the ‘known’ variables, and in a second step try to fit a sinus
function to the residuals produced by the model. [Once we have found the
phase of the seasonal effect, we can then create a “season” variable to
add to our main data set, and compare support for models with and without
the seasonality aspect.] Because the residuals from the multiple
regression will have a mean of zero, the sin function will oscillate
around the x-axis; this simplifies the model. But a complicating issue is
that we want to *force* the function to have a frequency such that one
year equals a full 360 degree period. I am not sure how to achieve that.

Any advice on what LIMDEP commands to use for fitting a model like
described above would be much appreciated.

Also - and here it becomes a bit more complex – we would greatly benefit
from the opportunity to test for a trend over time in the sin function’s
baseline level (e.g., in case residual values from the multiple regression
start to oscillate around negative y-values, then gradually increase over
time to oscillate around positive y-values) by adding a linear or
quadratic term to the model. This is described on
http://en.wikipedia.org/wiki/Sinusoidal_model    where a linear
increasing/decreasing baseline over time function is simply described by
the (B0 + B1Ti) expression in the equation,

Yi = (B0 + B1Ti) + αsin(2πωTi + φ) + Ei        (I hope the symbols show up
as anticipated...)

Grateful for hints on how we, in terms of LIMDEP commands, may incorporate
that expression into the more basic model.

Sincerely,
Bjorn Lardner / ecologist

```