33

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 ...


23

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,...


23

One simple way of "filtering" your data is to treat the points as a graph, and search for the shortest path from left to right: xScale = 10.; xy = Transpose[{N[Range[Length[data]]]*(xScale/Length[data]), data}]; start = {-xScale, Mean[data]}; finish = {2*xScale, Mean[data]}; graph = NearestNeighborGraph[Join[{start}, xy, {finish}], 25]; graph = ...


20

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


18

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} *)


18

One way to approach this is with "Dynamic Time Warping". First, preprocess your data to get the MFCC coefficients and extract the data from the time series: human = Audio["http://home.ustc.edu.cn/~xiaozh/SE/Audio/human.wav"]; hus = Audio["http://home.ustc.edu.cn/~xiaozh/SE/Audio/hus.wav"]; {humMFCC, husMFCC} = AudioLocalMeasurements[#, "MFCC"] & /@ {...


16

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}}]]


15

Alex Isakov has a Granger Causality Test in his Economica Time Series package here:- Mathematica Package Repository - Economica I'm not very familiar with the details, but I ran some tests using data from here:- Dave Giles' Blog - Testing for Granger Causality I downloaded the example data from the Data page. Here it is stored as QR codes. qrimage = ...


15

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 ...


14

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 -...


14

Here is a simple example that may help you get started. In this example, we are going to a predict a simple time series of a sinusoid wave. data = Table[Sin[x], {x, 0, 100, 0.04}]; We will cut the data into windows of 51 data points. The first 50 points as a whole is our X, and the last data point is our Y. training = RandomSample[ List /@ Most[#] -&...


13

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 ...


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

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]...


12

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 of ...


12

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 ...


12

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, ...


12

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"}]; attrsH1 ...


12

Taking inspiration from the answer by xslittlegrass, I came up with the following solution. Recall the sample data from this question. We have an observable obs we are interested to predict: and three parameters par1, par2, par3 that are correlated with the observable to some extent: We only use the data for the first 700 time steps to train the model, ...


11

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....


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

My interest piqued, I went back to my original code, from 2002 (ok, not quite 15 years). Simon's comment was correct. The problem in the modified version of the code (not mine) was that it changed the obsolete command AppendRows to Join instead of Join[##,2]. This version produces the expected format result in version 9, and does so in a fraction of a ...


11

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"} ]


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

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 ...


10

This is intended behaviour and here is why. Accumulate on TimeSeries or on EventSeries assumes that it accumulates according to every regular step on times. So in case of irregularly sampled TimeSeries it interpolates and in case of irregularly sampled EventSeries it creates Missing[] values. Examples: In[41]:= data = {1, 2, 3, 4, 5}; Accumulate[data] Out[...


10

I am having some troubles with removing a stochastic trend from a time series on Mathematica. It is not clear to me what exactly "removing a stochastic trend" means. If we assume "difference-stationary" time series (and making the time-series stationary for further analysis) then time-series differencing can be easily applied (in Mathematica.) If we ...


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 data ...


9

From the question formulation I am not sure what is the desired end result: a time series or a table. It seems to be the latter but I give solutions for both. I am using a sample of the stocks for clarity. stdate = "04/21/1982"; enddate = "10/31/2014"; rSP = {"ADP", "ALL", "CNP", "ED", "EMR", "EXPD", "FB", "FLIR", "HAR", "NEE", "OKE", "PHM", "PLD", "...


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 = ...


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