# Tag Info

34

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

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

19

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"] & /@ {...

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

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

15

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

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

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

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

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

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

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

10

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

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

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

9

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

9

Here's an alternate approach that takes the data into an image that you can edit in a Paint program, and then back into data. Presumes you have "insider knowledge" about the data set that allows you to identify and exclude bad data. Assuming the data is in dat, plot it ListPlot[dat] Convert to an image, using a sparse array as an intermediary: mindat = ...

8

As noted in my comment, constructs like TemporalData are not meant to be treated as vanilla lists (see the documentation for details on getting "pieces" of them via their properties). In your case, you're interested in the addition of the states over time, so, e.g.: Z = RandomFunction[WienerProcess[0, 1], {0, 1, 0.01}]; L = RandomFunction[...

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

There is a lot in documentation, e.g. For illustration: This is times series of AUD US exchange rate 1990 to 2016. tsm = TimeSeriesModelFit[aus, "ARIMA"]; forecast = TimeSeriesForecast[tsm, {0, 5}] q[ci_] := Quantile[NormalDistribution[], 1 - (1 - ci)/2] se = Sqrt[forecast["MeanSquaredErrors"]]; tsci[ci_, u_] := TimeSeriesThread[{1, u q[ci]}.# &, {...

8

Introduction It seems to me that this question should be answered using more "traditional" time series methods than the already provided interesting solutions (with graphs and image processing.) The workflow shown below is something considered during the design of the QRMon package and it is very similar to the data cleaning done in "Cleaning away data ...

8

To get output that looks a bit more reasonable, modify the second parameter to TimeSeriesModelFit. Load the data: ds = SemanticImport["https://textbin.net/raw/ikfqPWq6Iy"] ts = TimeSeriesResample@TimeSeries[Values@Normal@ds] Now, we can get output that has the repetition you were expecting with, for instance, an "ARMA" (auto-regressive moving-average) ...

7

I've also written a Mathematica version of the Johansen test which I coded after studying the equations for the procedure. I've examined Johansen test codes (in Matlab, C, etc.) available online. I've found that these different codes often don't agree with each other, especially with respect to detrending and normalization. My code allows for detrending of ...

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