[R] Sine Regression in R

David Winsemius dwinsemius at comcast.net
Mon Dec 20 22:02:06 CET 2010


On Dec 20, 2010, at 3:01 PM, Paolo Rossi wrote:

> Hi everyone,
>
> I am trying to fit a sine function on one year of wind data. I have  
> two
> questions below.
>
> Looking around on the net I managed to get the following:
>
> Sine Equation: y = a + b * sin( c + d*x )
>
> b is the amplitude, c is the phase shift, d is something deal with
> periodicty of data*.*
>
> This can be linearised by   sin( c+dx ) = cos(c) * sin(dx) + sin(c) *
> cos(dx).
>
> If one calls dx = x1
>
> y = a + b * sin( c + d*x )
> y = a + b * [cos(c) * sin(x1) + sin(c) * cos(x1)]
> y = a +  b * cos(c) * sin(x1) + b * sin(c) * cos(x1)
> y = a +  b1 * sin(x1) + b2 * cos(x1)
>
> where b1 = b * cos(c) and  b2 =  b * sin(c)
>
> This works fine for me as I am not interested in the value for b and  
> c. By
> trial and error I also detemined that the sensibel value for d is  
> 1/58. I
> have 366 days of data and want to fit a single sine onto it.
>
> *First question*: 1/ 58 = (2 pi) / 366. I guess 366 is the period of  
> my
> data, I have 366 days. so *d = (2 pi) / Period*. Is this correct.
> *Second question*: I reckon that all of this looks very DIY. Is  
> there a
> better way to do this in R? Maybe through a package I dont know?

The package "circular" might be a candidate.

>
>
> Thanks in advance
>
> Paolo
>


David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list