TSMBFIN
Boston dataset - Multiple linear regression
# Boston dataset Regression attach(Boston)summary(Boston)plot(Boston$medv,Boston$lstat) #Data Partition P1 = runif(506)P2 = order(P1)training_ds = Boston[P2[1:350],]testing_ds = Boston[P2[351:506],] # Model Building Linearmodel = lm(medv~lstat+age, data = training_ds)abline(Linearmodel, col = "red", lwd = 3)plot(Linearmodel)predicted_values = predict(Linearmodel, newdata = testing_ds) testing_ds$pred_medv = predicted_values
AirPassengers plot
# set the time series to Air PassengersAP= AirPassengersplot(AP)#Compare Additive VS Multiplicative model.plot(decompose(AP))plot(decompose(AP,type = "multiplicative"))
There are three general settings in which judgmental forecasting is used:
(i) there are no available data, so that statistical methods are not applicable and judgmental forecasting is the only feasible approach. (ii) data are available, statistical forecasts are generated, and these are then adjusted using judgement (iii) data are available and statistical and judgmental forecasts are generated independently and then combined.
Examples of time series data include:
1. Daily IBM stock prices 2. Monthly rainfall 3. Quarterly sales results for Amazon 4. Annual Google profits Anything that is observed sequentially over time is a time series. In this book, we will only consider time series that are observed at regular intervals of time (e.g., hourly, daily, weekly, monthly, quarterly, annually)
What can be forecast? • Forecasting is required in many situations:
1. Deciding whether to build another power generation plant in the next five years requires forecasts of future demand; 2. Scheduling staff in a Call Centre next week requires forecasts of call volumes; stocking an inventory requires forecasts of stock requirements. Forecasts can be required several years in advance (for the case of capital investments), or only a few minutes beforehand (for telecommunication routing). 3. Whatever the circumstances or time horizons involved, forecasting is an important aid to effective and efficient planning.
Transformations and adjustments
Adjusting the historical data can often lead to a simpler forecasting task. • We will deal with four kinds of adjustments: 1. calendar adjustments 2. population adjustments 3. inflation adjustments 4. mathematical transformations. •The purpose of these adjustments and transformations is to simplify the patterns in the historical data by removing known sources of variation or by making the pattern more consistent across the whole data set. •Simpler patterns usually lead to more accurate forecasts.
Time series decomposition Using the dataset nottem•
Average of temp per month dataset.nottemtemp = nottemstr(temp)class(temp)x = stl(temp, s.window = "periodic")plot(x)
Autocorrelation
Just as correlation measures the extent of a linear relationship between two variables, autocorrelation measures the linear relationship between lagged values of a time series.
Seasonal naïve method
A similar method is useful for highly seasonal data. In this case, we set each forecast to be equal to the last observed value from the same season of the year (e.g., the same month of the previous year). snaive( y, h )
Classical decomposition
•The classical decomposition method originated in the 1920s. •It is a relatively simple procedure, and forms the starting point for most other methods of time series decomposition. • There are two forms of classical decomposition: an additive decomposition and a multiplicative decomposition. •These are described below for a time series with seasonal period m (e.g., m=4 for quarterly data, m=12 for monthly data, m=7 for daily data with a weekly pattern). •In classical decomposition, we assume that the seasonal component is constant from year to year. For multiplicative seasonality, the m values that form the seasonal component are sometimes called the "seasonal indices". elecequip %>% decompose(type="multiplicative") %>%autoplot() + xlab("Year") +ggtitle("Classical multiplicative decompositionof electrical equipment index") •While classical decomposition is still widely used, it is not recommended, as there are now several much better methods.
Moving averages
•The classical method of time series decomposition originated in the 1920s and was widely used until the 1950s. •It still forms the basis of many time series decomposition methods, so it is important to understand how it works. •The first step in a classical decomposition is to use a moving average method to estimate the trend-cycle, so we begin by discussing moving averages.
New product forecasting
•The definition of a new product can vary. It may be an entirely new product which has been launched, a variation of an existing product ("new and improved"), a change in the pricing scheme of an existing product, or even an existing product entering a new market. •Judgmental forecasting is usually the only available method for new product forecasting, as historical data are unavailable. The approaches we have already outlined (Delphi, forecasting by analogy and scenario forecasting) are all applicable when forecasting the demand for a new product.
Time series graphics
•The first thing to do in any data analysis task is to plot the data. •Graphs enable many features of the data to be visualised, including patterns, unusual observations, changes over time, and relationships between variables. •The features that are seen in plots of the data must then be incorporated, as much as possible, into the forecasting methods to be used. •Just as the type of data determines what forecasting method to use, it also determines what graphs are appropriate.
What is forecast horizon?
•The forecast horizon is the length of time into the future for which forecasts are to be prepared. •The future period of time for which a demand forecast is generated, typically as long as the longest single-item cumulative lead time (on a monthly planning basis) or for 2-5 year periods for strategic planning.
Average method
•The forecasts of all future values are equal to the average (or "mean") of the historical data. •Forecast Horizon refers to a duration in time at a future point in time on which predictions are to be drawn.
•The mstl() function provides a convenient automated STL decomposition using s.window=13, and t.window also chosen automatically.
•This usually gives a good balance between overfitting the seasonality and allowing it to slowly change over time. •But, as with any automated procedure, the default settings will need adjusting for some time series. •As with the other decomposition methods discussed in this book, to obtain the separate components use the seasonal() function for the seasonal component, the trendcycle() function for trend-cycle component, and the remainder() function for the remainder component. •The seasadj() function can be used to compute the seasonally adjusted series.
Time series decomposition
•Time series data can exhibit a variety of patterns, and it is often helpful to split a time series into several components, each representing an underlying pattern category. •Thus we think of a time series as comprising three components: a trend-cycle component, a seasonal component, and a remainder component (containing anything else in the time series).
Time series models
•Time series models used for forecasting include: 1. decomposition models 2. exponential smoothing models 3. ARIMA models
The Forecaster's Toolbox
•We will discuss some general tools that are useful for many different forecasting situations. •We will describe some benchmark forecasting methods, ways of making the forecasting task simpler using transformations and adjustments, methods for checking whether a forecasting method has adequately utilized the available information, and techniques for computing prediction intervals.
Electrical equipment manufacturing - trend-cycle estimate
ma(elecsales, 5) ************************************ autoplot(elecsales, series="Data") + autolayer(ma(elecsales,5), series="5-MA") + xlab("Year") + ylab("GWh") + ggtitle("Annual electricity sales: South Australia") + scale_colour_manual(values=c("Data"="grey50","5-MA"="red"), breaks=c("Data","5-MA"))
Lung Cap Dataset - Multiple linear regression
model1 <- lm(LungCap ~ Age + Height)summary(model1)cor(Age, Height, method = "pearson") #highly correlatedmodel2 <- lm(LungCap ~ Age + Height + Smoke + Gender + Caesarean)summary(model2)# regression diagnostic plots for this modelplot(model2)
Mouse.data Simple linear regression
mouse.data = data.frame( size = c(1.4, 2.6, 1.0, 3.7, 5.5, 3.2, 3.0, 4.9, 6.3), weight = c(0.9, 1.8, 2.4, 3.5, 3.9, 4.4, 5.1, 5.6, 6.3), tail = c(0.7, 1.3, 0.7, 2.0, 3.6, 3.0, 2.9, 3.9, 4.0)) mouse.dataplot(mouse.data$weight, mouse.data$size)simpleregression = lm(size ~ weight, data = mouse.data)summary(simpleregression)abline(simpleregression, col = "red", lwd =2)
Additive decompose.
plot(decompose(AP))
•Multiplicative decomposition
plot(decompose(AP,type = "multiplicative"))
Mouse.data - Multiple regression
plot(mouse.data)multipleregression = lm(size ~ weight + tail, data = mouse.data)summary(multipleregression)
Scatter Plot - Demand/Temperature in Victoria, Australia
qplot(Temperature, Demand, data=as.data.frame(elecdemand)) + ylab("Demand (GW)") + xlab("Temperature (Celsius)")
Lets apply first three methods applied to the quarterly beer production data.
• # Set training data from 1992 to 2007 beer2 <- window(ausbeer,start=1992,end=c(2007,4)) # Plot some forecasts autoplot(beer2) + autolayer(meanf(beer2, h=11), series="Mean", PI=FALSE) + autolayer(naive(beer2, h=11), series="Naïve", PI=FALSE) + autolayer(snaive(beer2, h=11), series="Seasonal naïve", PI=FALSE) + ggtitle("Forecasts for quarterly beer production") + xlab("Year") + ylab("Megalitres") + guides(colour=guide_legend(title="Forecast"))
Scenario forecasting
• A fundamentally different approach to judgmental forecasting is scenario-based forecasting. • The aim of this approach is to generate forecasts based on plausible scenarios. • The scenarios are generated by considering all possible factors or drivers, their relative impacts, the interactions between them, and the targets to be forecast. • Building forecasts based on scenarios allows a wide range of possible forecasts to be generated and some extremes to be identified. For example it is usual for "best," "middle" and "worst" case scenarios to be presented, although many other scenarios will be generated. Thinking about and documenting these contrasting extremes can lead to early contingency planning. • With scenario forecasting, decision makers often participate in the generation of scenarios. While this may lead to some biases, it can ease the communication of the scenario-based forecasts, and lead to a better understanding of the results.
Seasonal Plots
• A seasonal plot is similar to a time plot except that the data are plotted against the individual "seasons" in which the data were observed. Code1 ggseasonplot(a10, year.labels=TRUE, year.labels.left=TRUE) + ylab("$ million") + ggtitle("Seasonal plot: antidiabetic drug sales") Code2 ggseasonplot(a10, polar=TRUE) + ylab("$ million") + ggtitle("Polar seasonal plot: antidiabetic drug sales")
ts objects
• A time series can be thought of as a list of numbers, along with some information about what times those numbers were recorded. For observations that are more frequent than once per year, you simply add a [frequency] argument. For example, if your monthly data is already stored as a numerical vector [z], then it can be converted to a [ts] object like this: y <- ts(z, start=2003, frequency=12) Almost all of the data used in this book is already stored as [ts] objects. But if you want to work with your own data, ou will need to use the ts() function before proceeding with the analysis.
Forecasting by analogy- A structured analogy
• Alternatively, a structured approach comprising a panel of experts can be implemented, as was proposed by Green & Armstrong (2007). The concept is similar to that of a Delphi; however, the forecasting task is completed by considering analogies. • First, a facilitator is appointed. Then the structured approach involves the following steps. 1.A panel of experts who are likely to have experience with analogous situations is assembled. 2.Tasks/challenges are set and distributed to the experts. 3.Experts identify and describe as many analogies as they can, and generate forecasts based on each analogy. 4.Experts list similarities and differences of each analogy to the target situation, then rate the similarity of each analogy to the target situation on a scale. 5.Forecasts are derived by the facilitator using a set rule. This can be a weighted average, where the weights can be guided by the ranking scores of each analogy by the experts.
Population adjustments
• Any data that are affected by population changes can be adjusted to give per-capita data. That is, consider the data per person (or per thousand people, or per million people) rather than the total. • For example, if you are studying the number of hospital beds in a particular region over time, the results are much easier to interpret if you remove the effects of population changes by considering the number of beds per thousand people. Then you can see whether there have been real increases in the number of beds, or whether the increases are due entirely to population increases.
New product forecasting-Customer intentions
• Customer intentions can be used to forecast the demand for a new product or for a variation on an existing product. • Questionnaires are filled in by customers on their intentions to buy the product. • A structured questionnaire is used, asking customers to rate the likelihood of them purchasing the product on a scale; for example, highly likely, likely, possible, unlikely, highly unlikely. • Survey designed challenges needs to be addressed. • Whichever method of new product forecasting is used, it is important to thoroughly document the forecasts made, and the reasoning behind them, in order to be able to evaluate them when data become available.
Inflation adjustments
• Data which are affected by the value of money are best adjusted before modelling. For example, the average cost of a new house will have increased over the last few decades due to inflation. A $200,000 house this year is not the same as a $200,000 house twenty years ago. For this reason, financial time series are usually adjusted so that all values are stated in dollar values from a particular year. For example, the house price data may be stated in year 2000 dollars. • To make these adjustments, a price index is used. If zt denotes the price index and yt denotes the original house price in year t, then xt=yt/zt∗ z2000 gives the adjusted house price at year 2000 dollar values. Price indexes are often constructed by government agencies. For consumer goods, a common price index is the Consumer Price Index (or CPI).
Time plots
• For time series data, the obvious graph to start with is a time plot. That is, the observations are plotted against the time of observation, with consecutive observations joined by straight lines
Calendar adjustments
• If you are studying the monthly milk production on a farm, there will be variation between the months simply because of the different numbers of days in each month, in addition to the seasonal variation across the year. dframe <- cbind(Monthly = milk, DailyAverage = milk/monthdays(milk)) autoplot(dframe, facet=TRUE) + xlab("Years") + ylab("Pounds") + ggtitle("Milk production per cow") •Notice how much simpler the seasonal pattern is in the average daily production plot compared to the total monthly production plot. By looking at the average daily production instead of the total monthly production, we effectively remove the variation due to the different month lengths. Simpler patterns are usually easier to model and lead to more accurate forecasts. •A similar adjustment can be done for sales data when the number of trading days in each month varies. In this case, the sales per trading day can be modelled instead of the total sales for each month.
Judgmental Forecasts
• In many cases, judgmental forecasting is the only option, such as when there is a complete lack of historical data, or when a new product is being launched, or when a new competitor enters the market, or during completely new and unique market conditions. • There are also situations where the data are incomplete, or only become available after some delay. • Research in this area has shown that the accuracy of judgmental forecasting improves when the forecaster has (i) important domain knowledge, and (ii) more timely, up-to-date information. A judgmental approach can be quick to adjust to such changes, information or events. • It is important to recognize that judgmental forecasting is subjective and comes with limitations
Beware of limitations
• Judgmental forecasts are subjective, and therefore do not come free of bias or limitations. • Judgmental forecasts can be inconsistent. Unlike statistical forecasts, which can be generated by the same mathematical formulas every time, judgmental forecasts depend heavily on human cognition, and are vulnerable to its limitations. • human judgement can vary due to the effect of psychological factors. One can imagine a manager who is in a positive frame of mind one day, generating forecasts that may tend to be somewhat optimistic, and in a negative frame of mind another day, generating somewhat less optimistic forecasts. • For example, it is common to take the last observed value as a reference point. The forecaster is influenced unduly by prior information, and therefore gives this more weight in the forecasting process. Anchoring may lead to conservatism and undervaluing new and more current information, and thereby create a systematic bias.
• The two main parameters to be chosen when using STL are the trend-cycle window (t.window) and the seasonal window (s.window).
• These control how rapidly the trend-cycle and seasonal components can change. Smaller values allow for more rapid changes. • Both t.window and s.window should be odd numbers; t.window is the number of consecutive observations to be used when estimating the trend-cycle; s.window is the number of consecutive years to be used in estimating each value in the seasonal component. • The user must specify s.window as there is no default. • Setting it to be infinite is equivalent to forcing the seasonal component to be periodic (i.e., identical across years). Specifying t.window is optional, and a default value will be used if it is omitted.
Judgmental adjustments
• We consider the situation where historical data are available and are used to generate statistical forecasts. It is common for practitioners to then apply judgmental adjustments to these forecasts. These adjustments can potentially provide all of the advantages of judgmental forecasting which have been discussed earlier. • Judgmental adjustments, like judgmental forecasts, come with biases and limitations, and we must implement methodical strategies in order to minimize them. 1. Use adjustments sparingly 2. Apply a structured approach
The linear model Assumptions
• When we use a linear regression model, we are implicitly making some assumptions about the variables.1. First, we assume that the model is a reasonable approximation to reality; that is, the relationship between the forecast variable and the predictor variables satisfies this linear equation.2. Second, we make the following assumptions about the errors (ε1,...,εT)(ε1,...,εT):• they have mean zero; otherwise the forecasts will be systematically biased.• they are not autocorrelated; otherwise the forecasts will be inefficient, as there is more information in the data that can be exploited.• they are unrelated to the predictor variables; otherwise there would be more information that should be included in the systematic part of the model.
SEATS decomposition
•"SEATS" stands for "Seasonal Extraction in ARIMA Time Series" •We will study ARIMA model later. •This procedure was developed at the Bank of Spain, and is now widely used by government agencies around the world. •The procedure works only with quarterly and monthly data. •So seasonality of other kinds, such as daily data, or hourly data, or weekly data, require an alternative approach •The result is quite similar to the X11 decomposition. •STL is a versatile and robust method for decomposing time series. • STL is an acronym for "Seasonal and Trend decomposition using Loess", while Loess is a method for estimating nonlinear relationships
Forecasting by analogy-Designing a high school curriculum
•A small group of academics and teachers were assigned the task of developing a curriculum for teaching judgement and decision making under uncertainty for high schools in Israel. Each group member was asked to forecast how long it would take for the curriculum to be completed. Responses ranged between 18 and 30 months. One of the group members who was an expert in curriculum design was asked to consider analogous curricula developments around the world. He concluded that 40% of analogous groups he considered never completed the task. The rest took between 7 to 10 years. The Israel project was completed in 8 years.
Forecasting by analogy
•A useful judgmental approach which is often implemented in practice is forecasting by analogy. •A common example is the pricing of a house through an appraisal process. An appraiser estimates the market value of a house by comparing it to similar properties that have sold in the area. The degree of similarity depends on the attributes considered. With house appraisals, attributes such as land size, dwelling size, numbers of bedrooms and bathrooms, and garage space are usually considered.
Drift Method
•A variation on the naïve method is to allow the forecasts to increase or decrease over time, where the amount of change over time (called the drift) is set to be the average change seen in the historical data.
Seasonal subseries plots
•An alternative plot that emphasises the seasonal patterns is where the data for each season are collected together in separate mini time plots. ggsubseriesplot(a10) + ylab("$ million") + ggtitle("Seasonal subseries plot: antidiabetic drug sales")
X11 decomposition
•Another popular method for decomposing quarterly and monthly data is the X11 method which originated in the US Census Bureau and Statistics Canada. •This method is based on classical decomposition, but includes many extra steps and features in order to overcome the drawbacks of classical decomposition •The process is entirely automatic and tends to be highly robust to outliers and level shifts in the time series. •The details of the X11 method are described in Dagum & Bianconcini (2016). Here we will only demonstrate how to use the automatic procedure in R. •Compare this decomposition with the STL decomposition shown in Figure 6.1 and the classical decomposition shown in Figure 6.8. The X11 trend-cycle has captured the sudden fall in the data in early 2009 better than either of the other two methods, and the unusual observation at the end of 2009 is now more clearly seen in the remainder component.
Forecasting
•Before starting time series modelling for business, lets see what is forecasting. •Forecasting in ancient times: Forecasting has fascinated people for thousands of years, sometimes being considered a sign of divine inspiration, and sometimes being seen as a criminal activity. • Consider the following famous predictions about computing. 1. I think there is a world market for maybe five computers. (Chairman of IBM, 1943) 2. Computers in the future may weigh no more than 1.5 tons. (Popular Mechanics, 1949) 3. There is no reason anyone would want a computer in their home. (President, DEC, 1977). 4. The last of these was made only three years before IBM produced the first personal computer. Not surprisingly, you can no longer buy a DEC computer. Forecasting is obviously a difficult activity, and businesses that do it well have a big advantage over those whose forecasts fail.
Weighted moving averages
•Combinations of moving averages result in weighted moving averages. For example, the 2×4-MA discussed above is equivalent to a weighted 5-MA A major advantage of weighted moving averages is that they yield a smoother estimate of the trend-cycle. Instead of observations entering and leaving the calculation at full weight, their weights slowly increase and then slowly decrease, resulting in a smoother curve.
Forecasting, planning, and goals
•Forecasting is about predicting the future as accurately as possible, given all of the information available, including historical data and knowledge of any future events that might impact the forecasts. •Goals are what you would like to have happen. Goals should be linked to forecasts and plans, but this does not always occur. Too often, goals are set without any plan for how to achieve them, and no forecasts for whether they are realistic. •Planning is a response to forecasts and goals. Planning involves determining the appropriate actions that are required to make your forecasts match your goals.
Mathematical adjustments
•If the data show variation that increases or decreases with the level of the series, then a transformation can be useful. For example, a logarithmic transformation is often useful. •Sometimes other transformations are also used (although they are not so interpretable). For example, square roots and cube roots can be used. These are called power transformations. •A useful family of transformations, that includes both logarithms and power transformations, is the family of Box-Cox transformations
Electrical equipment manufacturing - Seasonally adjusted data
•If the seasonal component is removed from the original data, the resulting values are the "seasonally adjusted" data. •For an additive decomposition, the seasonally adjusted data are given by yt−St, and for multiplicative data, the seasonally adjusted values are obtained using yt/St. •For example, monthly unemployment data are usually seasonally adjusted in order to highlight variation due to the underlying state of the economy rather than the seasonal variation. •An increase in unemployment due to school leavers seeking work is seasonal variation, while an increase in unemployment due to an economic recession is non-seasonal. •Most economic analysts who study unemployment data are more interested in the non-seasonal variation. Consequently, employment data (and many other economic series) are usually seasonally adjusted.
The linear model - Simple linear regression
•In the simplest case, the regression model allows for a linear relationship between the forecast variable y and a single predictor variable x. yt=β0+β1xt+εt. •The coefficients β0 and β1 denote the intercept and the slope of the line respectively. •The intercept β0 represents the predicted value of y when x=0. The slope β1 represents the average predicted change in y resulting from a one unit increase in x •Notice that the observations do not lie on the straight line but are scattered around it. •We can think of each observation yt as consisting of the systematic or explained part of the model, β0+β1xt, and the random "error," εt. •The "error" term does not imply a mistake, but a deviation from the underlying straight line model. It captures anything that may affect yt other than xt.
New product forecasting- Sales force composite
•In this approach, forecasts for each outlet/branch/store of a company are generated by salespeople, and are then aggregated. •Involves sales manager.•As sales person are close to customer & product, they bring valuable experience in forecasting. •But however it can create bias as the user and forecaster is same. •Moreover a successful salesperson is not necessarily a successful nor well-informed forecaster.
Moving averages of moving averages
•It is possible to apply a moving average to a moving average. One reason for doing this is to make an even-order moving average symmetric. •For example, we might take a moving average of order 4, and then apply another moving average of order 2 to the results. beer2 <- window(ausbeer,start=1992)ma4 <- ma(beer2, order=4, centre=FALSE)ma2x4 <- ma(beer2, order=4, centre=TRUE) •When a 2-MA follows a moving average of an even order (such as 4), it is called a "centred moving average of order 4". •This is because the results are now symmetric. •In general, an even order MA should be followed by an even order MA to make it symmetric. Similarly, an odd order MA should be followed by an odd order MA.
Correlation
•Measures the strength of relationship between two variables. •The value lies between -1 & 1. •If -ve: then it shows negative linear relationship and vice versa. •It only measures the strength of relationship and can be sometimes misleading.
Electrical equipment manufacturing - Trends
•Notice that the seasonal component changes slowly over time, so that any two consecutive years have similar patterns, but years far apart may have different seasonal patterns. •The remainder component shown in the bottom panel is what is left over when the seasonal and trend-cycle components have been subtracted from the data. •The grey bars to the right of each panel show the relative scales of the components. •Each grey bar represents the same length but because the plots are on different scales, the bars vary in size. •The large grey bar in the bottom panel shows that the variation in the remainder component is small compared to the variation in the data, which has a bar about one quarter the size. •If we shrunk the bottom three panels until their bars became the same size as that in the data panel, then all the panels would be on the same scale.
The appropriate forecasting methods depend largely on what data are available.
•Qualitative forecasting: If there are no data available, or if the data available are not relevant to the forecasts. These methods are not purely guesswork—there are well-developed structured approaches to obtaining good forecasts without using historical data. •Quantitative forecasting can be applied when two conditions are satisfied: 1. Numerical information about the past is available; 2. It is reasonable to assume that some aspects of the past patterns will continue into the future.
Forecast 1 & 2
•Sometimes one of these simple methods will be the best forecasting method available; but in many cases, these methods will serve as benchmarks rather than the method of choice. •That is, any forecasting methods we develop will be compared to these simple methods to ensure that the new method is better than these simple alternatives. If not, the new method is not worth considering.
The Delphi method
•The Delphi method was invented by Olaf Helmer and Norman Dalkey of the Rand Corporation in the 1950s for the purpose of addressing a specific military problem. •The method relies on the key assumption that forecasts from a group are generally more accurate than those from individuals. •The aim of the Delphi method is to construct consensus forecasts from a group of experts in a structured iterative manner. •A facilitator is appointed in order to implement and manage the process.
Time series regression models
•The basic concept is that we forecast the time series of interest y assuming that it has a linear relationship with other time series x. •For example, we might wish to forecast monthly sales y using total advertising spend x as a predictor. •The forecast variable y is sometimes also called the regressand, dependent or explained variable. The predictor variables x are sometimes also called the regressors, independent or explanatory variables
Time series forecasting: Figure shows the quarterly Australian beer production from 1992 to the second quarter of 2010.
•The blue lines show forecasts for the next two years. Notice how the forecasts have captured the seasonal pattern seen in the historical data and replicated it for the next two years. •The dark shaded region shows 80% prediction intervals. That is, each future value is expected to lie in the dark shaded region with a probability of 80%. •The light shaded region shows 95% prediction intervals. These prediction intervals are a useful way of displaying the uncertainty in forecasts. In this case the forecasts are expected to be accurate, and hence the prediction intervals are quite narrow.
Key Principles: Using a systematic and well structured approach in judgmental forecasting helps to reduce the adverse effects of the limitations of judgmental forecasting.
1. Set the forecasting task clearly and concisely 2. Implement a systematic approach 3. Document and justify 4. Systematically evaluate forecasts 5. Segregate forecasters and users
Modern organizations require short-term, medium-term and long-term forecasts, depending on the specific application.
1. Short term forecasts are needed for the scheduling of personnel, production and transportation. As part of the scheduling process, forecasts of demand are often also required. 2. Medium term forecasts are needed to determine future resource requirements, in order to purchase raw materials, hire personnel, or buy machinery and equipment. 3. Long term forecasts are used in strategic planning. Such decisions must take account of market opportunities, environmental factors and internal resources.
• STL has several advantages over the classical, SEATS and X11 decomposition methods:
1. Unlike SEATS and X11, STL will handle any type of seasonality, not only monthly and quarterly data. 2. The seasonal component is allowed to change over time, and the rate of change can be controlled by the user. 3. The smoothness of the trend-cycle can also be controlled by the user. 4. It can be robust to outliers (i.e., the user can specify a robust decomposition), so that occasional unusual observations will not affect the estimates of the trend-cycle and seasonal components. They will, however, affect the remainder component.
What can be forecast? - The predictability of an event or a quantity depends on several factors including:
1. how well we understand the factors that contribute to it; 2. how much data is available; 3. whether the forecasts can affect the thing we are trying to forecast. For eg:• Forecasts of electricity demand can be highly accurate.• On the other hand, when forecasting currency exchange rates, only one of the conditions is satisfied: there is plenty of available data.
Stages involved in the Delphi method:
1.A panel of experts is assembled. 2.Forecasting tasks/challenges are set and distributed to the experts. 3.Experts return initial forecasts and justifications. These are compiled and summarized in order to provide feedback. 4.Feedback is provided to the experts, who now review their forecasts in light of the feedback. This step may be iterated until a satisfactory level of consensus is reached. 5.Final forecasts are constructed by aggregating the experts' forecasts.
Naïve method
For naïve forecasts, we simply set all forecasts to be the value of the last observation. •This method works remarkably well for many economic and financial time series. These are also called random walk forecasts
Additive and Multiplicative Decomposition
If we assume an additive decomposition, then we can write yt=St+Tt+Rt, where yt is the data, St is the seasonal component, Tt is the trend-cycle component, and Rt is the remainder component, all at period t. Alternatively, a multiplicative decomposition would be written as yt=St×Tt×Rt. The additive decomposition is the most appropriate if the magnitude of the seasonal fluctuations, or the variation around the trend-cycle, does not vary with the level of the time series. When the variation in the seasonal pattern, or the variation around the trend-cycle, appears to be proportional to the level of the time series, then a multiplicative decomposition is more appropriate. Multiplicative decompositions are common with economic time series.
New product forecasting-Executive Opinion
In contrast to the sales force composite, this approach involves staff at the top of the managerial structure generating aggregate forecasts. • Such forecasts are usually generated in a group meeting, where executives contribute information from their own area of the company. • Having executives from different functional areas of the company promotes great skill and knowledge diversity in the group. • In this setting, it is important to justify and document the forecasting process. • That is, executives need to be held accountable in order to reduce the biases generated by the group meeting setting.
On the other hand, STL has some disadvantages
In particular, it does not handle trading day or calendar variation automatically, and it only provides facilities for additive decompositions.elecequip %>% stl(t.window=13, s.window="periodic", robust=TRUE) %>% autoplot()
Frequency of a time series
The "frequency" is the number of observations before the seasonal pattern repeats.1 When using the ts() function in R, the following choices should be used.
Electrical equipment manufacturing
The data show the number of new orders for electrical equipment (computer, electronic and optical products) in the Euro area (16 countries). •The trend-cycle shows the overall movement in the series, ignoring the seasonality and any small random fluctuations. •The next figure shows an additive decomposition of these data. The method used for estimating components in this example is STL, which is discussed in later part.
Time series patterns
Trend • A trend exists when there is a long-term increase or decrease in the data. It does not have to be linear. Sometimes we will refer to a trend as "changing direction," when it might go from an increasing trend to a decreasing trend. There is a trend in the antidiabetic drug sales data shown in Figure 2.2. Seasonal • A seasonal pattern occurs when a time series is affected by seasonal factors such as the time of the year or the day of the week. Seasonality is always of a fixed and known frequency. The monthly sales of antidiabetic drugs above shows seasonality which is induced partly by the change in the cost of the drugs at the end of the calendar year. Cyclic • A cycle occurs when the data exhibit rises and falls that are not of a fixed frequency. These fluctuations are usually due to economic conditions, and are often related to the "business cycle." The duration of these fluctuations is usually at least 2 years.
The linear model - Multiple linear regression
When there are two or more predictor variables, the model is called a multiple regression model. yt=β0+β1x1,t+β2x2,t+⋯+βkxk,t+εt, •where y is the variable to be forecast and x1,...,xk are the k predictor variables. Each of the predictor variables must be numerical. The coefficients β1,...,βk measure the effect of each predictor after taking into account the effects of all the other predictors in the model. Thus, the coefficients measure the marginal effects of the predictor variables. Example: US consumption expenditure Building a multiple linear regression model can potentially generate more accurate forecasts as we expect consumption expenditure to not only depend on personal income but on other predictors as well.
Forecasting with decomposition
While decomposition is primarily useful for studying time series data, and exploring historical changes over time, it can also be used in forecasting. Assuming an additive decomposition, the decomposed time series can be written as yt=^St+^At,where ^At=^Tt+^Rt is the seasonally adjusted component. Or, if a multiplicative decomposition has been used, we can writeyt=^St^At, where ^At=^Tt^Rt. •To forecast a decomposed time series, we forecast the seasonal component, S^t, and the seasonally adjusted component A^t, separately. •It is usually assumed that the seasonal component is unchanging, or changing extremely slowly, so it is forecasted by simply taking the last year of the estimated component. •In other words, a seasonal naïve method is used for the seasonal component.
Lung Cap Dataset - Simple linear regression
attach(LungCapData)names(LungCapData)class(LungCap)class(Age)x = LungCapDataplot(Age, LungCap, main = "Scatterplot")cor(Age, LungCap)help(lm)mod <- lm(LungCap ~ Age)summary(mod)coef(mod)plot(Age, LungCap, main = "Scatterplot")abline(mod, col = "blue", lwd = 3)
Antidiabetic drug sales plot
autoplot(a10) + ggtitle("Antidiabetic drug sales") + ylab("$ million") + xlab("Year")
demand and temperature plots in Victoria, Australia.
autoplot(elecdemand[,c("Demand","Temperature")], facets=TRUE) + xlab("Year: 2014") + ylab("") + ggtitle("Half-hourly electricity demand: Victoria, Australia")
Lets apply the 3 methods to a series of 200 days of the Google daily closing stock price.
autoplot(goog200) + autolayer(meanf(goog200, h=40), series="Mean", PI=FALSE) + autolayer(rwf(goog200, h=40), series="Naïve", PI=FALSE) + autolayer(rwf(goog200, drift=TRUE, h=40), series="Drift", PI=FALSE) + ggtitle("Google stock (daily ending 6 Dec 2013)") + xlab("Day") + ylab("Closing Price (US$)") + guides(colour=guide_legend(title="Forecast"))
Time plot for weekly economy passenger load on Ansett Airlines
autoplot(melsyd[,"Economy.Class"]) + ggtitle("Economy class passengers: Melbourne-Sydney") + xlab("Year") + ylab("Thousands") The time plot immediately reveals some interesting features. • There was a period in 1989 when no passengers were carried — this was due to an industrial dispute. • There was a period of reduced load in 1992. This was due to a trial in which some economy class seats were replaced by business class seats. • A large increase in passenger load occurred in the second half of 1991. • There are some large dips in load around the start of each year. These are due to holiday effects. • There is a long-term fluctuation in the level of the series which increases during 1987, decreases in 1989, and increases again through 1990 and 1991. • There are some periods of missing observations.
Lagged Scatter plots
beer2 <- window(ausbeer, start=1992)gglagplot(beer2) •The relationship is strongly positive at lags 4 and 8, reflecting the strong seasonality in the data. •The negative relationship is observed for lags 2 and 6. •The window() function is used to extract a portion from the time series.
•Most quantitative prediction problems use either ___________ or ____________
time series data (collected at regular intervals over time) or cross-sectional data (collected at a single point in time).
An alternative to using a multiplicative decomposition is...
to first transform the data until the variation in the series appears to be stable over time, then use an additive decomposition. •When a log transformation has been used, this is equivalent to using a multiplicative decomposition because: yt=St×Tt×Rt is equivalent to logyt=logSt+logTt+logRt.
scatterplot matrix of five variables.
uschange %>% as.data.frame() %>% GGally::ggpairs() • The scatterplots show positive relationships with income and industrial production, and negative relationships with savings and unemployment. • The strength of these relationships are shown by the correlation coefficients across the first row.• The remaining scatterplots and correlation coefficients show the relationships between the predictors.