How To Lie With Performance Data: Part 1 - How To Lie With A Small Number of Data Points
Tags: performance, datascience, tutorial
Published: 2021-11-07 21:54:53

## Introduction

As a Performance Engineer, I have observed multiple cases where my intuition has failed me while trying to make inferences about data. Since it is imperative to get good at making decisions with data, emboldening your "BS" detection skillset is of paramount importance for any engineer. 

This blog post is the first of 3 that goes over some ways you or others can lie with data from performance analysis such as Benchmarks or Regression detection based tooling.

## How To Lie With Small Number of Data Points

A data set with a small number of data points isn't sufficient enough to represent a true distribution especially if the data is littered with anomalous values. 

### Visual Perspective: Histogram

Consider the two data points both generated from a [Standard Normal Distribution](https://www.scribbr.com/statistics/standard-normal-distribution/) (As an aside, I have never observed any real performance data that follows a normal distribution but for the sake of exposition, I'll stick with this example):

___For a sample size of n = 10___ 

![Low # of Samples](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v4si7zrmf717fjnrs72r.png)

Visually, the histogram has no semblance of the standard normal distribution or even a normal distribution.

___For a sample size of n = 10,000___ 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/afjy6hv21vh7ojx1n7zs.png)

This distribution is more like the standard normal distribution, the real population from which we sample from indicating that the more the samples, the better we are off in terms of making decisions.

The code that generated these is the following:

{% gist https://gist.github.com/MokoSan/1f4ffb93c1fced56f1e3457195395b16 %}

### Statistical Perspective: Standard Error, Margin of Error and Confidence Intervals

#### Standard Error

The __Standard Error__ gives us a measure of __accuracy__ of how close the sample is to the true mean. The higher the standard error the less accurate we are in terms of guessing the true mean of a population.

The formula for standard error is:

{% katex %} se = \frac{s}{\sqrt{n}} {% endkatex %}

| Variable | Description |
| ----------- | ----------- |
| se | Standard Error |
| s | Standard Deviation of the Sample |
| n | Number of Samples |

From the formula, we notice that a lower 'n' under the condition of a lower number of samples, we are less accurate in guessing the true statistic such as the mean of a population as the Standard Error is higher.

#### Margin of Error

The Margin of Error is the Standard Error multiplied by a critical value: {% katex %} t^{*} {% endkatex %}, a magic constant whose value is derived from a table based on the the number of samples and a confidence %. This table can be found [here](https://www.coconino.edu/resources/files/pdfs/academics/sabbatical-reports/kate-kozak/appendix_table.pdf) on page 3. 

Formulaically, the margin of error is given by:

{% katex %} t^{*} \times \frac{s}{\sqrt{n}} {% endkatex %}

#### Confidence Intervals

Confidence Intervals are ranges between which the population statistic can be in with the margin of error as the "radius" or allowable leverage of error. For example, a confidence interval of 99% indicates that 99% of all confidence intervals with confidence level = 99% include the true population statistic.

For example, for the mean of a population based on a sample is given by:

{% katex %} [ \bar{x} - t^{*} \times \frac{s}{\sqrt{n}}, \bar{x} + t^{*} \times \frac{s}{\sqrt{n}} ] {% endkatex %}

Since the confidence interval does inherently rely on the number of samples, the conjecture that the "higher number of samples will give us a higher level of confidence about the said population statistic" is valid.

## Conclusion

Here are the lessons I have learnt over the years regarding the number of samples:

- Be sure to ask the number of data points the descriptive statistics were based off of. If the number of samples are low, inaccurate inferences from the data are possible.
- Make sure that even with seemingly high number of samples, the data is littered with anomalies; find out how to decrease these.
- Sometimes it's infeasible to get more samples - for these cases, make sure your anomalous values are as low as possible.
- Most importantly: always question the data.