Re: [R] adjusting a periodical function to a time series

About this list Date view Thread view Subject view Author view Attachment view

From: Adrian Trapletti (adrian.trapletti@lmttrading.com)
Date: Wed 19 Mar 2003 - 22:35:06 EST


Message-id: <3E7855EA.7A04695A@lmttrading.com>


> Subject: [R] adjusting a periodical function to a time series
> Date: Wed, 19 Mar 2003 11:35:37 +0100
> From: Hagen Schmöller<Hagen.Schmoeller@iaew.rwth-aachen.de>
> To: <r-help@stat.math.ethz.ch>
>
> Hi R-Community,
>
> is there a possibility to adjust a periodical function like
>
> s(t) = a1 sin(f1 t) + b1 cos(f1 t) + a2 sin(f2 t) + b2 cos(f2 t) + ...
>
> to a time series with R, if necessary with given frequencies fi.
>
> Much thanks in advance,
>
> Hagen Schmoeller
> --
> Dipl.-Ing. Hagen K. Schmöller
> Institut für Elektrische Anlagen und Energiewirtschaft, RWTH Aachen
> Schinkelstraße 6, D-52056 Aachen, Germany
> Tel.: +49 (0)241 80-96734
> Fax : +49 (0)241 80-92197
> Hagen.Schmoeller@iaew.rwth-aachen.de

Maybe something like this:

data(lh)
y <- lh
t <- 1:length(y)

err <- function(par)
{
    x <- par[1]+par[2]*sin(t)+par[3]*cos(t)
    sum((y-x)^2)
}

op <- optim(c(0,0,0), err)

op$par

plot(lh)

lines(op$par[1]+op$par[2]*sin(t)+op$par[3]*cos(t), col="red")

best
Adrian

--
Dr. Adrian Trapletti             Phone :             +41 (0) 1 994 5631
Trapletti Statistical Computing  Mobile:             +41 (0)76 370 5631
Wildsbergstrasse 31              Fax   :             +41 (0) 1 994 5631
CH-8610 Uster                    Email :  mailto:a.trapletti@bluewin.ch
Switzerland                      WWW   : http://trapletti.homelinux.com

______________________________________________ R-help@stat.math.ethz.ch mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help


About this list Date view Thread view Subject view Author view Attachment view

This archive was generated by hypermail 2.1.3 : Tue 01 Jul 2003 - 09:11:25 EST