Multivariate data analysis (STAT-H400)

1. Data collection and descriptive statistics

Adrien Foucart

Introduction

What is this module about?

  1. Examples of the role of statistics and data analysis.
  2. A look at the data analysis pipeline.
  3. Some important and/or useful definitions.
  4. Understanding how studies are designed (and what can go wrong).
  5. Summarizing and visualizing univariate data.

Statistics and data analysis in the world

Political polling

In a population of voters…

Political polling

…\(n\) people respond to the poll. Can we say they are sampled from the population?

Political polling

Rather: they are sampled from people who respond to pollsters.

Also, depending on the method used by the pollster, this population could further be reduced to:

Political polling

The HCQ study

Let’s take a look at the methodology of the study and see if we spot anything problematic…

The HCQ study

Diagram based on Gautret et al., 2020 https://www.ncbi.nlm.nih.gov/pmc/articles/PMC7102549/.

This diagram is made based on the text in the study. Relevant excerpts:

2.4 Procedure (…) All patients in the Marseille center were proposed oral hydroxychloroquine sulfate 200 mg, three times per day for ten days (in this preliminary phase, we did not enroll children in the treatment group based on data indicating that children develop mild symptoms of COVID-19 [4]). Patients who refused the treatment or had an exclusion criteria, served as controls in the Marseille centre. Patients in other centers did not receive hydroxychloroquine and served as controls.

3.1 Demographics and clinical presentation. We enrolled 36 out of 42 patients meeting the inclusion criteria in this study that had at least six days of follow-up at the time of the present analysis. A total of 26 patients received hydroxychloroquine and 16 were control patients. Six hydroxychloroquine-treated patients were lost during the follow-up of the survey because of early cessation of treatment. Reasons are as follows: three patients were transferred to intensive care unit, including one transferred on day2 post-inclusion who was PCR-positive on day1, one transferred on day3 post-inclusion who was PCR-positive on days1-2 and one transferred on day4 post-inclusion who was PCR-positive on day1 and day3; one patient died on day3 post inclusion and was PCR-negative on day2; one patient decided to leave the hospital on day3 post-inclusion and was PCR-negative on days1-2; finally, one patient stopped the treatment on day3 post-inclusion because of nausea and was PCR-positive on days1-2-3.

The HCQ study

The HCQ study

This is of course particularly true in politically charged topics, or when big financial interests are at stake. In those cases, even when the research is done properly and honestly, there may still be a “selection bias”: studies that go against what the company wants may not be published.

The same kind of bias exists simply in favour of studies that show “positive results”: demonstrating that a method “doesn’t work” is often harder to publish in a good journal than demonstrating that it works, which can create the illusion of a consensus even though the data doesn’t actually support it.

EEG spike detection

How much data analysis is there in a biomedical study? A quick look at a 2012 ULB paper by A. Nonclercq.

https://doi.org/10.1016/j.jneumeth.2012.07.015

EEG spike detection

In biomedical studies, it is quite common to have these very low sample sizes. Recruiting patients for a study is complicated, with ethical issues and cost issues to large-scale studies.

EEG spike detection

EEG spike detection

It is always important when looking at a medical study to assess how the “ground truth” was achieved. If a single expert annotated the data, it is likely to introduce a potential bias in the results.

But having multiple experts is expensive, and annotating datasets is a time-consuming job to ask of doctors, so it is often the reality that we have to deal with when analyzing the data afterwards.

The data analysis pipeline

The data analysis pipeline

Data collection \(\rightarrow\) Exploratory statistics \(\rightarrow\) Modelisation \(\rightarrow\) Evaluation

Different phases in most data analysis pipelines, from the acquisition of a dataset (with desirable characteristics) to a model that can be used to make predictions about new data.

The data analysis pipeline

Data collection \(\rightarrow\) Exploratory statistics \(\rightarrow\) Modelisation \(\rightarrow\) Evaluation

Data collection

The data analysis pipeline

Data collection \(\rightarrow\) Exploratory statistics \(\rightarrow\) Modelisation \(\rightarrow\) Evaluation

Exploratory statistics

The data analysis pipeline

Data collection \(\rightarrow\) Exploratory statistics \(\rightarrow\) Modelisation \(\rightarrow\) Evaluation

Modelisation

The data analysis pipeline

Data collection \(\rightarrow\) Exploratory statistics \(\rightarrow\) Modelisation \(\rightarrow\) Evaluation

Evaluation

Exploratory statistics

GlowstoneUnknown for Wikimedia

The choice of visualization has an impact on the “story” that you tell with the data. Here we can see essentially the same data in two different ways. On the left, the bar chart highlights the difference between two points in time. On the right, we have something that is richer with information about the trend over time and more data points to show the “variability” of the polling… but it is much harder to read.

Exploratory statistics

From Bulten et al., 2022 (doi:10.1038/s41591-021-01620-2)

Properly showing how values are distributed can be really difficult, and we have here a good example by Bulten et al. on how to show complex data in a reasonably readable way. We have both the “simplified” statistics of the mean and 95% confidence interval, and the richer information of all the individual points, all shown on the same graph.

We can quickly see here, for instance, the the algorithms (in blue) tend to have results that are much more concentrated, whereas the pathologisits (in blue) have a much wider range of opinions

Exploratory statistics

Modelisation

Data collection \(\rightarrow\) Exploratory statistics \(\rightarrow\) Modelisation \(\rightarrow\) Evaluation

Unsupervised methods

Unsupervised methods

Example from Foucart et al., 2021 (doi:10.1117/12.2604307, or https://research.adfoucart.be/pub-html/FOUCART21-SIPAIM.html)

Each point represents high-dimensional information (the grade given by a pathologist to a large number of images in a dataset).

We summarize the information based on a distance measure between the pathologists.

We reduce the dimensionality and project the information on a 2D space to give a visual representation of the clusters of experts.

The circles here are used to show the potential error made on by the projection method. A (somewhat imperfect) interpretation of the circle here is that, if the circle is larger than the distance between points, then the clustering is unlikely to be meaningful.

Modelisation

Data collection \(\rightarrow\) Exploratory statistics \(\rightarrow\) Modelisation \(\rightarrow\) Evaluation

Supervised methods

\(Y\) here may be a vector of variables as well, if we are trying to predict multiple values from the input.

Supervised methods

From Xu et al., 2014, doi:10.1016/j.jbiomech.2014.01.043.

Evaluation

Data collection \(\rightarrow\) Exploratory statistics \(\rightarrow\) Modelisation \(\rightarrow\) Evaluation

Evaluation of supervised methods: comparison with a reference “ground truth”.

From Bulten et al., 2022

Evaluations are often reduced to a single metric (such as accuracy), but we can often gather much richer information if we look beyond the metric. Here is another example from Bulten et al., where the colors show the categories (grades of cancer). The top row is the “ground truth” (from a consensus of experts), then we have the results by top algorithms, then the results by individual pathologists.

We can quickly see from this visualization that:

  1. some images in the benign and grade 5 class are easy to categorize (everyone agrees).
  2. images in the grandes 1-2-3-4 are much harder to categorize.
  3. top algorithms tend to agree with each other more than pathologists (for this particular task and dataset).

These insights can help understand the results better than just looking at numerical metrics.

Quick Quizz

We have a set of images \(S = \{I_i\}\), which are CT scans of the lungs. We make the hypothesis that image containing lung cancer will be “more different” compared to the “typical image” than non-cancer images. To test that hypothesis, we look at a measure of distance between images and try to detect outliers. What we are doing is…

  1. Supervised learning
  2. Descriptive analysis
  3. Unsupervised learning
  4. Data collection

Outlier detection does not require the labels, as we are just looking at distances between the “input” vectors, so it is not supervised learning.

We are however trying to make predictions about new data, so it is not just descriptive analysis or data collection.

This is an example of unsupervised learning: trying to find the “natural” structure of the data and see if we can use that structure to make predictions about new data.

Definitions

Definitions

Statistics

Statistics is the science of collecting and analyzing data for the purpose of drawing conclusions and making decisions.
– Tahmane and Dunlop, Statistics and Data Analysis, Prentice-Hall, 2000

Population

all the items of interest (may be people, things, events…).

Sample

subset of the population that is actually observed for the study.

Definitions

Variables

the things that we measure about the items in the sample. The value of the variables for a particular item is therefore used as a proxy for the item itself within the study.

Distribution

a mathematical function that describe the probability that a variable has a certain value. The term can also be applied to the observed frequency of occurence of the values for a variable.

Just like a sample gives a truncated view of the population, the variables give a truncated view of the studied items.

This is always a potential limitation to be aware of when analyzing data. We can only find relationships between variables that we measure. There may be other things that influence the data that we cannot measure. This is (part of) the reason why we typically cannot infer causality just from the data, as it’s often not possible to make the distinction between \(A \rightarrow B\), \(B \rightarrow A\) and \(C \rightarrow A, B\) where we may not be measuring \(C\) at all.

Definitions

Statistic

Examples:

Note the difference between statistics (the field of study) and a statistic (the thing that we are typically studying).

Quick Quizz

From Nonclercq et al., 2012

The variables are the column: Age, Sex, SWI (expert), SWI (algorithm), Absolute difference between expert and algorithm.

The statistics are the “mean expert SWI”, the “mean algorithm SWI” and the “mean absolute difference” (computed on the expert SWI, algorithm SWI, and absolute difference, respectively).

Summary of key points

Reading

Sampling a population

Some formalism

Let \(\mathcal{P}\) be the target population of a study, and \(X\) be a random variable of interest (e.g. the size of a subject, the political party of choice of a voter, the range of rotation of the shoulder of a patient…)

A random sample of size \(n\) is obtained by observing/measuring \(X\) \(n\) times, independently and under identical conditions. \(X_i\) is a random variable which represents the \(i^{th}\) observation of the variable \(X\). Its value varies from one sample to another, and the probability distribution of \(X_i\) is equal to that of \(X\).

Some formalism

The observed values for a given sample are noted: \(x_1, x_2, ..., x_n\).

A statistic is a function that characterizes the observed values in the sample.

A parameter is a function that characterizes the population.

The values of the parameters are generally unknown, and are estimated by the statistics.

Why \(n-1\) in \(s^2\) ?

See e.g. this answer on StackExchange

Short answer: because we want the sample variance to be a good estimator of the population variance, and using \(\frac{1}{n}\) would lead to a biased estimation:

Let \(s_t^2 = \frac{1}{n}\sum_{i=1}^n(X_i-\bar{X})^2\) be the variance of the sample \(t\).

To estimate the variance of the population, however, we have to add the variance of the sample mean: \(Var(\bar{X}) = \frac{\sigma^2}{n}\).

So we get: \(\sigma^2 = s_t^2 + \frac{\sigma^2}{n}\)

\(\Rightarrow (1-\frac{1}{n})\sigma^2 = s_t^2\)
\(\Rightarrow \sigma^2 = s_t^2 \times \frac{n}{n-1} = \frac{1}{n-1}\sum_{i=1}^n(X_i-\bar{X})^2\)

Experiment

distribution = stats.norm(loc=63, scale=7)
x = np.linspace(distribution.ppf(0.01), 
                distribution.ppf(0.99), 100)    
pdf = distribution.pdf(x)

r = distribution.rvs(size=20)
fig, ax = plt.subplots()
ax.plot(x, pdf, 'r-')
ax.hist(r, density=True, bins='auto', alpha=0.2)
ax.set_xlim([x[0], x[-1]])
ax.set_ylim([0, 0.1])

\(N(63, 7^2)\) with histogram of a sample of 20 randomly drawn items.

If we take a sample of size \(n\) from a distribution, and \(n\) is relatively low, we will probably have a shape that is significantly different from the original probability density function (pdf), with a sample mean and variance that are not great estimators.

Experiment

\(N(63, 7^2)\) with histogram of a sample of 20 randomly drawn items.

\(N(63, 7^2)\) with histogram of a sample of 2000 randomly drawn items.

The mean of the distribution is 63… but what is the mean of the sample?

As we increase the sample size, we can expect to get something that matches the theoretical distribution a lot more. As \(n\) grows to infinity, we will approximate the pdf.

Experiment

distribution = stats.norm(loc=63, scale=7)
x = np.linspace(distribution.ppf(0.01), 
                distribution.ppf(0.99), 100)
pdf = distribution.pdf(x)

n_repeat = 10_000

sample_size = 20
means = []
for _ in range(n_repeat):
    means.append(np.mean(
    distrib.rvs(size=sample_size)
    ))
fig, ax = plt.subplots()
ax.plot(x, pdf, 'r-')
ax.hist(means, density=True, bins='auto', alpha=0.2)
ax.set_xlim([x[0], x[-1]])
ax.set_ylim([0, 0.5])

\(N(63, 7^2)\) with histogram of means of 10.000 samples of 20 randomly drawn items.

If we look at the random variable \(\bar{X}\), the sample mean, over repeated samples, we can see that it has its own distribution, centered around \(\mu\), and much narrower than the distribution of \(X\).

Experiment

\(N(63, 7^2)\) with histogram of means of 10.000 samples of 20 randomly drawn items.

If I take 10.000 samples of 2000 randomly drawn items, the distribution will be…?

  1. Narrower
  2. Wider
  3. The same

Experiment

\(N(63, 7^2)\) with histogram of means of 10.000 samples of 20 randomly drawn items.

\(N(63, 7^2)\) with histogram of means of 10.000 samples of 2000 randomly drawn items.

As \(n\) grows, it is less likely that \(\bar{x}\) deviates from \(\mu\), so the distribution of \(\bar{X}\) will be a lot narrower.

Experiment

Types of studies

Comparative vs noncomparative

Observational vs experimental

Experimental studies are generally considered to be “stronger” and more apt at establishing causality. In observational studies, confounding variables may be difficult to detect and measure.

This is not to say that there can’t be confounding variables in experimental studies, but we are more likely to be able to isolate the effects of a single variable.

(Non)Sampling errors

If \(\theta = f(\mathcal{P})\) is a parameter, function of a population, and \(t = f(x)\) is the corresponding statistic, function of a sample, what are the different ways that \(t \neq \theta\)?

To achieve a representative sample (such that \(f(x) \approx f(\mathcal{P}) \forall f\)), the sampling method must be adapted to the problem. Convenience sampling (colleagues, friends, people on the street…) is typically much weaker than random sampling.

Control group and baseline experiment

A comparative study often tries to evaluate the effect of a change from the normal, baseline conditions. To assess this effect, measures must be made on a control group (baseline conditions) alongside the “intervention” group.

This is true also when comparing image analysis algorithms or the quality of a medical instrument: a comparison to a known baseline is required to detect the potential effects of the novel approach.

Biases in studies

Accuracy and precision

From Zar, Biostatistical Analysis.

If \(\epsilon_i = x_i - x^\dagger\) where \(x_i\) is the \(i\)-th measured value, \(x^\dagger\) the “true” value:

\(\bar{\epsilon_i}\), the average error, gives us the accuracy (or bias) of the measure. If \(\bar{\epsilon_i} \approx 0\), the measure is accurate or unbiased.

\(Var[\epsilon_i]\), the variance of the error, gives us the precision of the measure. If \(Var[\epsilon_i] \approx 0\), the measure is precise or reliable.

Nonrepresentative sample

From Kinyanjui et al., 2020, doi:10.1007/978-3-030-59725-2_31

In benchmark datasets for skin disease classification algorithms, the population sample is biased towards lighter skin tones compared to the target population (all humans, or at least all humans with skin)

Biased measurements

Biased metrics

\[IoU(T, P) = \frac{|T \cap P|}{|T \cup P|}\]

Segmentation metric, with \(T\) the “ground truth” (i.e. real boundaries of the object, as annotated by an expert) and \(P\) the “prediction” of an algorithm.

The IoU (a.k.a. Jaccard Index) is a very common segmentation metric, but “very common” doesn’t mean that it should be accepted as a “true” measure of quality.

Every evaluation metric is flawed, because we are always trying to reduce a complex question (which method/algorithm/etc. is better) to a single number.

Biased metrics

\[IoU(T, P) = \frac{|T \cap P|}{|T \cup P|}\]

Let \(P_{over}\) be a prediction that overestimates the size of the object by \(n\) pixels (predicts \(n\) additional pixels inside of \(P\) which are outside of \(T\)), and \(P_{under}\) a prediction that underestimates the size of the object by \(n\) pixels (predicts \(n\) additional pixels as outside of \(P\) which are inside of \(T\)).

Biased metrics

Which of these statements is true?

  1. \(IoU(T, P_{over}) = IoU(T, P_{under})\)
  2. \(IoU(T, P_{over}) < IoU(T, P_{under})\)
  3. \(IoU(T, P_{over}) > IoU(T, P_{under})\)

Biased metrics

\(M^{+} = IoU(T, P_{over})\)
\(M^{+} = \frac{|T \cap P|}{|T \cup P|+n} = \frac{I}{U+n}\)

\(M^{-} = IoU(T, P_{under})\)
\(M^{-} = \frac{|T \cap P|-n}{|T \cup P|} = \frac{I-n}{U}\)

\(\Rightarrow I = M^{+}(U+n)\)
\(\Rightarrow M^{-} U + n = M^{+}(U+n)\)
\(\Rightarrow M^{-} = \frac{M^{+}(U+n)-n}{U}\)
\(\Rightarrow M^{-} = M^{+} + \frac{n(M^{+}-1)}{U}\)

The equations here are shown to be complete, but the point is: we can compute a general relationship between the “overestimated IoU” and the “underestimated IoU” that hold whatever the shape and size of the object.

Biased metric

\(\Rightarrow M^{-} = M^{+} + \frac{n(M^{+}-1)}{U}\)

As \(0 \leq M^{+} < 1\) and \(n > 0\) and \(U > 0\):

\(\frac{n(M^{+}-1)}{U} < 0\)

\(\Rightarrow M^{-} < M^{+}\)
\(\Rightarrow IoU(T, P_{under}) < IoU(T, P_{over})\)

The IoU has a bias in favour of algorithms that overestimate the size of the predicted region.

This bias may very well be desirable (in some applications, underestimating the size of an object may lead to more problems than overestimating it!), but it shouldn’t be ignored.

Every metrics will have different behaviours in different situations, and it’s important to be aware of the potential edge cases of a metric.

See e.g. Reinke et al., 2023 for all the ways we can make mistakes with image processing metrics: Common limiatations of Image Processing Metrics: A Picture Story, arXiv:2104.05642…

Or Chapter 4 of Foucart, A., 2022, Evaluation metrics and processes, in Impact of real-world annotations on the training and evaluation of deep learning algorithms in digital pathology, PhD Dissertation.

Systematic errors

A systematic error happens when there are differences between the experimental conditions between the groups.

From Catalá et al., 2021 (doi:10.1109/ACCESS.2021.3065456)

Systematic errors

Problem: patients with low-probability of having COVID are treated in a different service (and imaged with a different machine) from patients with a high-probability of having the disease.

Consequence: deep learning methods learn to recognize background patterns and still performs very well even if we remove the lung from the image !

This is a very common occurence with deep learning methods: they are extremely good optimizers, but what you are optimizing exactly is not necessarily easy to determine if you’re not careful about the experimental setup.

Quick Quizz

A study that tests one algorithm on its ability to detect COVID in X-Ray Images based on publicly available datasets is…

  1. Comparative and observational
  2. Comparative and experimental
  3. Noncomparative and observational
  4. Noncomparative and experimental

Single algorithm \(\rightarrow\) noncomparative study.

Public dataset \(\rightarrow\) we can’t be active anymore, so it’s observational.

Summary of key points

Reading

Univariate statistics

Types of variables

Types of variables

Summarizing categorical data

Sample ID Category
1 CAT
2 DOG
3 DOG
4 DOG
5 CAT
6 CAT
7 DOG
8 DOG
9 DOG
CAT DOG
Frequency 3 6
Relative frequency 33,3% 66,6%

Summarizing categorical data

CAT DOG
Frequency 3 6
Relative frequency 33,3% 66,6%
— — —
Mode DOG

Visualizing categorical data

Pie charts should not be used for ordinal data. Categories can be sorted by frequency for nominal data. For ordinal data, the natural order of the categories should be preserved.

There are probably use cases where those “rules” should be broken, but in general it leads to the most interpretable figures.

Visualizing categorical data

From Kinyanjui et al., 2020, doi:10.1007/978-3-030-59725-2_31

Question: is this an ordinal or nominal variable?

This is an ordinal variable, as it represents a scale from light to dark, with a natural order… except for the “undefined” value, so any analyses that relies on the order of the categories should probably first remove the undefined values!

Visualizing categorical data

From https://ecampusontario.pressbooks.pub/bio16610w18/chapter/how-graph-misrepresents-data/ : percentage of sold trucks still on the road, by manufacturer.

For ratio variables (where there is a meaningful 0), the 0 should appear on the graph. Otherwise, it misrepresents the data.

Visualizing categorical data

From https://ecampusontario.pressbooks.pub/bio16610w18/chapter/how-graph-misrepresents-data/ : evolution of ocean temperature.

For interval variables, conversely, adding an arbitrary 0 can hide significant variations.

Summarizing quantitative data

Let \(x_1, x_2, ..., x_n\) be a sample of size \(n\) of a random variable X which is quantitative. The most common measures of the central tendency are the mean and the median.

Mean: \(\bar{x} = \frac{\sum_{i=1}^{n} x_i}{n}\)

Median: middle value in the ordered sample. If n is odd, then there is a unique middle value. If n is even, there are two middle values, and the median is generally computed as the average of those two values.

Summarizing quantitative data

Mean: best when the data follows a symmetric distribution with few values away from the center.

Median: best when the data follows an asymmetric distribution or when there are many values away from the center.

A data value that is far away from other values in the sample is called an outlier, which often (but not always) correspond to observation errors.

Summarizing quantitative data

Some common measures of the variability are the standard deviation, the variance, the interquartile range and the spread.

Variance: \(s^2 = \frac{1}{n-1} \sum_{i=1}^{n}(x_i - \bar{x})^2\)
Standard deviation: \(s = \sqrt{s^2}\)

Percentile \(p\): in the ordered sample, the value which divides the sample such that \(p\)% of the values are less than or equal to it.
IQ range: in the ordered sample, let \(Q_1\) be the percentile 25 and \(Q_2\) be the percentile 50 (= median), \(Q_3\) the percentile 75. The IQ range is defined as \(IQR = Q_3 - Q_1\)
Spread: \(max({x_1, x_2, ..., x_n}) - min({x_1, x_2, ..., x_n})\)

Summarizing quantitative data

Note the difference between the statistics of the sample and the parameters of the population:

Statistic Sample Population
Mean \(\bar{x} = \frac{1}{n} \sum_{i=1}^{n} x_i\) \(\mu = E[X] = \int{xf(x)dx}\)
Variance \(s^2 = \frac{1}{n-1} \sum_{i=1}^{n}(x_i - \bar{x})^2\) \(\sigma^2 = Var[X] = E[X - \mu]^2 = E[X^2]-\mu^2\)

Visualizing quantitative data

How many bins? The rule of thumb is \(\sqrt{n}\) where \(n\) is the sample size, but there is no single answer…

From Elliott, 2008, doi:10.1111/j.1365-2427.2008.01978.x.

Visualizing quantitative data

When comparing different samples, a very common choice of visualization is the boxplot or box-and-whiskers plot.
It uses five values to summarize the distribution of the observed sample: the median (marked with a line), the first and third quartiles (marked with the boundaries of the box) and the fences, defined as \(F_{low} = Q_1 - 1.5 \times IQR\) and \(F_{high} = Q_3 + 1.5 \times IQR\) with \(IQR = Q_3 - Q_1\). Points outside the fence are shown as outliers.

All individual points may be shown if readability is not impaired.

From Maier-Hein et al., 2018. (doi:10.1038/s41467-018-07619-7)

Experiment

Diabetes dataset (from https://www4.stat.ncsu.edu/~boos/var.select/diabetes.html)

Does the target measure depend on the sex of the patient?

Experiment

Sex (n) Mean (std)
1 (235) 149.02 (75.7)
2 (207) 155.67 (78.26)

Are those distributions different?

The boxplot hides the shape of the distribution, which may make different distributions look more similar… but on the other hand, the histogram is impacted by the choice of bins, which sometimes may introduce visible differences which are mostly artifacts of the binning.

We also tend to focus on small differences in the histogram which may make distributions look more different than they really are…

Experiment

Violin plots combine a smoothed histogram with the information in the boxplot, which tend to provide a more “balanced” estimation… but it’s still dangerous to rely on your eyes only!

Experiment

Reading

For the different visualization proposed, determine the type of variables whose observed distribution is being shown. What are the qualitative assessments implied by those visualizations?

Summary of key points