Re: [R] Fourier Analysis and Curve Fitting in R

From: Spencer Graves <spencer.graves_at_pdf.com>
Date: Mon, 28 Jan 2008 19:03:31 -0800

The 'fda' package supports fitting finite Fourier series with examples in 'canadian-weather.R' and 'gait.R' in the 'demo' subdirectory of '~R\library\fda\fda'; see also 'fda-ch01.R' in the 'scripts' subdirectory. Also, the 'percur' funcction in the 'DierckxSpline' package supports fitting periodic splines.

stephen sefick wrote:
> well if you want to find the spectral density aka what frequencies
> explain most of the variance then I would suggest the spectral
> density. This can be implemented with spec.pgram(). This is
> conducted with the fast fourier transform algorithm.
>
>> a<-ts(data, frequency = 1) #make the time series with 365readings/365days
>> ?spec.pgram
>>
> and you should be able to take it from here
>
> This will give you the raw periodogram and the dominant frequencies
> after you smooth the periodogram. If your intention is to just fit a
> curve to your data there are many types of cuve fitting options moving
> average etc.
>
> What are you trying to do find the dominant periodicy? make a
> prediction equation? fit a smooth line? or...
>
> give us some more information and maybe we can help
>
>
> On 1/28/08, Carson Farmer <cfarmer_at_uvic.ca> wrote:
>
>> Rolf Turner wrote:
>>
>>>> On 26/01/2008, at 10:54 AM, Carson Farmer wrote:
>>>>
>>>>
>>>>> Dear List,
>>>>>
>>>>> I am attempting to perform a harmonic analysis on a time series of snow
>>>>> depth, in which the annual curve is essentially asymmetric (i.e. snow
>>>>> accumulates slowly over time, and the subsequent melt occurs relatively
>>>>> rapidly). I am trying to fit a curve to the data, however, the actual
>>>>> frequency is unknown.
>>>>>
>>> In general the actual frequency of the curve will indeed be close to
>>> 1/(1 year). However, because I intend to perform this analysis on many
>>> regions, this will not always be the case. This is perhaps an
>>> acceptable assumption however...
>>>
>>>> Obviously there is something I am not understanding here.
>>>> I would have thought that the ``actual frequency'' would
>>>> be 1/(1 year) (period = 1 year) --- modulo the fact that
>>>> the length of the year is constantly changing a tiny bit.
>>>> (But I would've thought that this would have no practical
>>>> impact in respect of any observed series.)
>>>>
>>>>
>>> My sampling interval is daily.
>>>
>>>> What is your sampling interval, BTW? Day? Week? Month?
>>>>
>>>>> I have been trying to follow the methods in Peter
>>>>> Bloomfields text "Fourier Analysis of Time Series", but am having
>>>>> trouble implementing this in R.
>>>>>
>>> Yes it certainly would.
>>>
>>>> Note that even though the ``actual frequency'' is (???) 1/(1 year),
>>>> the representation of the mean function in terms of sinusoids
>>>> will involve in theory infinitely many terms/frequencies since
>>>> the mean function is clearly (!) not a sinusoid.
>>>>
>>>>
>>>>> Does anyone have any suggestions, or perhaps directions on how this
>>>>> might be done properly? Am I using the right methods for fitting an
>>>>> asymmetric curve?
>>>>>
>>> What I am really trying to do is fit a relatively smooth line to my
>>> data which will preferentially weight the larger values. This method
>>> needs to be able to fit through data gaps however, which is why I was
>>> originally looking to fit sinusoids. A jpg of a single year of the
>>> data is available here:
>>> <http://www.geog.uvic.ca/spar/carson/snowDepth.jpg> to give you an
>>> idea of the shape of my curve.
>>> Thank you again for your help,
>>>
>>> Carson
>>>
>>>> I would have to know more about what you are *really* trying
>>>> to do, and what the data are like, before I could make any
>>>> useful suggestions. Many modelling issues could come into
>>>> play, and many modelling strategies are potentially applicable.
>>>>
>>>> cheers,
>>>>
>>>> Rolf Turner
>>>>
>>>>
>> ______________________________________________
>> 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. Received on Tue 29 Jan 2008 - 03:07:35 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 Tue 29 Jan 2008 - 03:30:09 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