Tag Info

Hot answers tagged

18

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


17

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


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


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

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


10

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


9

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


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

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


8

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


8

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


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


8

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


8

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


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

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


7

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


6

After some study, I think that I found out how to answer it using: data = TemporalData[salesData,{{2010,1},{2012,11},"Month"}]; proc=EstimatedProcess[salesData,SARIMAProcess[{},1,{},{12,{a},1,{b}},v]]; forecast=TimeSeriesForecast[proc, data,{14}]; DateListPlot[N@{data["Path"],forecast["Path"]} ,AspectRatio->0.2 ,Joined-> True ,PlotStyle ...


6

Wolfram has renamed the LogLikelihood function in the Time Series package to LogLikelihoodFunction. But they have apparently forgotten to update the documentation.


6

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


5

Here is a solution based on rules and recursion (not very efficient, but IMO rather interesting): Clear[fn]; fn[lst_, delta_, startIndex_: 0] := Flatten@ ReplaceList[ lst, {Shortest[PatternSequence[x__, y_, z___]], p_, q___} /; y - p == delta && y >= Max[x] :> ({ # + startIndex, fn[{q}, delta, # + ...


5

Straightforward approach with controlling related heights. Needs["HierarchicalClustering`"] SeedRandom@2; data = RandomVariate[NormalDistribution[], {10, 20}]; height = 50; label = ListPlot[#, Axes -> False, Joined -> True, ImageSize -> {300, height}, AspectRatio -> height/300] & /@ data; Edit I'm sorry my previous ...


5

With version 10 data = WeatherData["KATL", "Temperature", {{2004, 1}, {2014, 10}, "Month"}] ds = TimeSeriesWindow[data, {{#, 1}, {#, 12}}] & /@ Range[2004, 2014]; ListPlot[ds[[#]]["Values"] & /@ Range@Length@ds, Joined -> True, Ticks -> {Transpose[{Range[12], {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", ...


4

I might be a bit late, but hopefully not too late. Here's a routine for finding the positions of "reversals" based on some finite difference trickery, which exploits the analogy between differences for discrete data and derivatives in the usual calculus: findReversalPositions[data_?VectorQ, h_?NumericQ] := Module[{n = Length[data], si = ...


4

Using the same example data as R.M., ts = {1, 2, 3, 5, 10, 8, 6, 3, 5, 7, 4, 3, 2, 1, 6, 9, 5}; Try something like this: Flatten@Position[ FoldList[With[{b = Boole[#2 + 4 <= First[#1]]}, {(1 - b) Max[{First[#1], #2}] + b #2, b}] &, {First@ts, 0}, Rest@ts], {_, 1}] {7, 12, 17} This approach as the advantage that you can ...


4

Lag differences are not the same as second-differencing etc, so Differences is not the right approach. test2 = Array[f, 10] In[23]:= Differences[test2, 3] Out[23]= {-f[1] + 3 f[2] - 3 f[3] + f[4], -f[2] + 3 f[3] - 3 f[4] + f[5], -f[3] + 3 f[4] - 3 f[5] + f[6], -f[4] + 3 f[5] - 3 f[6] + f[7], -f[5] + 3 f[6] - 3 f[7] + f[8], -f[6] + 3 ...


4

There are a couple issues here worth touching on, I think. Firstly, you are making things overly complicated for your self. Mathematica has a built in function for generating data from a random process, called RandomFunction. You can easily use it and a time series model to generate data, like so: armodel = ARProcess[{0.5469865826154379`, ...


4

I think your modeldata generation should be y[[t]] = whitenoise + (a1*y[[t-1]]) + (a2*y[[t-2]]) + (a3*y[[t-3]]) + (a4*y[[t-4]]) since for an AR(4) model, the current value is a linear combination of four previous values plus the current value of the noise. Also, after looking at the plot of processdata, I observed strong trend and seasonality, so you ...


4

This looks like very useful function for e.g. economic time series. If this can be done easily in R does it need to be done in Mathematica? With the qualifier that this is my first day testing 9 he is my attempt at the alternative: Needs["RLink`"] InstallR[]; data = REvaluate["{ url <- \"http://www.massey.ac.nz/~pscowper/ts/cbe.dat\" CBE ...



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