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 <http://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@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@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.