Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Discrete fourier transform on time series in R

I would like to use discrete Fourier transform to identify dynamic of sales and then cluster similar patterns. However, I'm new in using R and after searching for a solution, I found a prodecure fft(), but not exactly sure if I get the same result as for DFT. I would like to present waves on a plot and then use an algorithm to cluster similar sales dynamics. What's more, I was wondering if I can use procedure fft to transform all time series, not one by one (so suggest R: transform new time series after 26 weeks - look at the database)

http://imageshack.com/a/img854/1958/zlco.jpg piece of my database; three columns: Product - present the group of product Week - time since launch the product (week), first 26 weeks Sales_gain - how the sales of product change by weeks

http://imageshack.com/a/img703/6726/sru7.jpg that's how my time series looks like

I believe that I can use fft() to eventually accomplish this goal however the leap from the output of fft() to my goal is a bit unclear.

Please note that I am relatively new to time series analysis (that's why I cannot put here my code) so any clarity you could provide w.r.t. putting the output of fft() in context, or any package you could recommend that would accomplish this task efficiently would be appreciated

like image 298
user3463225 Avatar asked Nov 10 '22 10:11

user3463225


1 Answers

From ancient memory you should square the real part to get the spectrum which gives you the magnitude at each frequency (days in your example)

x = some data
plot(Re(fft(x))^2)
like image 191
user3472874 Avatar answered Nov 15 '22 07:11

user3472874