# Tag Info

## Hot answers tagged time-series

26

I had a go with HiddenMarkovProcess[], based on the assumption that the data is normally distributed around two different means (it looks like it!). This approach should be fine for cases where the number of "states" is small, e.g. 2 in this case. Otherwise you're looking at Infinite Hidden Markov Models, or see the bottom of this answer. To remove some ...

20

Based on @b.gatessucks answer and on @RahulNarain comment tip, I created this functions for the multiplicative decompose case. I changed @b.gatessucks method for seasonality to keep it closer from R method, and used TemporalData to easily handle time interval. decompose[data_,startDate_]:=Module[{dateRange,plot,plotOptions,observedData,observedPlot,...

18

This site has exactly what you want here, already in Mathematica code. One example here:

16

ListPlot@{l1, msf = MeanShiftFilter[l1, IntegerPart[Length@l1/10], MedianDeviation@l1, MaxIterations -> 10]} And here are the detected means (assuming there are three): fc = FindClusters[msf]; Mean /@ fc ( *{3.77282, 220.788, 387.444} *)

14

One of the new operations on TimeSeries objects is TimeSeriesWindow. I think it does what you need. ts = WeatherData["KP60", "Temperature", {{2013, 7, 1}, {2013, 9, 30}}]; DateListPlot[TimeSeriesWindow[ts, {{2013, 8, 1}, {2013, 8, 14}}]]

13

The following seems a little more elegant. data = Import["http://www.massey.ac.nz/~pscowper/ts/cbe.dat"]; ts = TemporalData[data[[2 ;; -1, 1]], {"1958", Automatic, "Month"}]; DateListPlot[ts["Path"]] TemporalData can also store multiple paths. ts2= TemporalData[Transpose[data[[2 ;; -1]]], {"1958", Automatic, "Month"}]; DateListPlot[ts2["Paths"]]

12

You could use RunScheduledTask or its relatives for this. For example, to append a random integer to catch once every two seconds you could do something like catch = {}; task = RunScheduledTask[AppendTo[catch, RandomInteger[10]], 2]; You could also use CreateScheduledTask which is similar to RunScheduledTask except that the task won't be started ...

11

While you come back with a version 9 solution here is an old school approach : The first entry is labels so I removed it : rawData = Import["http://www.massey.ac.nz/~pscowper/ts/cbe.dat"][[2 ;;]]; Added the dates to the imported data : they are monthly dates starting {1958, 1, 1} : data = Transpose[{NestList[DatePlus[#, {1, "Month"}] &, {1958, 1, 1},...

11

So this generates the heatmap: << Calendar` year = 1990; yearLen = DaysBetween[{year, 1, 1}, {year, 12, 31}] + 1; data = RandomReal[1, yearLen]; days = Map[DayOfWeek[{year, 1, #}] &, Range[3, 9]]; day1 = Position[days, DayOfWeek[{year, 1, 1}]][[1, 1]]; dayn = Position[days, DayOfWeek[{year, 12, 1}]][[1, 1]]; Paddata = Join[ConstantArray[100, day1 -...

11

The links provide you with everything you need I think. The goal of this answer is to show you that even though it's not built in, a discrete STFT is quite easy and short to code. This would take the DFT of the data set partitioned into chunks of length 2^13, with half a window overlap, and a rectangular window STFT[r_]:= Fourier /@ Partition[r, 2^13, 2^12]...

11

There are basically two methods. The first is to use the ARProcess function (or ARMAProcess or ARIMAProcess as needed) introduced in version 9. The answers to this question should be helpful. Here is a small example that modifies the example in the documentation to show how to plot the resulting TemporalData using DateListPlot rather than ListPlot: you ...

11

The only elegant thing I've found that can be done for this question is the shifting of the time series with TimeSeriesShift to help get the answer. {pepsi, mcds} = TimeSeries[FinancialData[{"NYSE", #}, "Price", {DateObject[{2012, 12, 31}], DateObject[{2015, 3, 31}], "Week"}]] & /@ {"PEP", "MCD"} Get to time series. TimeSeriesShift will shift ...

11

Another approach is to use compound median filtering which returns a blocky function. Then threshold the jumps between blocks. No assumptions about the number or size of blocks is made. Function to plot the input series as discrete jumps. BlockPlot[s_] := Partition[ Flatten[{s[[1]], Table[{{s[[i, 1]], s[[i - 1, 2]]}, s[[i]]}, {i, 2, ...

11

TimeSeries[Rest[input]] works directly without having to go through an association. If you really need to make an association: assoc = Inner[#2 -> #1 &, Rest[input], First[input], Association]. From there: TimeSeries[Values[assoc]]. TimeSeriesMapThread[] is useful for detrending: ts = TimeSeries[Rest[input]]; trend = LinearModelFit[ts, {1, x, x^2}, x]...

10

The three best-known tests for stationarity (or rather, unit roots) in time series econometrics are: Dickey-Fuller including Augmented Dickey-Fuller Phillips-Perron KPSS There are also Bayesian tests of unit roots, as implemented in this conference presentation. If you have access to JSTOR or another way of getting at old journals, this article might be ...

10

Generating an autoregressive time series is not the same as "finding" it, since you have the parameters. If I understand you correctly, this is an application made for FoldList: Here is a simple AR(1) process to illustrate the technique: FoldList[c1 #1 + #2&, x0, RandomVariate[NormalDistribution[0,1],{100}] For example FoldList[0.9 #1 + #2 &, 0....

10

Here are two approaches. We'll create a second dataset by shifting the given data by two months: blossom = {{4, 3}, {4, 22}, {4, 15}, {4, 2}, {4, 18}, {4, 20}, {4, 12}, {3, 30}, {4, 4}, {4, 24}, {4, 26}, {3, 4}, {4, 26}, {4, 13}, {5, 1}, {4, 4}, {4, 8}, {4, 18}, {4, 9}, {4, 19}, {4, 10}, {4, 20}, {4, 3}, {4, 4}, {3, 21}, {4, 19}, {4, 15}, {...

10

This is as designed but an argument could be made for making some tweaks to it. The driving concern was to preserve options (e.g. ResamplingMethod) where it makes sense. If options are contained in one and only one object that option is kept as is. If an option is shared among objects the combined object inherits the first occurrence (MetaInformation for ts1 ...

9

Here is another way of obtaining the positions of reversals using Reap-Sow and MapIndexed. I've used a longer ts than yours to demonstrate multiple reversals. ts = {1, 2, 3, 5, 10, 8, 6, 3, 5, 7, 4, 3, 2, 1, 6, 9, 5}; Module[{max = -Infinity}, MapIndexed[ (max = Max[max, #1];If[max - #1 == 4, Sow[#2]; max = -Infinity;]) &, ts ]; ] // ...

9

If the points were regularly spaced you could use Datarange: ListPlot[{28, 32, 37, 66}, DataRange -> {300, 1440}] However, they aren't spaced regularly, so in one way or another you have to specify the x values. Like this, for instance: ListPlot[Transpose[{{300, 600, 1200, 1440}, {28, 32, 37, 66}}]] BTW ExcelLink is not really necessary to get ...

9

For seasonal data you probably want SARIMA which is a more parsimonious way to work with high order ARIMA models. This is especially true given the small amount of data you are working with. You can use TimeSeriesModelFit at various levels of automation. By default it will just try to pick the best model from its list of potential families. mod = ...

9

You posted what appears to be incomplete code but if I'm interpreting correctly you fit a model with TimeSeriesModelFit and it returned a model which you then used to create a forecast as such. monthlyObservations = TimeSeries[ WeatherData["KORD", "Temperature", {{2008, 1, 1}, {2014, 12, 31}, "Month"}]]; trendAdded = TimeSeries[ MapThread[#...

8

Calling Wolfram|Alpha is not generally an efficient way to retrieve bulk data; where possible, it is better to use a built in data function. Part of the problem is figuring out what to submit to Wolfram|Alpha. In the code you supplied, the issue begins with Wolfram|Alpha returning Missing[NotAvailable]. WolframAlpha["AAPL history",{{"HistoryDaily:Close:...

8

UPDATED ma = MovingMap[Mean, ts, Quantity[12, "Months"]]; sd = MovingMap[StandardDeviation, ts, Quantity[12, "Months"]]; DateListPlot[ {ts, ma, ma + sd , ma - sd}, PlotLegends -> {"Original", "Moving Mean", "+ Moving STD", "- Moving STD"} ]

7

Here's a line right out of the help for CellularAutomaton. ListLinePlot[Accumulate[(-1)^CellularAutomaton[30, {{1}, 0}, {500, {{0}}}]]]

7

You seem to be on the right track. If I understand your question I believe this will help: f = If[#2 + 4 <= #, -∞, Max[##]] &; FoldList[f, ts] Position[%, -∞, {1}] (See Shorter syntax for Fold and FoldList? regarding FoldList[f, ts].) The above assumes that you want to reset the new maximum to the value after the reversal (3). If you want to ...

7

It appears that the default estimation methods do not like the fact that you set TemporalRegularity->True, which essentially forces Mathematica to treat it as regularly sampled when it really isn't so. A better way might be to use TimeSeriesResample. E.g. monthlyObservations = TimeSeries[ WeatherData["KORD", "Temperature", {{2012}, {2014}, "Month"}]...

7

MovingMap is doing, what it is supposed to do. Evaluating AbsoluteTime /@ (Data[[1 ;; 5]][[All, 1]]) {3439843200, 3440102400, 3440188800, 3440275200, 3440361600} gives the timestamps for the first five data points in absolute time. The output of MovingMap[foo[#] &, Data, 5] or simpler MovingMap[foo[#] &, Data[[1 ;; 5]], 5] {{...

7

My first question is: is it possible that the import is discarding the timestamp data? The relevant timing data is contained in the attributes of the /Strain/strain dataset. These can be extracted using: H1url = "https://losc.ligo.org/s/events/GW150914/H-H1_LOSC_4_V1-1126259446-32.hdf5"; strainH1 = Import[H1url, {"Datasets", "/strain/Strain"}]; ...

7

This is the purpose of the TemporalRegularity option. TemporalRegularity is an option for TemporalData, TimeSeries, and EventSeries that controls whether the paths are assumed to be uniformly spaced in time. When setting this option, the dates themselves are ignored and a standard index {0,1,...,n} is used in its place, allowing for non-uniform ...

Only top voted, non community-wiki answers of a minimum length are eligible