[R] newbie: fourier series for time series data

eddie smith eddieatr at gmail.com
Thu Jun 2 06:05:26 CEST 2011


Hi Spencer and Mike,

Thank you very much! I never expect to get 3 replies in one day. You all are
really helpful. While I am struggling reading all the documents suggested,
here is the data. Maybe this will help to clear up what I am intending to
do.

Thank in advance guys.

Eddie

On Tue, May 31, 2011 at 10:39 PM, Mike Marchywka <marchywka at hotmail.com>wrote:

>
> ( hotmail won't mark text so I'm top posting... )
>
> Can you post the data? Personally I'd just plot abs(fft(x))
> and see what you see, as well as looking at Im(fft(x))/Re(fft(x))
> or phase spectrum. Now, presumably you are nominally looking
> for something with a period of 1 year, that part could
> be expressed in harmonic specrum as suggested below, but you'd
> also be looking for trends and noises of various types- additive
> gausssian, amplitude modulation, maybe even frequncy modulation, etc.
> I guess you could remove a few power terms ( average, linear, etc)
> just to simplify ( often you get this spectrum with huge uniformative
> DC or zero frequency component just gets in the way). You can probably
> find book online dealing with signal processing and RF ( this is where
> I'm used to seeing this things). It would of course be helpful to
> then examine known simple cases and see if you can tell them apart.
> Create fft( sin(t)*(1+a*sin(epsilon*t)+b*t ) for example.
>
>
> I guess if you want to look at writing a model, you could look at
> phase portrait ( plot derviative versus value ) to again get some idea what
> you may have that makes sense as model to fit.
>
>
>
> ----------------------------------------
> Date: Tue, 31 May 2011 10:35:16 -0700
> From: spencer.graves at structuremonitoring.com
> To: eddieatr at gmail.com
> CC: r-help at r-project.org
> Subject: Re: [R] newbie: fourier series for time series data
>
>
> On 5/31/2011 5:12 AM, eddie smith wrote:
> > Hi Guys,
> >
> > I had a monthly time series's data of land temperature from 1980 to 2008.
> > After plotting a scatter diagram, it seems that annually, there is a semi
> > sinusoidal cycle. How do I run Fourier's series to the data so that I can
> > fit model on it?
>
> There are several methods.
>
>
> 1. The simplest would be to select the number of terms you
> want, put the data into a data.frame, and use lm(y ~ sin(t/period) +
> cos(t/period) + sin(2*t/period) + cos(2*t/period) + ..., data),
> including as many terms as you want in the series. This is not
> recommended, because it ignores the time series effects and does not
> apply a smoothness penalty to the Fourier approximation.
>
>
> 2. A second is to use the 'fda' package. Examples are
> provided (even indexed) in Ramsay, Hooker and Graves (2009) Functional
> Data Analysis with R and Matlab (Springer). This is probably what
> Ramsay and Hooker would do, but I wouldn't, because it doesn't treat the
> time series as a time series. It also requires more work on your part.
>
>
> 3. A third general class of approaches uses Kalman
> filtering, also called dynamic linear models or state space models.
> This would allow you to estimate a differential equation model, whose
> solution could be a damped sinusoid. It would also allow you to
> estimate regression coefficients of a finite Fourier series but without
> the smoothness penalty you would get with 'fda'. For this, I recommend
> the 'dlm' package with its vignette and companion book, Petris, Petrone
> and Campagnoli (2009) Dynamic Linear Models with R (Springer).
>
>
> If you want something quick and dirty, you might want option 1.
> For that, I might use option 2, because I know and understand it
> moderately well (being third author on the book). However, if you
> really want to understand time series, I recommend option 3. That has
> the additional advantage that I think it would have the greatest chances
> of acceptance in a refereed academic journal of the three approaches.
>
>
> > I am really sorry for my question sound stupid, but I just don't know
> where
> > to start.
>
> There also are specialized email lists that you might consider
> for a future post. Go to www.r-project.org
> -> "Mailing Lists". In particular, you might be most interested in
> R-sig-ecology.
>
>
> Hope this helps.
> Spencer Graves
>
> > I am desperately looking for help from you guys.
> >
> > Thanks in advance.
> >
> > Eddie
> >
> > [[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 guidehttp://
> www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
>
>
> --
> Spencer Graves, PE, PhD
> President and Chief Operating Officer
> Structure Inspection and Monitoring, Inc.
> 751 Emerson Ct.
> San José, CA 95126
> ph: 408-655-4567
>
>
> [[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.
>
>
-------------- next part --------------
Land Temperature (1982 to 2008)

Year	Jan	Feb	Mac	Apr	Mei	Jun	Jul	Aug	Sep	Oct	Nov	Dis
1982	27.73	27.51	27.80	28.08	28.51	28.45	28.06	27.89	27.94	28.15	28.20	28.17
1983	27.79	27.56	27.77	28.32	28.40	28.62	28.32	28.16	28.54	28.74	28.65	28.05
1984	27.76	27.54	27.79	28.28	28.67	28.50	28.34	28.18	28.54	28.52	28.42	28.01
1985	27.54	27.65	27.83	28.31	28.53	28.54	28.28	28.12	28.28	28.43	28.59	28.21
1986	27.71	27.44	27.65	28.22	28.63	28.64	28.49	28.19	28.12	28.38	28.37	28.00
1987	27.67	27.24	27.74	28.29	28.77	28.67	28.35	28.29	28.32	28.59	28.72	28.25
1988	28.08	28.01	28.31	28.60	28.95	28.91	28.74	28.67	28.79	28.89	28.66	28.11
1989	27.94	27.65	27.83	28.39	28.65	28.73	28.71	28.45	28.59	28.69	28.58	28.04
1990	27.68	27.69	27.84	28.30	28.70	28.63	28.56	28.42	28.21	28.51	28.45	27.97
1991	27.61	27.40	27.63	28.23	28.53	28.65	28.53	28.33	28.20	28.21	28.13	27.85
1992	27.49	27.51	27.71	28.26	28.58	28.68	28.32	28.28	28.34	28.33	28.03	27.78
1993	27.36	26.99	27.44	27.91	28.32	28.56	28.34	28.08	28.17	28.15	28.42	28.06
1994	27.66	27.71	27.80	28.29	28.58	28.63	28.31	28.01	28.03	28.18	28.28	28.07
1995	27.74	27.51	27.67	28.28	28.67	28.81	28.71	28.69	28.69	28.80	28.83	28.32
1996	27.84	27.63	27.88	28.41	28.68	28.94	28.90	28.69	28.79	28.99	28.80	28.35
1997	27.72	27.63	27.71	28.31	28.63	28.69	28.37	28.01	28.11	28.43	28.38	28.40
1998	27.89	27.96	28.18	28.70	29.08	29.17	29.18	29.13	29.21	29.30	29.23	28.74
1999	28.38	28.12	28.41	28.76	28.89	28.85	28.62	28.38	28.63	28.91	28.82	28.44
2000	28.12	27.86	28.02	28.64	28.81	28.78	28.47	28.53	28.65	28.93	29.02	28.54
2001	28.26	28.02	28.28	28.76	29.09	29.24	28.83	28.62	28.77	28.98	28.85	28.36
2002	27.91	27.73	28.12	28.74	29.09	29.09	28.66	28.41	28.46	28.68	28.83	28.50
2003	28.02	27.83	28.03	28.63	28.92	28.78	28.76	28.59	28.66	28.94	28.78	28.33
2004	27.95	27.80	28.08	28.67	28.93	28.68	28.50	28.17	28.38	28.50	28.64	28.38
2005	27.93	27.85	28.05	28.43	28.87	28.87	28.80	28.54	28.62	28.91	28.87	28.49
2006	28.00	27.82	27.96	28.44	28.82	28.83	28.47	28.20	28.41	28.23	28.57	28.48
2007	28.03	27.83	27.97	28.37	28.82	29.09	28.78	28.51	28.59	28.76	28.65	28.48
2008	28.01	27.87	27.93	28.46	28.54	28.58	28.43	28.38	28.69	28.94	28.92	28.55


More information about the R-help mailing list