BSTS and CausalImpact: Analysing Dell XPS Laptop Popularity by Web Page Views
By: Michael Grogan
Tags: Bayesian Statistics, Data Science, Hardware, Probability, Machine Learning

BSTS and CausalImpact: Analysing Dell XPS Laptop Popularity by Web Page Views

Disclaimer: This article is written on an “as is” basis and without warranty. It was written with the intention of providing an overview of data science concepts, and should not be interpreted as professional advice. The findings and interpretations in this article are solely those of the author and are not endorsed by or affiliated with any third-party mentioned in this article. This article is not intended to promote any particular company or product.

Background

In February of 2020, Forrester predicted that as a result of COVID-19, demand for hardware including computer and communications equipment will be quite weak due to the fact that consumers tend to delay capital investment in hardware during periods of weak economic activity, while software and cloud services will continue to thrive.

One reason for this is that hardware can often require greater upfront investment than software and cloud services. As such, periods of weak economic activity can entice consumers and businesses to delay hardware purchases until such time that economic conditions pick up once more.

One way of determining consumer interest in a particular product range is through analysing web page views, e.g. how many page views is a particular piece of hardware or software offering receiving over a defined period?

Business Scenario

Dell XPS is a high-quality laptop brand aimed at the premium end of the market. The laptops are also highly popular among data scientists (I use one myself).

Now, let’s consider this scenario. Suppose that Dell wishes to determine whether consumer interest in XPS laptops has been dampened as a result of the economic impact of the pandemic.

How can we gauge consumer interest in this case? Apart from looking at sales figures, one possibility would be to look at web page views for the search term “Dell XPS”.

Indeed, this might even be preferable as one should consider the possibility that consumers are deferring spending but still considering an eventual purchase of this brand of laptop — which would be reflected in page view levels remaining at similar levels as previously.

While it would be easy to simply look at the change in web page views pre and post March 2020, this doesn’t necessarily tell the full story.

For instance, one has no way of knowing for sure what page views would have looked like had the pandemic not occurred.

In this regard, the below analysis will make use of the following methodologies:

Use of BSTS (the Bayesian Structural Time Series Modelling) package from R to sample from the posterior distribution Use of CausalImpact to attempt to calculate what web page view levels would have been like had COVID-19 not occurred

The web page view data is sourced from pageviews.toolforge.org, which allows for analysis of page views for particular search terms across the Wikimedia Foundation.

Specifically, page views for the search term “Dell XPS” are examined from July 2015 — March 2021. When modelling with the CausalImpact package, page views for the search term “VMware Workstation” are also analysed across the same time period and used as a control series — VMware Workstation being a hypervisor that allows for setting up of multiple operating systems on a single Windows or Linux PC.

Given the hypothesis that software offerings were supposedly less affected by the economic fallout from the pandemic — comparison of consumer interest for both Dell XPS and VMware Workstation can potentially give a better overview of consumer interest levels for Dell XPS offerings had economic factors not significantly changed.

BSTS

Here is a graphical illustration of page views for “Dell XPS” over the specified period:

Source: RStudio Output

We can see that after day 1700 — which is roughly when the COVID-19 pandemic started to take hold in March 2020 — we can see a downward trend in page views. However, it is unclear as to whether this is directly as a result of recent events, or due to random fluctuations.

The purpose of using BSTS is to quantify a range of potential page view levels based on MCMC (Markov Chain Monte Carlo) sampling from the posterior distribution. Instead of making a point blank prediction as to where page view levels could go next — what are the potential ranges that we could observe based on the posterior distribution?

The page view data is loaded into R in CSV format. In order to allow BSTS to interpret the data properly, the data frame is then converted into xts format:

mydata<-read.csv("dellxps.csv") library("xts")

mydata$my_dates <- as.Date(mydata$Date)

mydata <- xts(mydata$Dell.XPS, mydata$my_dates)

Now, the BSTS model is specified. In this case, given the inherent volatility of web page view data, only the LocalLinearTrend will be modelled in this case.

1,000 iterations are performed and the model components are plotted.

library(bsts)

ss <- AddLocalLinearTrend(list(), mydata) model <- bsts(mydata, state.specification = ss, niter = 1000) plot(model)

plot(model, "components")

Here is the trend and generated distribution, with the latter showing the range of potential outcomes that could have been observed at a particular point in time:

Trend

Source: RStudio Output

Distribution

Source: RStudio Output

Now, let’s generate some predictions. Forecasts are made for the next 15 time periods, and the purpose of this is to generate a range of potential page view levels that could be observed over this time period.

pred <- predict(model, horizon = 15, burn = 100)

pred

plot(pred)

Source: RStudio Output

From the above, it is evident that BSTS is forecasting a range of outcomes for web page views over the selected period. The mean, median and interval forecasts are provided. At the most extreme end of the ranges, the BSTS model is forecasting that page views could be as low as 144 or as high as 690.

> pred $mean

[1] 418.5689 420.4969 419.4255 418.6695 415.5628

[6] 413.9601 413.5601 414.8989 415.8069 416.0139

[11] 415.7935 413.9589 408.6109 410.5100 411.8946 $median

[1] 417.8570 417.9747 419.1763 418.3281 417.6503

[6] 414.5861 418.8882 415.3306 417.3510 413.3739

[11] 417.3411 407.7334 411.0777 411.6520 411.1981 $interval

[,1] [,2] [,3] [,4] [,5]

2.5% 288.8354 285.9850 275.0117 254.0120 248.9270

97.5% 542.8098 565.5993 567.6804 591.9176 580.5002

[,6] [,7] [,8] [,9] [,10]

2.5% 221.8867 208.5441 210.8201 198.3210 195.1280

97.5% 596.5839 608.9127 613.7725 615.1689 640.2005

[,11] [,12] [,13] [,14] [,15]

2.5% 182.5640 174.2203 141.7563 143.3177 144.2848

97.5% 648.4422 650.0539 642.7709 694.1793 690.8501

With an overall mean of 471 page views per day observed across the time series, the forecasted mean is significantly below the average. However, the mean value is being significantly skewed by the presence of large “spikes” in page views. In the absence of these outliers, the mean level likely lies closer to that calculated by BSTS.

CausalImpact

As previously mentioned, one shortcoming of time series analysis is that it is not possible to analyse the movements of a time series in the absence of an intervention.

In other words, assuming the hypothesis that the economic fallout from COVID-19 has caused an increase in the replacement cycle for hardware — it is not possible to see what consumer interest for the Dell XPS range would have been had COVID-19 not occurred.

The closest we can get to doing so is through analysing the time series in conjunction with a control series that has not been affected by the intervention. Again, assuming the hypothesis that the replacement cycle for software will not have been affected by recent events, web page views for VMware Workstation is used as a control series.

In order to smooth out anomalies, both series are expressed in logarithmic format.

CausalImpact is used to analyse the pre and post-period as follows:

pre.period <- c(1, 1705)

post.period <- c(1706, 2101) impact <- CausalImpact(data, pre.period, post.period)

plot(impact) summary(impact)

summary(impact, "report") impact$summary

Here are the posterior inference results:

> summary(impact)

Posterior inference {CausalImpact} Average

Actual 6.3

Prediction (s.d.) 6.1 (0.45)

95% CI [5.2, 6.9]



Absolute effect (s.d.) 0.19 (0.45)

95% CI [-0.63, 1.1]



Relative effect (s.d.) 3.1% (7.4%)

95% CI [-10%, 17%]

Cumulative

Actual 2495.5

Prediction (s.d.) 2421.4 (178.46)

95% CI [2078.2, 2745.2]



Absolute effect (s.d.) 74.13 (178.46)

95% CI [-249.67, 417.3]



Relative effect (s.d.) 3.1% (7.4%)

95% CI [-10%, 17%] Posterior tail-area probability p: 0.34393

Posterior prob. of a causal effect: 66% For more details, type: summary(impact, "report")

In this case, the actual number of web page views for Dell XPS actually came in higher than expected at 6.3 compared to a prediction of 6.1 (both expressed in logarithmic format). The posterior probability of a causal effect comes in at 66%.

Let’s read the expanded summary generated by CausalImpact.

> summary(impact, "report")

Analysis report {CausalImpact} During the post-intervention period, the response variable had an average value of approx. 6.30. In the absence of an intervention, we would have expected an average response of 6.11. The 95% interval of this counterfactual prediction is [5.25, 6.93]. Subtracting this prediction from the observed response yields an estimate of the causal effect the intervention had on the response variable. This effect is 0.19 with a 95% interval of [-0.63, 1.05]. For a discussion of the significance of this effect, see below. Summing up the individual data points during the post-intervention period (which can only sometimes be meaningfully interpreted), the response variable had an overall value of 2.50K. Had the intervention not taken place, we would have expected a sum of 2.42K. The 95% interval of this prediction is [2.08K, 2.75K]. The above results are given in terms of absolute numbers. In relative terms, the response variable showed an increase of +3%. The 95% interval of this percentage is [-10%, +17%]. This means that, although the intervention appears to have caused a positive effect, this effect is not statistically significant when considering the entire post-intervention period as a whole. Individual days or shorter stretches within the intervention period may of course still have had a significant effect, as indicated whenever the lower limit of the impact time series (lower plot) was above zero. The apparent effect could be the result of random fluctuations that are unrelated to the intervention. This is often the case when the intervention period is very long and includes much of the time when the effect has already worn off. It can also be the case when the intervention period is too short to distinguish the signal from the noise. Finally, failing to find a significant effect can happen when there are not enough control variables or when these variables do not correlate well with the response variable during the learning period. The probability of obtaining this effect by chance is p = 0.344. This means the effect may be spurious and would generally not be considered statistically significant.

Ultimately, the analysis generated a higher average value than predicted, but there is not deemed to be statistically significant, i.e. it could have been obtained by chance.

This could also mean that the intervention period was shorter than expected — i.e. any possible economic impact of COVID-19 on the hardware market was short-lived.

Ultimately, the analysis by BSTS and CausalImpact has failed to establish any evidence that interest in Dell XPS has been negatively affected in the past year.

Limitations

Of course, the above analysis comes with limitations. For one, it is only considering one out of a myriad of products in the hardware market. It is possible that other hardware offerings saw a relatively higher drop-off in interest, but that of Dell XPS remained robust.

Moreover, one cannot be sure that consumer interest for one particular software offering (in this case, VMware Workstation) is representative of the software market as a whole. Had CausalImpact been used to compare Dell XPS to page views for another software product, then the results may be different.

Additionally, only one intervention point has been considered. March 2020 — when COVID-19 was declared a global pandemic. There could be other significant intervention points that have not been considered but may still be significant, e.g. those coinciding with the launch of a new product, new entrants to the market, etc.

Finally, web page views from just one source has been used as the benchmark. There are numerous ways of gauging potential consumer interest in a product that have not been discussed here.

Conclusion

This is one example of how Bayesian methods can be used to analyse interventions in a time series. Specifically, you saw how BSTS and CausalImpact can be used to:

Analyse web page views

Sample from posterior distributions

Generate posterior predictions

Forecast a time series using intervention analysis

In conducting the analysis, we also saw some limitations associated with Bayesian time series modelling and how results should be interpreted with caution.

Many thanks for your time, and any questions or feedback are greatly appreciated. You can also find more of my data science content at michael-grogan.com.

References