({{, (RefLink[TimeSeriesMap, paclet:ref/TimeSeriesMap])[f,tseries] 
applies f to the values in tseries.}})

OpenersNotesSection(Spacer1)Details

(RefLink[TimeSeriesMap, paclet:ref/TimeSeriesMap]) is used to apply functions to the values in a time series.

(RefLink[TimeSeriesMap, paclet:ref/TimeSeriesMap]) can be used for regularly and irregularly spaced time series.

The input tseries can be a list of values {(Subscript[x, 1]),(Subscript[x, 2]),…}, a list of time-value pairs {{(Subscript[t, 1]),(Subscript[x, 1])},{(Subscript[t, 2]),(Subscript[x, 2])},…}, a (RefLink[TimeSeries, paclet:ref/TimeSeries]), an (RefLink[EventSeries, paclet:ref/EventSeries]), or (RefLink[TemporalData, paclet:ref/TemporalData]).

(RefLink[TimeSeriesMap, paclet:ref/TimeSeriesMap]) threads pathwise for tseries with multiple paths.

OpenersPrimaryExamplesSection(Spacer1)Examples  (17)

OpenersExampleSection0(Spacer1)Basic Examples  (2)

Map a function f over the values in a time series:

ts=TimeSeries[{(Subscript[x, 1]),(Subscript[x, 2]),(Subscript[x, 3]),(Subscript[x, 4]),(Subscript[x, 5])},{1}];

TimeSeriesMap[f,ts]["Path"]

Find totals for each value in a multivariate time series:

ts=TimeSeries[Array[x,{5,2}],Automatic,ValueDimensions->2];

TimeSeriesMap[Total,ts]

%["Path"]

OpenersExampleSection1(Spacer1)Scope  (9)

OpenersExampleSubsection0(Spacer1)Basic Uses  (3)

Map a function over a time series:

data=TimeSeries[{(Subscript[x, 1]),(Subscript[x, 2]),(Subscript[x, 3]),(Subscript[x, 4]),(Subscript[x, 5])},{1}];

TimeSeriesMap[Array[#,2]&,data]["Path"]

Center a time series:

data=RandomFunction[ARIMAProcess[.1,{.1},1,{.2},1],{0,1000}];

Mean[data]

centered=data-Mean[data];

Mean[centered]

ListLinePlot[{data,centered}]

Use (RefLink[Standardize, paclet:ref/Standardize]):

Standardize[data,Mean,1&]

Mean[%]

Use (RefLink[TimeSeriesMap, paclet:ref/TimeSeriesMap]) to find the norm of each value of a vector-valued time series:

α={{.2,.1},{-.3,.2}};
β={{.2,.5},{-.2,.9}};
Σ={{1,0},{0,.3}};
sample=RandomFunction[ARMAProcess[{α},{β},Σ],{1,10^2}];

norms=TimeSeriesMap[Norm,sample]

ListPlot[norms,Filling->0]

OpenersExampleSubsection1(Spacer1)Data Types  (6)

Map a function over a vector:

v=RandomInteger[{-10,10},10]

TimeSeriesMap[f,v]

Set extreme values to (RefLink[Missing, paclet:ref/Missing]) for a list of time-value pairs:

data={{"2005",1},{"2006",-1},{"2007",3},{"2008",6},{"2009",-2},{"2010",4},{"2011",5},{"2012",9999},{"2013",4},{"2014",2}};

clip=TimeSeriesMap[If[#>10,Missing[],#]&,data];

DateListPlot[clip,GridLines->{True,False}]

Double the values of a (RefLink[TimeSeries, paclet:ref/TimeSeries]):

ts=TimeSeries[];

d=2*ts

ListLinePlot[{ts,d}]

Add 50 to the values of (RefLink[TemporalData, paclet:ref/TemporalData]):

td=TemporalData[];

plus50=td+50

Show[ListLinePlot[plus50,PlotStyle->Orange],ListLinePlot[td,PlotStyle->Darker@Blue],PlotRange->All]

Represent the events in an (RefLink[EventSeries, paclet:ref/EventSeries]) by alternating colored disks:

es=EventSeries[RandomChoice[{1,5}->{1,0},50]];

ListPlot[es,Filling->Axis]

rg[c_,e_]:=If[e==0,c,RGBColor[0,c[[3]],c[[2]]]]

c=RGBColor[0,.5,1];i=0;
disks=TimeSeriesMap[{c=rg[c,#],Disk[{++i/15,0}]}&,es];

Graphics[disks["Values"]]

Add a (RefLink[Quantity, paclet:ref/Quantity]) to a time series with quantities:

ts=TimeSeries[Quantity[{0,16,9,3,7,2,17,10,6,12},"Meters"]];

res=(Quantity[10, "m", meters, "Meters"])+ts

res["Path"]

ListLinePlot[{ts,res},PlotLegends->{"ts","shifted ts"},Filling->Axis,AxesLabel->Automatic]

OpenersExampleSection2(Spacer1)Applications  (5)

Visualize the evolution of rail lines in Japan, starting in 1980:

railLines=EntityValue[Entity["Country", "Japan"], EntityProperty["Country","RailLines",{"Date"->All}]]

Check the units in which the length is given:

railLines["Values"]

Convert the length to kilometers:

data=UnitConvert[railLines,"Kilometers"]

DateListPlot[data,FrameLabel->Automatic,PlotLabel->"Japan railway length in kilometers"]

Study unemployment in France:

LaborForce=TemporalData[Table[EntityValue[Entity["Country","France"],EntityProperty["Country","LaborForce",{"Date"->All,"Gender"->g}]],{g,{"Female","Male"}}],MetaInformation->{"Gender"->{"Female","Male"}}]

Unemployement rates:

Rates=TemporalData[Table[EntityValue[Entity["Country","France"],EntityProperty["Country","UnemploymentRate",{"Date"->All,"Gender"->g}]],{g,{"Female","Male"}}],MetaInformation->{"Gender"->{"Female","Male"}}]

Convert rates to fractions:

UnemploymentRate=QuantityMagnitude[Rates]/100

The unemployment is the corresponding fraction of the labor force:

Unemployment=TimeSeriesThread[{#[[1]]*#[[3]],#[[2]]*#[[4]]}&,TimeSeriesResample[TemporalData[{LaborForce,UnemploymentRate}],"Intersection"]]

Each value component corresponds to one gender:

Unemployment["ValueDimensions"]

Unemployment["Gender"]

lgd=Map[#~~" "~~"Unemployement"&,Unemployment["Gender"]];
DateListPlot[Unemployment,FrameLabel->Automatic,PlotLegends->lgd]

Use (RefLink[TimeSeriesMap, paclet:ref/TimeSeriesMap]) to find the total unemployement:

TotalUnemployment=TimeSeriesMap[Total,Unemployment];

DateListPlot[Flatten@{Unemployment["PathComponents"],TotalUnemployment},FrameLabel->Automatic,PlotLegends->Join[lgd,{"Total Unemployement"}]]

Time series of wind speeds in Champaign, IL, in May 2014:

data=WeatherData[{"Champaign","Illinois"},"WindSpeed",{2014,5}]

Specify how to handle missing values:

wd=TimeSeries[data,MissingDataMethod->{"Interpolation",InterpolationOrder->1}];

Use (RefLink[TimeSeriesMap, paclet:ref/TimeSeriesMap]) to build the time series for the power output of a 1.5 MW wind turbine:

turbine=Interpolation[{{0.`,0.`},{0.5`,0.`},{1.`,0.`},{1.5`,0.`},{2.`,0.`},{2.5`,0.`},{3.`,0.`},{3.5`,0.`},{4.`,36.`},{4.5`,66.`},{5.`,104.`},{5.5`,150.`},{6.`,205.`},{6.5`,269.`},{7.`,344.`},{7.5`,428.`},{8.`,528.`},{8.5`,644.`},{9.`,774.`},{9.5`,926.5`},{10.`,1079.`},{10.5`,1211.`},{11.`,1342.`},{11.5`,1401.`},{12.`,1460.`},{12.5`,1477.`},{13.`,1494.`},{13.5`,1500.`},{14.`,1500.`},{14.5`,1500.`},{15.`,1500.`},{15.5`,1500.`},{16.`,1500.`},{16.5`,1500.`},{17.`,1500.`},{17.5`,1500.`},{18.`,1500.`},{18.5`,1500.`},{19.`,1500.`},{19.5`,1500.`},{20.`,1500.`},{20.5`,1500.`},{21.`,1500.`},{21.5`,1500.`},{22.`,1500.`},{22.5`,1500.`},{23.`,1500.`},{23.5`,1500.`},{24.`,1500.`},{24.5`,1500.`},{25.`,1500.`},{25.5`,0.`},{26.`,0.`},{26.5`,0.`},{27.`,0.`},{27.5`,0.`},{28.`,0.`},{28.5`,0.`},{29.`,0.`},{29.5`,0.`},{30.`,0.`}}];
power[s_Missing]:=s
power[s_Quantity]:=Quantity[turbine[UnitConvert[s,"m/s"]//QuantityMagnitude],"kilowatts"];

output=TimeSeriesMap[power,wd]

Visualize the daily moving average of the energy output:

ma=MovingMap[Mean,output,{Quantity[1,"Day"]}];

DateListPlot[ma,PlotTheme->{"Detailed","ThinLines"},FrameLabel->Automatic,ImageSize->300,Filling->Bottom]

Simulate (RefLink[GeometricBrownianMotionProcess, paclet:ref/GeometricBrownianMotionProcess]) g(t) by transforming a (RefLink[WienerProcess, paclet:ref/WienerProcess]) w(t) where g(t)=(Subscript[x, 0]) exp(w(t)):

μ=1;σ=1/3;x0=2;
proc=WienerProcess[μ-(σ^2)/2,σ];
data=RandomFunction[proc,{0,1,.1},100];

Apply the transformation to a random sample to obtain the geometric Brownian motion:

sample=x0 Exp[data];

Compare to the corresponding (RefLink[GeometricBrownianMotionProcess, paclet:ref/GeometricBrownianMotionProcess]):

data=RandomFunction[GeometricBrownianMotionProcess[μ,σ,x0],{0,1,.1},100];

Both simulations should have the same statistical properties, including for slices:

{Mean[sample[0.5]],Mean[data[0.5]]}

Use (RefLink[TimeSeriesMap, paclet:ref/TimeSeriesMap]) to calculate determinants of covariance matrices for an (RefLink[ARProcess, paclet:ref/ARProcess]):

cov=CovarianceFunction[ARProcess[{{{1/3,1/2},{-1/4,1/2}}},{{1,1/3},{1/3,1}}],{10}];

det=TimeSeriesMap[Det,cov]

det["Values"]//N

OpenersExampleSection3(Spacer1)Properties & Relations  (1)

Some operations can be obtained using listability:

ts=TimeSeries[{7,9,16},{1}];

TimeSeriesMap[#+c&,ts]["Path"]

Obtain the same result using listability:

(ts+c)["Path"]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[MovingMap, paclet:ref/MovingMap])  ▪  (RefLink[TimeSeriesAggregate, paclet:ref/TimeSeriesAggregate])  ▪  (RefLink[TimeSeriesResample, paclet:ref/TimeSeriesResample])  ▪  (RefLink[TimeSeriesThread, paclet:ref/TimeSeriesThread])  ▪  (RefLink[RegularlySampledQ, paclet:ref/RegularlySampledQ])  ▪  (RefLink[MinimumTimeIncrement, paclet:ref/MinimumTimeIncrement])  ▪  (RefLink[TimeSeriesShift, paclet:ref/TimeSeriesShift])  ▪  (RefLink[TimeSeriesRescale, paclet:ref/TimeSeriesRescale])  ▪  (RefLink[TimeSeriesMapThread, paclet:ref/TimeSeriesMapThread])  ▪  (RefLink[TimeSeriesInsert, paclet:ref/TimeSeriesInsert])  ▪  (RefLink[TimeSeriesModelFit, paclet:ref/TimeSeriesModelFit])  ▪  (RefLink[TimeSeriesWindow, paclet:ref/TimeSeriesWindow])  ▪  (RefLink[TemporalData, paclet:ref/TemporalData])  ▪  (RefLink[TimeSeries, paclet:ref/TimeSeries])  ▪  (RefLink[EventSeries, paclet:ref/EventSeries])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Date & Time, paclet:guide/DateAndTime])}, {▪(RefLinkPlain[Time Series Processing, paclet:guide/TimeSeries])}})}})