Re: [R] Fit a sine to data

From: Peter Dalgaard <P.Dalgaard_at_biostat.ku.dk>
Date: Fri, 23 May 2008 17:00:40 +0200

Juan Manuel Barreneche wrote:
> i guess nls or gnls should work....
>
Yes. Notice though that this is really a linear problem because of the trigonometric identity

sin(x+b) = cos(b) * sin(x) + sin(b) * cos(x)

which means that you can reparametrize c*sin(x+b) (you forgot the multiplier, did you not?) as

A*sin(x)+B*cos(x)

It is easy to invert the reparametrization if you notice that A^2 + B^2 = c^2, but it may be expedient to use the nonlinear functions to get confidence itervals for a,b,c.
> JM
>
> El Viernes, 23 de Mayo de 2008 10:47, Zroutik Zroutik escribió:
>
>> Dear R-users,
>>
>> I'd like to fit a sine function to my data. The result should have a format
>> (and thus the formula, too)
>>
>> y ~ a + sin(x+b)
>>
>> where y and x are vectors, and a and b are (yet) unknown values.
>>
>> The data sets (vectors x and y) are OK, and I can do a simple lm fitting
>> lm(y~x), or lm(y~I(sin(2*pi*x/360))), succesfully My issue is that I'm not
>> able to do the optional linear shift in x (e.g. x+b). What other
>> possibilities should I use instead of lm? I looked searched the R-seek for
>> terms: fit, sine, lm, and combinations, but I could not find anything
>> useful. Anybody would be so kind and point me to the right direction where
>> I can find other fitting possibilities?
>>
>> Thank you for listening and kind answers upfront.
>>
>> Regards,
>> Milan
>>
>> [[alternative HTML version deleted]]
>>
>> ______________________________________________
>> R-help_at_r-project.org mailing list
>> 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.
>>
>
> ______________________________________________
> R-help_at_r-project.org mailing list
> 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.
>

-- 
   O__  ---- Peter Dalgaard             Øster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark      Ph:  (+45) 35327918
~~~~~~~~~~ - (p.dalgaard_at_biostat.ku.dk)              FAX: (+45) 35327907

______________________________________________
R-help_at_r-project.org mailing list
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.
Received on Fri 23 May 2008 - 16:07:53 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 23 May 2008 - 17:30:39 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive