Message Boards Message Boards

1
|
4806 Views
|
5 Replies
|
5 Total Likes
View groups...
Share
Share this post:

Question about time series and autocorrelation function

Posted 3 years ago

Hi everyone,

I have calculated the autocorrelation function for Istanbul's monthly rainfall data. The value of this function has reached zero at lag 3.

How do I extract the list of time series for lag1,lag 2, and lag 3 separately? I would like to use these time series as input for prediction modeling.

data0 = WeatherData["Istanbul", 
  "TotalPrecipitation", {{1970, 1, 1}, {2018, 1, 31}, "Month"}]

Istanbul = QuantityMagnitude[data0["Values"]];

ListLinePlot[Istanbul, PlotRange -> All];

ListPlot[CorrelationFunction[Istanbul, {20}], Filling -> Axis, 
 PlotRange -> All]

enter image description here

POSTED BY: Alex Teymouri
5 Replies
Posted 3 years ago

Here is one way (not very efficient for long lists)

list = {15, 18, 10, 13, 16, 14, 29, 55};
lag = 3;

lags = Table[ArrayPad[list, {j, 0}, NA], {j, 0, lag}]
lags[[All, lag + 1 ;; Length@list]]
POSTED BY: Rohit Namjoshi
Posted 3 years ago

Hi Alex,

Isn't the lag n time series just this?

Istanbul[[n + 1 ;;]]
POSTED BY: Rohit Namjoshi
Posted 3 years ago

Thank you so much, Rohit.

Let me say my question through the below image with a simple list:

Really I appreciate your help.

enter image description here

POSTED BY: Alex Teymouri
Posted 3 years ago

Hi Alex,

The creation of additional lists can be avoided by generating the correct Spans.

list = {15, 18, 10, 13, 16, 14, 29, 55};
lag = 3;
length = Length@list

Table[list[[lag + i ;; length + i - 1]], {i, 1, 1 - lag, -1}]

Encapsulated in a function

ClearAll@lagWindow
lagWindow[list_List, lag_?Positive] /; Length@list > lag :=
  Module[{length = Length@list},
  Table[list[[lag + i ;; length + i - 1]], {i, 1, 1 - lag, -1}]]
POSTED BY: Rohit Namjoshi

That's an awesome solution.

I should say extracting the lag time series is very important in water engineering. Thank you so much, Rohit.

You are always great :)

POSTED BY: M.A. Ghorbani
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract