Time series models can vary widely depending on the structure of the data and the type of model desired, from a simple regression model to extremely complex ones. The basic data assumption is that all observations were taken at equally spaced intervals.
Time Series Graphs and Simple Trend Models
There are two ways in Excel to create a time series graph and fit a trend line.
You can create a time series graph using Insert ➔ Scatterplot with Straight Lines
. The time index (1, 2, …) or date (X) variable must be the left column in the two adjoining columns of data in the spreadsheet (use copy and paste to make the columns adjacent to one another, if needed).
Simple trend models can be fit using linear regression from the Data ➔ Data Analysis menu.
There are three options to create a time series graph.
Simple trend models can be fit using the time (or date) as X and the variable of interest as Y with Analyze ➔ Fit Y by X.
There are three options to create a time series graph.
Simple trend models can be fit using Stat ➔ Regression ➔ Regression ➔ Fit Regression Model with the variable of interest as the response and the time (or index) variable as a continuous predictor.
Assuming you have the correct version of the software (there are several from Base to Standard to Professional), there are two ways to create a time series plot.
Simple trend models can be fit using Analyze ➔ Regression ➔ Linear if you have a time variable (or index) in the data set. Click to enter the variable of interest as the dependent variable and the time variable as the independent variable.
Use Graphics ➔ Scatterplot. Define the plot with the time variable as the x variable and the statistic as y. Set the “Display” option to either “Line” or “Both.”
Simple trend models can be fit using Statistics ➔ Regression ➔ Simple Linear. Use the time variable as the independent variable and the variable of interest as the dependent variable.
You can create the time series plot using the connected Scatterplot (
) option from 2nd Y= (STAT PLOTS). Define the plot with the time variable as the x variable and the variable of interest as y.
Simple trend models can be fit using STAT ➔ Calc ➔ LinReg(a+bX).
The simplest way to graph a time series is with the time series plot command
> ts.plot(var)
You can also use the regular plot command. The type=“1” part tells R to connect the points. Note that no time variable is needed here.
> plot(var,type=“1”,xlab=“time”,ylab=“Variable Name”)
The simple trend model can be fit using lm (linear model) command as detailed in Chapters 2 and 10.
Trend with Seasonality
These models allow cyclical behavior in the variable of interest. You need one fewer indicator variable than there are periods in the year (3 for quarterly data, for example). They are fit as a multiple regression.
Data files may have dates entered as, for example, 01/2010. We need to separate the month from the date to add the indicator variable while preserving the original for the trend part of the model.
Data files may have dates entered as, for example, 01/2010. We need to separate the month from the date to add the indicator variable while preserving the original for the trend part of the model. This requires an add-in that can be found at https://community.jmp.com/docs/DOC-7537. You need only install this add-in once. (This procedure also works for quarterly data.)
Data files may have dates entered as, for example, 01/2010. We need to separate the month from the date to add the indicator variable while preserving the original for the trend part of the model.
Data files may have dates entered as, for example, 01/2010. We need to separate the month from the date to add the indicator variable while preserving the original for the trend part of the model (requires Python Essentials).
Data files may have dates entered as, for example, 01/2010. We need to separate the month from the date to add the indicator variable while preserving the original for the trend part of the model. The first step here ensures R understands the date as a date.
> date<-as.Date(Month,format=“%m/%d/%y”)
Next, extract the month from the date
> month2<-format(date,“%m”)
Create the indicator variables
> month.f=factor(month2)
> dummies=model.matrix(~month.f)
Perform the regression
> res = lm(Retail.Sales ~ date + dummies)
Lag Regression Models
These models exploit the relationship between an observation and its previous value. The degree of relationship is measured by the autocorrelation function.
To find the autocorrelations in a time series, copy and paste the column of data (with the variable of interest) so it is offset by 1 observation (paste so the first observation is now paired with the second). Use Data ➔ Data Analysis ➔ Correlation to find the correlation of (Yt, Yt−1).
Use Data ➔ Data Analysis ➔ Regresson to fit the model using the offset column as the predictor (X).
To find the autocorrelation (and partial autocorrelation) in a time series, use Analyze ➔ Time Series (in the student version) or Analyze ➔ Modeling ➔ Time Series (in the full version). Click to enter the variable of interest into the “Y, Time Series” block and (if desired) the dates into the “X, Time ID” block. You can set the number of autocorrelation lags to something like 2 from the default 25. Click “OK.”
To fit the autoregressive model, there are two options.
Find the autocorrelation (partial autocorrelation) using Stat ➔ Time Series ➔ Autocorrelation (Partial Autocorrelation). Click to select and enter the series variable name. You can also move the radio button to only ask for a reasonable (2 or 3) autocorrelation lags.
To fit the model, you have two options:
Use Stat ➔ Time Series ➔ ARIMA and set the Autoregressive order to 1 (or the desired number of lags),
or
Use Analyze ➔ Forecasting ➔ (Partial) Autocorrelations to find the (partial) autocorrelation. Click to select and enter the time series as the variable. Uncheck the box for Partial Autocorrelations. To limit the number of autocorrelations shown, click “Options,” then enter a smaller number (like 2 or 3). Click “Continue” to return to the main dialog and click “OK.”
To fit the model, first lag the series. Use Transform ➔ Shift Values. Click to select and enter the series name. Enter a name for the result variable in the box labeled “Name.” Click “Change.” The default is a 1 period lag; if a different lag is desired, enter that. Click “OK.” Use Analyze ➔ Regression ➔ Linear to fit the model using the lagged variable as the predictor.
Create a lagged time series using the following steps:
For the autocorrelation and regression, use STAT , Calc, 8:LinReg a+bx using the original list as Y and the new list as X. For example, LinReg (a+bx)L2,L1.
For the autocorrelation (or partial autocorrelation), the command shown below uses “series” as the name of the variable; nn is a reasonable number (usually 2 or 3) for the maximum lag to consider, and plot=F tells R to display the numeric coefficients instead of simply plotting them. For partial autocorrelations, the command is pacf with the same parameters.
> acf(series,lag.max=nn, plot=F)
To create a lagged series by one time step, use the command like
> lagseries <- lag(series,k=-1)
where “series” is the name of the original time series. For the regression, use a command like
> res = lm(Retail.Sales~lagseries)
Moving Average and Smoothing Models
Moving average (MA) models smooth a time series by sliding a window of width k and computing the average of those k previous observations to replace observation yt. Exponential smoothing models use a weighted average of the previous observation and its forecast, which progressively lowers the weight (impact) of observations far distant on the estimate of a current value.
For a moving average, use Data ➔ Data Analysis ➔ Moving Average.
For exponential smoothing, use Data ➔ Data Analysis ➔ Exponential Smoothing.
Use Analyze ➔ Time Series as discussed earlier.
For moving average smoothing, click the red triangle at the top of the output and select Smoothing Model ➔ Simple Moving Average.
For exponential smoothing as described in your text, click the red triangle at the top of the output and select Smoothing Model ➔ Simple Exponential Smoothing.
For a moving average smooth, use Stat ➔ Time Series ➔ Moving Average.
For exponential smoothing, use Stat ➔ Time Series ➔ Single Exp Smoothing.
SPSS does not have a built-in function to do moving average smoothing.
SPSS can do exponential smoothing, but not with specified weights. The system will determine an “optimal” weight or you if you use Analyze ➔ Forecasting ➔ Create Traditional Models and move the drop-down to “Exponential smoothing.”
Using these methods requires we actually declare the variable to be a time series. Use the ts command as illustrated below. The terms “frequency” and “start” are optional, but can be used to specify the time labels. For example, “frequency=12,start=c(2000,)1” means that the series is monthly and starts in January, 2000.
> Vartimeseries <-ts(var, frequency=nn, start=c(t1,inc)
With this definition, you can also use plot.ts to plot the time series as
> plot.ts(vartimeseries)
The smoothing commands shown below require you to install and load the package TTR. (Click Packages ➔ Set CRAN Mirror and choose a site; Packages ➔ Install Package and locate TTR; Packages ➔ Load Package ➔ TTR.)
A moving average smooth of length k is created with the SMA command. Use plot. ts to see the smoothed time series.
> SMA(vartimeseries,n=k)
The exponential smooth is created with the HoltWinters function. with alpha being the specified weight. Plotting this afterward shows both the smooth and the original series.
> ExpSM <-HoltWinters(vartimeseries,Gamma=F, Beta=F, alpha = wt)