({{, (RefLink[TimeSeriesModelFit, paclet:ref/TimeSeriesModelFit])[data]
constructs a time series model for data from an automatically selected model family.}, {, (RefLink[TimeSeriesModelFit, paclet:ref/TimeSeriesModelFit])[data,mspec]
constructs a time series model for data from a model family specified by mspec.}})

OpenersNotesSection(Spacer1)Details and Options

(RefLink[TimeSeriesModelFit, paclet:ref/TimeSeriesModelFit]) is used in time series analysis. It automates the selection of a time series model from a large class of possible models.

(RefLink[TimeSeriesModelFit, paclet:ref/TimeSeriesModelFit]) returns a symbolic (RefLink[TimeSeriesModel, paclet:ref/TimeSeriesModel]) object to represent the time series model it constructs. The properties and diagnostics of the model can be obtained from model["property"].

A list of available model properties can be obtained using model["Properties"].

The data can be a list of numeric 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]), or (RefLink[TemporalData, paclet:ref/TemporalData]).

The value of the model at time t can be obtained by giving model[t]. If t is in the range of the input data, then the data at time t is returned; otherwise, a forecasted value is given.

Forecast prediction limits at a time t can be obtained using model["PredictionLimits"][t].

The model specification mspec can take the following forms:

The following families and parameterizations can be used:

Autoregressive and moving-average orders p and q and their seasonal counterparts sp and sq can be given as (RefLink[Automatic, paclet:ref/Automatic]), a non-negative integer, a list of non-negative integers, or a (RefLink[Span, paclet:ref/Span]) indicating such a list.

The non-seasonal and seasonal integration orders d and sd can be given as (RefLink[Automatic, paclet:ref/Automatic]), a non-negative integer, a list of non-negative integers, or a (RefLink[Span, paclet:ref/Span]) indicating such a list.

For seasonal models, the seasonality parameter s can be (RefLink[Automatic, paclet:ref/Automatic]) or a positive integer.

Additional model family parameterizations are given in the examples.

The following model properties can be obtained using model["property"]:

Properties pertaining to model selection include:

Properties that measure goodness of fit include:

The following properties can be used to assess the whiteness of the model residuals:

The maximum number of lags to include for a residual whiteness property "wprop" can be controlled by giving model["wprop","LagMax"->max], where max is a positive integer.

Properties and diagnostics for coefficient estimates include:

(RefLink[TimeSeriesModelFit, paclet:ref/TimeSeriesModelFit]) takes the following options:

The default setting (RefLink[IncludeConstantBasis, paclet:ref/IncludeConstantBasis])->(RefLink[Automatic, paclet:ref/Automatic]) will include a constant in the model if both the non-seasonal and seasonal integration orders are zero; otherwise, no constant will be included.

The method m in (RefLink[Method, paclet:ref/Method])->m can be either "Stepwise" or "GridSearch". For stepwise selection, (RefLink[Automatic, paclet:ref/Automatic]) parameter orders are incrementally changed until a model with an optimal selection criterion is found. Using a grid search exhaustively tries all models over a specified grid.

The best model is selected according to a selection criterion crit, which can be set in (RefLink[Method, paclet:ref/Method])->{m,"SelectionCriterion"->crit}. Some examples of valid selection criteria include "AIC" (default), "AICc", "SBC", and "BIC".

OpenersPrimaryExamplesSection(Spacer1)Examples  (42)

OpenersExampleSection0(Spacer1)Basic Examples  (1)

Fit a time series model to some data:

data={5.,9.,8.,10.,6.1,10.4,9.1,11.6,7.5,12.1,10.4,13.5,9.,14.1,11.9,15.7,10.8,16.4,13.7,18.3,12.9,19.,15.8,21.2,
15.3,22.1,18.3,24.6};

tsm=TimeSeriesModelFit[data]

The fitted time series model:

Normal[tsm]

Obtain a point forecast and 95% prediction limits at time 35:

tsm[35]

tsm["PredictionLimits"][35]

Visualize the data with a 10-step-ahead forecast:

ListLinePlot[{tsm["TemporalData"],TimeSeriesForecast[tsm,{10}]}]

OpenersExampleSection1(Spacer1)Scope  (22)

OpenersExampleSubsection0(Spacer1)Basic Uses  (5)

Automatically fit a model to a time series:

ts=Accumulate[RandomVariate[NormalDistribution[],10^4]];

ListLinePlot[ts]

tsm=TimeSeriesModelFit[ts]

The model selected for the data:

Normal[tsm]

Create a forecast using some monthly temperature data:

tsm=TimeSeriesModelFit[TimeSeries[]]

The monthly temperature data and a 24-month forecast:

DateListPlot[{tsm["TemporalData"],TimeSeriesForecast[tsm,{24}]},Joined->True]

Forecast the average temperature for June 1, 2014:

tsm["June 1, 2014"]

A 95% confidence interval about the forecast:

tsm["PredictionLimits"]["June 1, 2014"]

Fit a particular model to a time series:

ts=TimeSeries[];

ListLinePlot[ts,PlotRange->All]

Fit a "GARCH"(1,1) model to the data:

tsm=TimeSeriesModelFit[ts,{"GARCH",{1,1}}]

The model and parameter estimates:

tsm["ParameterTable"]

Fit a time series model to a 100-business-day time series:

data=TemporalData[RandomFunction[ARIMAProcess[{.1},2,{.1,.2},2],{1,10^2}]["PathStates"],{Automatic,DateString[],"BusinessDay"}];

p1=DateListPlot[data]

tsm=TimeSeriesModelFit[data,{"ARIMA",{1,2,2}}]

Simulate the next 30 business days 50 times:

Show[p1,DateListPlot[RandomFunction[tsm,{1,30},50],Joined->True],PlotRange->All]

Use the original data to simulate future observations with (RefLink[TimeSeriesModel, paclet:ref/TimeSeriesModel]):

data=TemporalData[RandomFunction[ARProcess[{.8},1],{100}]["Values"],{"January 24 1982",Automatic,"Month"}]

Fit a model:

model=TimeSeriesModelFit[data]

Use the best-fit process to simulate 10 future observations:

process=model["Process"]

No information about time stamps or initial values is passed to (RefLink[RandomFunction, paclet:ref/RandomFunction]):

SeedRandom["TSM"];BlockRandom[sim1=RandomFunction[process,{10},4]]

Simulate using (RefLink[TimeSeriesModel, paclet:ref/TimeSeriesModel]) to use information given by the original data:

SeedRandom["TSM"];BlockRandom[sim2=RandomFunction[model,{10},4]]

{ListLinePlot[sim1],DateListPlot[sim2]}

OpenersExampleSubsection1(Spacer1)Model Specification  (6)

Automatically select a model for a time series:

ts=RandomFunction[ARMAProcess[{.1,-.3},{.1},1],{0,10^4}];

tsm=TimeSeriesModelFit[ts]

Equivalently, specify (RefLink[Automatic, paclet:ref/Automatic]):

TimeSeriesModelFit[ts,Automatic]

Find a model in a particular family:

SeedRandom[235];
ts=RandomFunction[ARProcess[{.1,.2},1],{0,10^4}];

Search the autoregressive family of models:

tsm=TimeSeriesModelFit[ts,"AR"]

Select the best model from an explicit set of candidates:

SeedRandom[203371];
ts=RandomFunction[ARMAProcess[{.1},{.2,-.3},1],{0,10^4}];

Search the ARMA family with orders p and q from 0 to 2:

TimeSeriesModelFit[ts,{"ARMA",{0;;2,0;;2}}]

%["CandidateSelectionTable"]

Fit a model with fixed orders:

ts=RandomFunction[ARIMAProcess[{.2,-.1},1,{.5,-.3,.4},2],{0,10^4}];

ListLinePlot[ts]

Fit an "ARIMA"(2,1,3) model to the data:

tsm1=TimeSeriesModelFit[ts,{"ARIMA",{2,1,3}}]

Fix the integration order and search for the autoregressive and moving average orders:

tsm2=TimeSeriesModelFit[ts,{"ARIMA",{Automatic,1,Automatic}}]

Parameterizations for the ARIMA family of models:

ts=TemporalData[];

Automatically detect the orders p, d, and q:

TimeSeriesModelFit[ts,"ARIMA"]

Alternatively, use (RefLink[Automatic, paclet:ref/Automatic]) for all parameter orders:

p=d=q=Automatic;

TimeSeriesModelFit[ts,{"ARIMA",{p,d,q}}]

Equivalent ways to fix the integration order d==1 while leaving p and q (RefLink[Automatic, paclet:ref/Automatic]):

TimeSeriesModelFit[ts,{"ARIMA",{p,1,q}}]

TimeSeriesModelFit[ts,{"ARIMA",1}]

Equivalent ways to fix p==1 and q==2 while leaving the integration order d (RefLink[Automatic, paclet:ref/Automatic]):

TimeSeriesModelFit[ts,{"ARIMA",{1,d,2}}]

TimeSeriesModelFit[ts,{"ARIMA",{1,2}}]

Parameterizations for the SARIMA family of models:

ts=RandomFunction[SARIMAProcess[{.3},1,{.2},{12,{.2},2,{}},1],{1,10^4}];

Automatically detect p, d, q, sp, sd, sq, and s:

tsm=TimeSeriesModelFit[ts,"SARIMA"]

Alternatively, use (RefLink[Automatic, paclet:ref/Automatic]) for all parameter orders:

p=d=q=sp=sd=sq=s=Automatic;

TimeSeriesModelFit[ts,{"SARIMA",{{p,d,q},{sp,sd,sq},s}}]

Equivalent ways to fix the seasonality parameter s==12 while leaving all others (RefLink[Automatic, paclet:ref/Automatic]):

TimeSeriesModelFit[ts,{"SARIMA",{{p,d,q},{sp,sd,sq},12}}]

TimeSeriesModelFit[ts,{"SARIMA",12}]

Equivalent ways to fix the seasonality s==12 and integration orders d==1 and sd==2:

TimeSeriesModelFit[ts,{"SARIMA",{{p,1,q},{sp,2,sq},12}}]

TimeSeriesModelFit[ts,{"SARIMA",{1,2,12}}]

OpenersExampleSubsection2(Spacer1)Model Properties  (11)

Obtain a list of available properties:

tsm=TimeSeriesModelFit[TimeSeries[]];

tsm["Properties"]

Extract the best-fitting process:

tsm=TimeSeriesModelFit[TimeSeries[]];

tsm["BestFit"]

Equivalently, use (RefLink[Normal, paclet:ref/Normal]):

Normal[tsm]

Show some fit criteria for the selected model:

tsm=TimeSeriesModelFit[TimeSeries[]];

sc={"AIC","AICc","BIC","SBC"};

TableForm[{#,tsm[#]}&/@sc]

The criterion that was used to choose the best model:

tsm["SelectionCriterion"]

Report the top models that were fitted to the data:

tsm=TimeSeriesModelFit[TimeSeries[]];

tsm["CandidateSelectionTable"]

The entries from the table:

tsm["CandidateSelectionTableEntries"]//Shallow

Obtain a list of candidate models fitted to the data:

tsm=TimeSeriesModelFit[TimeSeries[],Method->{"GridSearch","SelectionCriterion"->"AICc"}];

Shallow[mod=tsm["CandidateModels"]]

Compare the models by AIC:

ListPlot[MapThread[Tooltip,{tsm["CandidateModelSelectionValues"],mod}],PlotRange->All,PlotStyle->PointSize[Large],Filling->Axis]

Check whether fit residuals are autocorrelated:

ts=TimeSeries[];

tsm1=TimeSeriesModelFit[ts,{"ARMA",{2,0}}];

There is a significant spike at lag 3:

tsm1["ACFPlot"]

Adding a moving-average component removes the autocorrelation at lag 3:

tsm2=TimeSeriesModelFit[ts,{"ARMA",{2,1}}];

tsm2["ACFPlot"]

Check whether the partial correlation function for the fit residuals is zero:

ts=TimeSeries[];

tsm1=TimeSeriesModelFit[ts,{"ARMA",{2,0}}];

There is a significant spike at lag 3:

tsm1["PACFPlot"]

Adding a moving-average component removes the partial correlation at lag 3:

tsm2=TimeSeriesModelFit[ts,{"ARMA",{2,1}}];

tsm2["PACFPlot"]

Test model residuals for autocorrelation:

ts=TimeSeries[];

tsm1=TimeSeriesModelFit[ts,{"ARMA",{2,0}}];

There are significant spikes at lags 3 and 4:

tsm1["LjungBoxPlot"]

Adding a moving-average component removes the significant autocorrelations:

tsm2=TimeSeriesModelFit[ts,{"ARMA",{2,1}}];

tsm2["LjungBoxPlot"]

Obtain values used in residual whiteness diagnostic plots:

mod=TimeSeriesModelFit[TimeSeries[],{"ARMA",{2,1}}];

mod/@{"ACFPlot","PACFPlot","LjungBoxPlot"}//GraphicsRow

The first 5 autocorrelation values and 95% confidence region used in the "ACFPlot":

mod["ACFValues","LagMax"->5]

The first 5 partial autocorrelation values and 95% confidence region used in the "PACFPlot":

mod["PACFValues","LagMax"->5]

The Ljung–Box p-values for lags 1 to 12 and the critical value used in the plot:

mod["LjungBoxValues","LagMax"->12]

Report the values and significance of model parameters:

tsm=TimeSeriesModelFit[TimeSeries[]]

tsm["ParameterTable"]

The value entries from the table:

tsm["ParameterTableEntries"]

Obtain parameter standard errors from the parameter covariance matrix:

tsm=TimeSeriesModelFit[d=TimeSeries[]]

Sqrt[Diagonal[tsm["CovarianceMatrix"]]/d["PathLength"]]

Standard errors can be obtained directly:

tsm["ParameterStandardErrors"]

OpenersExampleSection2(Spacer1)Options  (9)

OpenersExampleSubsection3(Spacer1)ConfidenceLevel  (2)

Set the confidence level to use for prediction limits:

ts=RandomFunction[ARIMAProcess[{.1},2,{.2},1],{1,150}];

ListLinePlot[ts]

Use a 90% confidence level:

tsm=TimeSeriesModelFit[ts,ConfidenceLevel->.9]

t=tsm["PredictionLimits"][155]

The confidence level can be changed after fitting:

tsm["PredictionLimits",ConfidenceLevel->.99][155]

The (RefLink[ConfidenceLevel, paclet:ref/ConfidenceLevel]) setting affects thresholds for feature detection:

SeedRandom[11];
data=RandomFunction[GARCHProcess[2,{.5},{.3}],{1,10^4}];

TimeSeriesModelFit[data,ConfidenceLevel->.9]

Normal[%]

TimeSeriesModelFit[data,ConfidenceLevel->.99]

Normal[%]

OpenersExampleSubsection4(Spacer1)IncludeConstantBasis  (1)

Require that a constant be estimated for the model:

data=TemporalData[];

TimeSeriesModelFit[data,"ARMA",IncludeConstantBasis->True]//Normal

Set the constant to zero:

TimeSeriesModelFit[data,"ARMA",IncludeConstantBasis->False]//Normal

OpenersExampleSubsection5(Spacer1)Method  (5)

By default, parameter orders are selected using a stepwise search:

data=RandomFunction[ARMAProcess[{.1},{.2},1],{1,10^4}];

tsm1=TimeSeriesModelFit[data,"ARMA",Method->Automatic]//Normal

tsm2=TimeSeriesModelFit[data,"ARMA",Method->"Stepwise"]//Normal

tsm1==tsm2

Use a grid search instead:

TimeSeriesModelFit[data,"ARMA",Method->"GridSearch"]//Normal

Perform a hybrid search:

TimeSeriesModelFit[data,{"ARMA",{Automatic,0;;10}},Method->"Stepwise"]//Normal

Use different selection criteria to pick the best model:

data=RandomFunction[ARMAProcess[{.1},{.2},1],{1,10^4}];

By default, "AIC" is used:

TimeSeriesModelFit[data,"ARMA"]["CandidateSelectionTable"]

Use "BIC":

TimeSeriesModelFit[data,"ARMA",Method->{Automatic,"SelectionCriterion"->"BIC"}]["CandidateSelectionTable"]

Set the maximum number of candidate models to keep for reporting:

temp=TemporalData[];

Retain a maximum of 15 models:

TimeSeriesModelFit[temp,Method->{Automatic,"MaxCandidates"->15}]["CandidateModels"]//Length

Keep all models that were fitted:

TimeSeriesModelFit[temp,Method->{Automatic,"MaxCandidates"->Infinity}]["CandidateModels"]//Length

By default, a maximum of 10 models are kept:

TimeSeriesModelFit[temp]["CandidateModels"]//Length

Set the maximum allowable autoregressive and moving-average orders:

temp=TemporalData[];

TimeSeriesModelFit[temp,Method->{Automatic,"MaxAROrder"->1,"MaxMAOrder"->1,"MaxSeasonalAROrder"->1,"MaxSeasonalMAOrder"->1}]

The maximum orders limit the number of models that can be fitted:

TimeSeriesModelFit[temp,Method->{"GridSearch","MaxCandidates"->Infinity,"MaxAROrder"->2,"MaxMAOrder"->2,"MaxSeasonalAROrder"->2,"MaxSeasonalMAOrder"->2}]["CandidateModels"]//Length

TimeSeriesModelFit[temp,Method->{"GridSearch","MaxCandidates"->Infinity,"MaxAROrder"->1,"MaxMAOrder"->1,"MaxSeasonalAROrder"->1,"MaxSeasonalMAOrder"->1}]["CandidateModels"]//Length

The stepwise method fits models within "MaxStepSize" orders of the current best model:

data=TemporalData[];

By default, the maximum order step is set to 1:

AbsoluteTiming[tsmDefault=TimeSeriesModelFit[data,Method->{Automatic,"MaxStepSize"->1}]]

Increasing the step size can improve quality but may increase search time:

AbsoluteTiming[tsmBigStep=TimeSeriesModelFit[data,Method->{"Stepwise","MaxStepSize"->5}]]

Compare to a grid search:

AbsoluteTiming[tsmGrid=TimeSeriesModelFit[data,"ARMA",Method->"GridSearch"]]

OpenersExampleSubsection6(Spacer1)WorkingPrecision  (1)

Use (RefLink[WorkingPrecision, paclet:ref/WorkingPrecision]) to obtain higher-precision estimates:

ts=Accumulate[RandomChoice[{-1,1},10^4]];

TimeSeriesModelFit[ts,{"ARIMA",{1,1,1}},WorkingPrecision->50]//Normal

OpenersExampleSection3(Spacer1)Applications  (8)

OpenersExampleSubsubsection0(Spacer1)Local Temperature  (1)

Forecast the average temperature for the next month at your location:

today=DateValue[Today,{"Year","Month"}];
start=DateValue[DatePlus[Today,{-10,"Year"}],{"Year","Month"}];
tspec = {start,today,"Month"};

Local average monthly temperature for the past 10 years:

temp=TimeSeries[WeatherData[FindGeoLocation[],"Temperature",tspec,"NonMetricValue"],{start,Automatic,"Month"}]

DateListPlot[temp,Joined->True,FrameLabel->Automatic]

Fit a time series model:

tsm=TimeSeriesModelFit[temp]

Next month's forecast:

tsm[DatePlus[today,{1,"Month"}]]

Plot a forecast for the next year with 95% confidence bands:

fdates=DateRange[today,DatePlus[today,{1,"Year"}],"Month"];

forecast=tsm/@fdates;
bands=tsm["PredictionLimits"][#]&/@fdates;

DateListPlot[{bands[[All,1]],forecast,bands[[All,2]]},{today,Automatic,"Month"},Joined->True,PlotStyle->{Gray,Automatic}]

OpenersExampleSubsubsection1(Spacer1)Airline Passengers  (2)

The following data contains the monthly total number of US international airline passengers (in thousands) from January 1949 to December 1960:

passengers=TimeSeries[];

Split the data at January 1958:

before1958=TimeSeriesWindow[passengers,{Automatic,"December 1957"}];
since1958=TimeSeriesWindow[passengers,{"January 1958",Automatic}];

p=DateListPlot[{before1958,since1958},Joined->True,PlotLegends->{"Before 1958","After 1958"}]

Fit a time series model to the airline passenger data before 1958:

tsm=TimeSeriesModelFit[before1958]

Compare the forecasted and actual number of airline passengers for June of 1959:

tsm["June 1959"]*1000//Round

1000since1958["June 1959"]

The forecast from 1958 to 1961 compared to the actual data:

DateListPlot[{before1958,since1958,Table[{t,tsm[t]},{t,DateRange["January 1958","December 1960","Month"]}]},Joined->True,PlotLegends->{"Before 1958","After 1958","Forecast"}]

Simulate airline passenger counts seven years into the future and compare to a forecast:

passengers=TimeSeries[];

Fit a time series model to the data:

tsm=TimeSeriesModelFit[passengers]

Create the seven-year forecast and prediction limits:

k=7;
start="December 1st, 1960";

tsm["TemporalData"]["DateFunction"]/@tsm["TemporalData"]["FirstTimes"]

forecastDates=DateRange[start,DatePlus[start,{k,"Year"}],"Month"];

forecast=tsm/@forecastDates;
bands=tsm["PredictionLimits"][#]&/@forecastDates;

A plot of the forecast:

pforecast=DateListPlot[{bands[[All,1]],forecast,bands[[All,2]]},{start,Automatic,"Month"},Joined->True,Filling->{1->{3}},PlotStyle->{Directive[Dashed,Darker@Gray],Directive[Thick,Black]}]

Simulate 100 paths seven years into the future:

sim=RandomFunction[tsm,{0,12*k},100];

psim=DateListPlot[sim,PlotStyle->Directive[Opacity[.25]],Joined->True,PlotRange->All]

Show the 95% prediction limit with the simulated paths:

Show[psim,pforecast,PlotRange->All]

OpenersExampleSubsubsection2(Spacer1)Prime Numbers  (1)

Fit a time series model to the differences between actual and estimated prime numbers:

primeEstimator[n_]:=n Log[n]

primeDiff[n_]:=Prime[n]-primeEstimator[n]

diffs=Table[primeDiff[n],{n,1,250}];

ListLinePlot[diffs,PlotRange->All]

Fit a model to the differences:

tsm=TimeSeriesModelFit[diffs]

Show the forecast of the next 100 differences with 95% prediction limits:

Show[Plot[tsm["PredictionLimits"][t],{t,251,350},PlotRange->{100,400},AxesOrigin->{251,100},PlotStyle->{Gray,Dashed}],DiscretePlot[primeDiff[n],{n,251,350},Filling->None]]

Use the model to improve the estimate of the (300^th) prime:

primeEstimator[300]//N

primeEstimator[300]+tsm[300]

Prime[300]

The original and improved estimators compared to the actual primes:

ListLinePlot[Transpose@Table[Join[{Prime[n],primeEstimator[n],primeEstimator[n]+tsm[n]},primeEstimator[n]+tsm["PredictionLimits"][n]],{n,251,350}],PlotStyle->{Automatic,Automatic,Automatic,Directive[Dashed,Gray],Directive[Dashed,Gray]},PlotLegends->{"primes","original prime estimator","improved prime estimator"}]

OpenersExampleSubsubsection3(Spacer1)Accidental Deaths  (1)

The number of accidental deaths in the United States was recorded monthly for six years:

deaths=ExampleData[{"Statistics","USAccidentalDeaths"},"EventSeries"]

n=deaths["PathLength"]

DateListPlot[deaths]

Fit an (RefLink[ARProcess, paclet:ref/ARProcess]) to the data:

tsm1=TimeSeriesModelFit[deaths,"AR"]

The model misses the seasonality in the data:

Table[Pane[tsm1[plot],ImageSize->Medium],{plot,{"ACFPlot","PACFPlot"}}]

The diagnostic plots suggest a model with seasonality of 12 is needed:

tsm12=TimeSeriesModelFit[deaths,{"SARIMA",12}]

The seasonal model seems to generally outperform the non-seasonal one:

(#[{"AIC","AICc","BIC","SBC"}]&/@{tsm1,tsm12})\[Transpose]//Grid

Table[Pane[tsm12[plot],ImageSize->Medium],{plot,{"ACFPlot","PACFPlot"}}]

Obtain an empirical estimate of the 90% forecast prediction limits two months into the future:

sixM=RandomFunction[tsm12,{0,1},10^4];

α=0.9;

Quantile[sixM["28 Feb 1979"],{((1-α)/2),((1+α)/2)}]

Compare to the asymptotic estimates:

tsm12["PredictionLimits",ConfidenceLevel->α]["28 Feb 1979"]

OpenersExampleSubsubsection4(Spacer1)Lynx Pelts  (1)

Number of mink furs sold yearly by the Hudson's Bay Company, Canada, from 1850 to 1911:

sales=TimeSeries[];

ListPlot[sales,Joined->True,PlotRange->All]

Fit a model to the data:

saleModel=TimeSeriesModelFit[sales]

Simulate the values of the model for the next 10 years:

sim=RandomFunction[saleModel,{0,10},150]

The simulated values may be negative, but the mean function provides a positive forecast:

forecast=TimeSeriesThread[Mean,sim];

Min[forecast]

Plot the data with the forecast given by the simulation:

Show[ListLinePlot[sales],ListLinePlot[sim,PlotStyle->Directive[Opacity[.2]]],
ListLinePlot[forecast,PlotStyle->Black],PlotRange->All]

OpenersExampleSubsubsection5(Spacer1)Retail Sales  (1)

Retail monthly sales in United States:

raw=WolframAlpha["usa retail sales",{{"History:RetailSales:EconomicData",1},"TimeSeriesData"}];

raw[[1]]

Create (RefLink[TimeSeries, paclet:ref/TimeSeries]) from the selection:

data=TimeSeries[{QuantityMagnitude[raw[[-12*15;;,2]]]},{Automatic,raw[[-1,1]],"Month"}]

Plot the sales with grid lines at December peaks:

grids=Table[{1992,12 i},{i,data["PathLength"]}];
DateListPlot[data,GridLines->{grids,None},AspectRatio->1/3]

Fit a seasonal model:

model=TimeSeriesModelFit[data,{"SARIMA",12}]

The process parameters:

proc=model["BestFit"]

Find the forecast for the next 7 years:

forecast=TimeSeriesForecast[model,{0,7*12}]

Calculate 95% confidence bands for the forecast:

α=.95;
q=Quantile[NormalDistribution[],1-(1-α)/2];
err=forecast["MeanSquaredErrors"];
bands=TimeSeriesThread[{{1,-q}.#,{1,q}.#}&,{forecast,Sqrt[err]}]

There is an upper and a lower band:

bands["ValueDimensions"]

Plot the forecast within the 95% confidence region:

grids=Table[{1992,12 i},{i,data["PathLength"]+forecast["PathLength"]}];

DateListPlot[{data,forecast,bands["PathComponent",1],bands["PathComponent",2]},Filling->{3->{4}},AspectRatio->1/3,PlotStyle->{Automatic,Automatic,Gray,Gray},GridLines->{grids,None}]

OpenersExampleSubsubsection6(Spacer1)Medical Sales and Advertising  (1)

The following time series are bi-quarterly sales and advertising of US patent-medicine proprietor Lydia Pinkham. Pinkham began making Vegetable Compound as a home remedy, sharing it with her neighbors. Her compound, a blend of ground herbs, was 18% alcohol by content. In 1875 the Pinkham family decided to go into business selling the medicine, which Pinkham claimed could cure any female complaint from nervous prostration to a prolapsed uterus. It quickly gained acceptance, and the business was soon grossing close to $300,000 a year. Not until the 1920s, when federal regulation of drugs and advertising increased, did the Lydia E. Pinkham Medicine Co. reduce both the alcohol content of the medicine and the claims for its efficacy:

sales=TemporalData[];

sales["Source"]

DateListPlot[sales,Filling->Axis]

Find a model for the data:

salesModel=TimeSeriesModelFit[sales]

Normal[salesModel]

Forecast the values for the next 5 years:

forecast=TimeSeriesForecast[salesModel,{2*5}]

The model predicts steep decline of customer trust in the efficacy of the Pinkham remedy:

DateListPlot[{sales,forecast},Filling->Axis]

OpenersExampleSection4(Spacer1)Possible Issues  (2)

The following data is sampled monthly and is known to have seasonality 12:

data=TimeSeries[];

data["Dates"]===TimeSeriesResample[data,"Month"]["Dates"]

DateListPlot[data,Joined->True]

(RefLink[TemporalData, paclet:ref/TemporalData]) does not know that the data is equally spaced by month:

RegularlySampledQ[data]

Automatic resampling at the minimum time increment of 28 days causes the seasonality to be 13:

MinimumTimeIncrement[data]

TimeSeriesModelFit[data]

Tell (RefLink[TemporalData, paclet:ref/TemporalData]) to treat the data as regular:

dataR=TimeSeries[data,TemporalRegularity->True];

RegularlySampledQ[dataR]

No resampling is necessary; the seasonality is preserved:

TimeSeriesModelFit[dataR]

(RefLink[TimeSeriesModelFit, paclet:ref/TimeSeriesModelFit]) uses a method of moments to estimate parameters of candidate processes. Use of different estimators may result in different ranking:

data=RandomFunction[MAProcess[{4/5,-4/5},1],{0,1000}];

tsm=TimeSeriesModelFit[data,{"MA",2},"IncludeConstantBasis"->False]

tsm["BestFit"]

The maximum likelihood estimate of the order 2:

mle=EstimatedProcess[data,MAProcess[{b1,b2},v],ProcessEstimator->"MaximumLikelihood"]

The maximum likelihood estimate is favored by every selection criterion:

criteria={"AIC","BIC","SBC","AICc"};mleCrits=TimeSeriesModelFit[data,mle][criteria];
bestFitCrits=tsm[criteria];

TableForm[{Style[#,Gray]&/@bestFitCrits,Style[#,Black]&/@mleCrits},TableHeadings->{{"BestFit","MLE"},criteria}]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[TimeSeriesModel, paclet:ref/TimeSeriesModel])  ▪  (RefLink[TimeSeriesForecast, paclet:ref/TimeSeriesForecast])  ▪  (RefLink[UnitRootTest, paclet:ref/UnitRootTest])  ▪  (RefLink[AutocorrelationTest, paclet:ref/AutocorrelationTest])  ▪  (RefLink[ARProcess, paclet:ref/ARProcess])  ▪  (RefLink[MAProcess, paclet:ref/MAProcess])  ▪  (RefLink[ARMAProcess, paclet:ref/ARMAProcess])  ▪  (RefLink[ARIMAProcess, paclet:ref/ARIMAProcess])  ▪  (RefLink[SARIMAProcess, paclet:ref/SARIMAProcess])  ▪  (RefLink[RandomFunction, paclet:ref/RandomFunction])  ▪  (RefLink[SequencePredict, paclet:ref/SequencePredict])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Time Series Processes, paclet:guide/TimeSeriesProcesses])}, {▪(RefLinkPlain[Time Series Processing, paclet:guide/TimeSeries])}, {▪(RefLinkPlain[Scientific Data Analysis, paclet:guide/ScientificDataAnalysis])}, {▪(RefLinkPlain[Scientific Models, paclet:guide/ScientificModels])}, {▪(RefLinkPlain[Using the Wolfram Data Drop, paclet:guide/UsingTheWolframDataDrop])}, {▪(RefLinkPlain[Image Computation for Microscopy, paclet:guide/ImageComputationForMicroscopy])}})}})