Forecasting the number of visitors on your website using R. Part I

By Parth Vadera | 29.10.2013 | Blog Marketing

This blog post is the first in the series of three blogs. The current blog will introduce the reader to the importance of forecasting “views” of an e-Commerce website. The process of forecasting can be implemented using the time-series approach and decomposing the “views” signal into four components namely seasonal, trend, cyclic and irregularity. This decoupling can be achieved through exponential smoothing using the HoltWinters function of the forecast package of R.
Businesses around the globe have been forecasting their sales for a long time. The primary reason for it is planning, for instance, amount of inventory to store or when to allot the budget on marketing etc. Now a day every e-Commerce business, big or small, has their online presence. This gives them an opportunity to accumulate data about  their consumer’s behaviour, demographics, sources, no of new visits, etc, which can be indirectly used to predict sales. A precursor to sales can also be found by calculating some correlation between the number of visitors and sales. (If this is not the case then one should first rethink about the efficacy of the website in generating revenue) Since many consumers thoroughly research the products and services online before they buy, the web analytics forecasted no of visitors can quickly alert you on any new trend, than what the sales data can.
ABC of forecasting:                                                                     
Forecasting is the process of estimating a future event based on recent and past time series data. It may not reduce the uncertainty of future; however, it gives the decision makers an idea and a basic premise for planning. Short term forecast will always be more accurate than Long term forecast.

We will use a Time-Series Model for our forecasting purpose. People may visit a particular website for many different reasons which are next to impossible for us to fathom all the underlying factors. So,we presume to know nothing about the causality that affects the variable we are trying to forecast. Instead, we examine the past behaviour of a time series in order to infer something about its future behaviour. Time-series models are particularly useful when little is known about the underlying process one is trying to forecast.

A variety of factors influence the time series data. We shall use decomposition analysis to identify certain patterns that appear concurrently in the time series. There are four components in the decomposition analysis that we’ll methodically dissect namely Seasonality, Trend, Cycling and Irregularity.

For an arbitrary observed data running from 1955 to 1995, we’ll decompose it into the desired components mentioned above:

  • Seasonality: When a repetitive pattern is observed over a period of time, such series is known to have a seasonal component. Trend: It is growth or decay that is the tendencies for data to increase or decrease fairly steadily over time. A time series may be stationary or exhibit trend over time.

  • Irregularity: This component of the time series is unexplainable; therefore it is unpredictable.
  • Cyclic:  An upturn or downturn not tied to seasonal variation. Usually results from changes in economic conditions.
Inherent in the collection of data taken over time is some form of random variation. There exist methods for reducing of cancelling the effect due to random variation. A widely used technique is “smoothing“. This technique, when properly applied, reveals more clearly the underlying trend, seasonal and cyclic components.Smoothing techniques are used to reduce irregularities in time series data. Smoothing techniques, such as the Moving Average, Weighted Moving Average, and Exponential Smoothing, are well suited for one-period-ahead forecasting.


Exponential smoothing is a very popular scheme to produce a smoothed time series. It assigns exponentially decreasing weights as the observation gets older. In other words, recent observations are given relatively more weight in forecasting than the older observations.

I have implemented the exponential smoothing method for forecasting number of visitors to a website using Holt Winters model in the next blog.

Forecasting the number of visitors on your website using R. Part I by
The following two tabs change content below.

Parth Vadera

He is a Data Analyst at Tatvic. His interests lie in getting the maximum insights out of raw data using R and Python

Leave a Reply

Your email address will not be published. Required fields are marked *