Skip to content

Hypothesis Testing and Statistical Analysis

In this module, you will learn the statistics that an analysis of social media data needs: how to describe a set of numbers, how to test a claim about them, and how to measure whether two values change together.

Social media data is highly skewed. A few accounts have millions of followers, and most accounts have very few. The mean, a histogram with equal bins, and a test that assumes a normal distribution all give a wrong picture of such data. Each page shows what to use for skewed data.

Learning objectives

  • Describe a set of numbers with the mean and the median, and say which one fits skewed data
  • Plot a distribution with a histogram, a box plot, a violin plot, a CDF, and a CCDF
  • Use log bins and log axes for skewed data such as follower counts
  • State a null hypothesis and explain what a p-value means
  • Run a binomial test and a t-test with SciPy, and choose another test when the data is not normal
  • Report the p-value and the size of the difference, not only whether the result is significant
  • Plot the relationship between two variables and measure it with the Spearman or the Pearson coefficient
  • Explain why a correlation does not show a cause

Pages

Page What it covers
Descriptive statistics and distributions The mean and the median, and five plots of a distribution: histogram, box plot, violin plot, CDF, and CCDF; log bins and log axes for skewed data
Hypothesis testing What a p-value means; a test built by simulation with a coin; the binomial test and the t-test; how to choose another test; how to report a result; significance and effect size
Correlation Why a correlation does not show a cause; the scatter plot on log axes; the Spearman and the Pearson coefficient; the 2D histogram

Notebooks

Each notebook holds all the code of one page and runs in Colab without setup. Two of the notebooks download a small data file (154 KB) on first run.

Notebook Sections
Distributions Mean and median, Simulated heights, Box plot and violin plot, Load the Botwiki-2019 data, Histogram of follower counts, Mean and median of a skewed distribution, Box plot on a log axis, CDF and CCDF Open in Colab
Significance tests Toss a coin 100,000 times, One sample of 100 tosses, What a fair coin does, The p-value, A biased coin, The binomial test, Compare two groups with a t-test, Other tests, Significance and effect size Open in Colab
Correlation analysis Load the Botwiki-2019 data, Scatter plot, Log axes, Spearman and Pearson, 2D histogram, Log color scale Open in Colab

Tools

Tool What it is for
scipy.stats (Python) Statistical tests, correlation coefficients, and distributions
statsmodels (Python) Statistical models and more tests, such as the two-proportions z-test
matplotlib (Python) Histograms, box plots, CDFs, scatter plots, and 2D histograms
R A language made for statistics

Every plot and test in this module uses scipy.stats, statsmodels, and matplotlib.