\documentclass{beamer}
% \documentclass[handout]{beamer}

\usetheme{dcc}

\usepackage[utf8]{inputenc}
\usepackage[american]{babel}
\usepackage{url}
\usepackage[autolanguage]{numprint}

\newcommand{\ie}{i.\,e.}
\newcommand{\Ie}{I.\,e.}
\newcommand{\eg}{e.\,g.}
\newcommand{\Eg}{E.\,g.}

\newcommand{\pub}{\hskip2pt\raisebox{-3.5pt}{\pgfuseimage{beamericonarticle}}\hskip1pt}

\title{Mineração de Dados Aplicada}
\subtitle{From Correlation to Causation}

\author{Loïc Cerf}

\date{March, 24th 2025}

\institute
{
  \scriptsize
  DCC -- ICEx -- UFMG
  \bigskip\\
  \includegraphics[width=.334113288\linewidth]{images/dcc}\hfill\includegraphics[width=.5\linewidth]{images/ufmg}
}

\subject{From Correlation to Causation}

\keywords{correlation, causation, Simpson's paradox, scientific
  methods, p-value}

\hypersetup{pdfpagemode=FullScreen}

\AtBeginSection[]
{
  \begin{frame}<beamer>
    \frametitle{Outline}
    \tableofcontents[currentsection]
  \end{frame}
}

\begin{document}

\begin{frame}[plain]
  \titlepage
\end{frame}

\section*{Summary of the last session}

\begin{frame}
  \frametitle{Dependence between attributes}
  \begin{itemize}
  \item \emph{Conditional box plots} allow to visualize a dependence
    between two attributes of the nominal and interval types;
  \item \emph{Scatter plots} allow to visualize a dependence between
    two (or three) interval-scaled attributes and more
    (color/shape/size of the point);
  \item \emph{Regression} aims to explain an attribute of the interval
    type as a function of other attributes; it supports predictions;
  \item The \emph{coefficient of determination} (the
    \emph{correlation}, if there are two attributes) quantifies how
    much the regression function fits the data;
  \item Models with too few or too many parameters are bad; model
    selection techniques exist to learn the ``good amount''.
  \end{itemize}
\end{frame}

\begin{frame}
  \frametitle{Outline}
  \tableofcontents
\end{frame}

\section{Correlation and causation}

\begin{frame}
  \frametitle{Correlation}
  Correlations:
  \begin{itemize}[<+->]
  \item support predictions;
  \item allow to form hypotheses about cause-and-effect relationships;
  \item \emph{never} prove such hypotheses, unless the data were
    collected for that purpose, following a well-designed methodology.
  \end{itemize}

  \vfill
  \uncover<4>{
    \begin{center}
      \includegraphics[width=.67\linewidth]{img/correlation_does_not_imply_causation}
    \end{center}
  }

\end{frame}

\begin{frame}
  \frametitle{Correlation does not imply causation}
  A correlation indicates a dependence between two attributes but not
  necessarily a cause-and-effect relationship:
  \begin{itemize}[<+->]
  \item \alert<5>{A third attribute (not necessarily in the dataset)
      is \emph{confounding}, the cause for both variations.}
  \item Even if there is causation, the correlation, which is
    symmetric, does not allow to discern the cause from the
    consequence...
  \item ... and the causation may be bidirectional.
  \item It may be a mere coincidence.
  \end{itemize}

  \vfill

  \uncover<4->{See
    \url{http://www.tylervigen.com/spurious-correlations} for examples
    of spurious correlations found by data dredging.}
\end{frame}

\section{Simpson's paradox}

\begin{frame}
  \frametitle{Three questions}
  \begin{itemize}[<+->]
  \item Do people with larger brains have higher IQs?
    \uncover<4->{Yes.}
  \item Do men have larger brains than women?  \uncover<5->{Yes.}
  \item Do men have higher IQs than women?
    \uncover<6->{No.}
  \end{itemize}

  \footnotesize

  \uncover<4->{\pub Pietschnig et al.  Meta-Analysis of Associations
    between Human Brain Volume and Intelligence Differences: How
    Strong Are They and What Do They Mean?  \emph{Neuroscience \&
      Biobehavioral Reviews}, 57:411--432, 2015.}

  \vfill

  \uncover<5->{\pub Ruigrok et al.  A Meta-Analysis of Sex Differences
    in Human Brain Structure.  \emph{Neuroscience \& Biobehavioral
      Reviews}, 39:34--50, 2014.}

  \vfill

  \uncover<6->{\pub Reynolds et al.  The sexes do not differ in
    general intelligence, but they do in some specifics.
    \emph{Intelligence}, 92:101651, 2022.}

  \normalsize

  \vfill

  \uncover<7>{And, no, there is no contradiction.}
\end{frame}

\begin{frame}
  \frametitle{Simpson's paradox: illustration (1/2)}
  A drug and a surgery can cure a given cancer.  Taking the last 1000
  patients for each cure:

  \vfill

  \begin{center}
    \begin{tabular}{cccc}
      & recovers & dies & recovery rate\\
      \hline
      drug & 761 & 239 & \alert<2>{76\%}\\
      surgery & 658 & 342 & 66\%
    \end{tabular}
  \end{center}

  \vfill

  \uncover<2>{The patients taking the drug have a better recovery
    rate.}
\end{frame}

\begin{frame}
  \frametitle{Simpson's paradox: illustration (2/2)}
  Partitioning the \emph{same} numbers w.r.t. whether the tumor is
  big:

  \vfill

  \begin{description}
  \item[Big:] \begin{tabular}{cccc}
      & recovers & dies & recovery rate\\
      \hline
      drug & 90 & 92 & 49\%\\
      surgery & 564 & 331 & \alert<2>{63\%}
    \end{tabular}
  \item[Small:] \begin{tabular}{cccc}
      & recovers & dies & recovery rate\\
      \hline
      drug & 671 & 147 & 82\%\\
      surgery & 94 & 11 & \alert<2>{90\%}
    \end{tabular}
  \end{description}

  \vfill

  \uncover<2>{Big or small, the tumor is better cured by surgery.}
\end{frame}

\begin{frame}
  \frametitle{Simpson's paradox: explanation}
  The size of the tumor is a confounding attribute:
  \begin{itemize}
  \item patients with big tumors have a smaller recovery rate;
  \item patients with big tumors are more often prescribed surgery.
  \end{itemize}

  \vfill
  \pause

  The drug is less effective.  It \emph{appears} more effective
  because it is applied more frequently to less severe cancers.

  \vfill
  \pause

  Here, looking at the partitioned objects is preferable\dots{}
  \uncover<4>{but that is not always true.  Notice that any attribute
    could be used to partition the objects.}
\end{frame}

\begin{frame}
  \frametitle{Confirmation of previous beliefs (1/3)}
  The analyst believes high fat diets entail heart diseases.  She
  collects data about 1000 randomly selected people:

  \vfill

  \begin{center}
    \begin{tabular}{cccc}
      & heart disease & no heart disease & disease rate\\
      \hline
      high fat & 300 & 300 & \alert<2>{50\%}\\
      low fat & 100 & 300 & \alert<2>{25\%}
    \end{tabular}
  \end{center}

  \vfill
  \pause

  People on high fat diets develop heart diseases twice more often.
\end{frame}

\begin{frame}
  \frametitle{Confirmation of previous beliefs (2/3)}
  Further partitioning the \emph{same} people w.r.t. whether their
  diets are low/high sugar:

  \vfill

  \begin{description}
  \item[High sugar:] \begin{tabular}{ccc}
      & heart disease & no heart disease\\
      \hline
      high fat & 300 & \alert<3>{100}\\
      low fat & 100 & \alert<3>{100}
    \end{tabular}
    \begin{center}
      disease rate: \alert<2>{67\%}
    \end{center}
    \vfill
  \item[Low sugar:] \begin{tabular}{ccc}
      & heart disease & no heart disease\\
      \hline
      high fat & 0 & \alert<3>{200}\\
      low fat & 0 & \alert<3>{200}
    \end{tabular}
    \begin{center}
      disease rate: \alert<2>{0\%}
    \end{center}
  \end{description}
\end{frame}

\begin{frame}
  \frametitle{Confirmation of previous beliefs (3/3)}
  High sugar diets are more strongly correlated with heart diseases
  than high fat diets.

  \vfill
  \pause

  If high sugar diets \alert<4>{cause} heart diseases, the correlation
  between high fat diets and heart diseases may be only due to the
  correlation between diets: the more sugar is eaten, the more fat as
  well.

  \vfill
  \pause

  Because of previous beliefs, the analyst may not collect data about
  how sugary the diets.
\end{frame}

\section{Scientific methods}

\begin{frame}
  \frametitle{Randomized controlled trial}
  Once an hypothesis formed, a \emph{randomized controlled trial}:
  \begin{enumerate}[<+->]
  \item randomly splits a population into statistically identical
    groups (according to gender, age, race, socioeconomic status,
    etc.);
  \item fixes the possible cause to a different value (the cure or the
    diet in the previous examples) in each group but one (the control
    group);
  \item observes the effects and tests whether the dependence between
    the controlled attribute and the effect is \emph{statistically
      significant}.
  \end{enumerate}

  \vfill

  \uncover<4->{Randomized controlled trials may be:
    \begin{itemize}
    \item time consuming and expensive;
    \item \uncover<5->{impossible to conduct, \eg, in astronomy or in
        macroeconomics;}
    \item \uncover<6>{unethical, \eg, forcing a group to smoke.}
    \end{itemize}
  }
\end{frame}

\begin{frame}
  \frametitle{Other scientific methods}
  Establishing an evidence of a causal relationship requires different
  methods in different scientific areas.

  \vfill
  \pause

  \begin{exampleblock}{The Bradford Hill criteria, in epidemiology}
    Strength (effect size), consistency (reproducibility),
    specificity, temporality, biological gradient, plausibility,
    coherence, experiment, analogy, and reversibility.
  \end{exampleblock}

  \vfill
  \pause

  Statistical hypothesis testing is misunderstood, overused and
  misused.  It is heavily criticized... but remains the norm.
\end{frame}

\section{Statistical hypothesis testing}

\begin{frame}
  \frametitle{Statistical hypothesis testing}
  A \emph{statistical hypothesis test} provides a p-value, the
  probability that chance alone explains the observed result or a more
  extreme result.

  \vfill
  \pause

  It is often considered that a p-value below 0.05 indicates a
  statistically \emph{significant} result.

  \vfill
  \pause

  Here, ``significant'' does not have its popular meaning.  A p-value
  tells nothing about the effect size.  If a dependence exists, more
  objects entail a smaller p-value.

  \vfill
  \pause

  More assumptions on the attributes (\eg, statistical independence,
  normal distribution, etc.) mean less objects are required to get a
  smaller p-value.
\end{frame}

\begin{frame}
  \frametitle{Statistical hypothesis testing: example}
  \begin{block}{Hypothesis}
    There are \emph{more} French births on full-moon days.
  \end{block}

  \vfill
  \pause

  \begin{block}{Null hypothesis}
    \only<2>{There are \emph{no more} French births on full-moon days
      than on any other day.}\only<3>{In France, the probability to
      be born on a full-moon day is the probability of a full-moon
      day.}
  \end{block}
\end{frame}

\begin{frame}
  \frametitle{Statistical hypothesis testing: example}
  \url{https://insee.fr/fr/statistiques/fichier/2904770/T79jnais.xls}
  provides the daily distribution of the \numprint{38011313} French
  births from January 1st, 1968 to December 31st, 2016.

  \vfill
  \pause

  \url{https://www.timeanddate.com/moon/phases/france/paris} lists the
  606 full-moon days among those \numprint{17898} days.
  \numprint{1295426} French babies were born on one of those 606
  full-moon days.
\end{frame}

\begin{frame}
  \frametitle{Statistical hypothesis testing: example}
  The null hypothesis is that, in France, the probability to be born
  on a full-moon day is $\frac{606}{\numprint{17898}} = 0.03385853$.

  \vfill
  \pause

  Under that hypothesis, the exact probability to have, among the
  \numprint{38011313} French births, at least \numprint{1295426} on
  full-moon days is:
  \begin{displaymath}
    \sum_{k = \numprint{1295426}}^{\numprint{38011313}}
    \left(\begin{array}{c}
            \numprint{38011313}\\
            k
          \end{array}\right)0.03385853^k(1 -
        0.03385853)^{\numprint{38011313} - k} \enspace .
  \end{displaymath}

  \vfill
  \pause

  Hard to compute!
\end{frame}

\begin{frame}
  \frametitle{Statistical hypothesis testing: example}
  The central limit theorem applies here: the normal distribution of
  mean $\numprint{38011313} \times 0.03385853 = \numprint{1287007}$
  and variance
  $\numprint{1287007} \times (1 - 0.03385853) = \numprint{1243431}$
  well approximates the binomial distribution.

  \vfill
  \pause

  \begin{center}
    \includegraphics[width=.5\linewidth]{img/normal}
  \end{center}
\end{frame}

\begin{frame}
  \frametitle{Statistical hypothesis testing: example}
  Under the null hypothesis, using the normal approximation, the
  probability to have, among the \numprint{38011313} French births, at
  least \numprint{1295426} on full-moon days is:
  \begin{displaymath}
    \frac{1}{2} -
    \frac{1}{\sqrt{\pi}}\int_0^{\frac{\numprint{1295425.5} -
        \numprint{1287007}}{\sqrt{2 \times \numprint{1243431}}}}
    e^{-t^2} \, dt = 2.176037 \times 10^{-14} \enspace .
  \end{displaymath}

  \vfill
  \pause

  It is foolish to believe that the probability to be born on a
  full-moon day is $\frac{606}{17898} = 0.03385853$\dots
  \uncover<3>{but is it the proper null hypothesis?}
\end{frame}

\begin{frame}
  \frametitle{Statistical hypothesis testing: example}
  \begin{block}{Null hypothesis}
    There are \emph{no more} French births on full-moon days than on
    any other day.
  \end{block}

  \vfill

  \uncover<2>{The \emph{statistical unit} is the day.  Indeed, the
    experimental conditions are the same during a given day.  Choosing
    the birth as the statistical unit was pseudoreplication.}

  \vfill

  \uncover<2>{\pub Stuart H. Hurlbert.  Pseudoreplication and the
    Design of Ecological Field Experiments.  \emph{Ecological
      Monographs}, 54(2):187--211, 1984.}
\end{frame}

\begin{frame}
  \frametitle{Statistical hypothesis testing: example}
  \numprint{1295426} French babies were born on one of the 606
  full-moon days:
  $\frac{\numprint{1295426}}{606} = \numprint{2137.67}$ in average.
  The sample variance is \numprint{57585}.  In other terms, the
  standard deviation is $\approx 240$.

  \vfill

  \numprint{36715887} French babies were born on one of the
  \numprint{17292} other days:
  $\frac{\numprint{36715887}}{\numprint{17292}} = \numprint{2123.29}$
  in average.  The sample variance is \numprint{59232}.  In other
  terms, the standard deviation is $\approx 243$.

  \vfill
  \pause

  Compared to the standard deviations, the effect size (a difference
  of $\approx 14$ births) is small: the study could (should?) stop
  here.
\end{frame}

\begin{frame}
  \frametitle{Statistical hypothesis testing: example}
  Assuming the distribution of the French births over each set of days
  is normal, Welch's $t$-test tests whether the mean number of births
  on full-moon days is significantly greater than the mean number of
  births on the other days.

  \vfill

  \begin{displaymath}
    t = \frac{\numprint{2137.67} -
      \numprint{2123.29}}{\sqrt{\frac{\numprint{57585}}{606} -
        \frac{\numprint{59232.5}}{\numprint{17292}}}} = 1.44927
  \end{displaymath}
  , with
  \begin{displaymath}
    \frac{\left(\frac{\numprint{57585}}{606} +
        \frac{\numprint{59232.5}}{\numprint{17292}}\right)^2}{\frac{\numprint{57585}^2}{606^2
      (606 - 1)}
    + \frac{\numprint{59232.5}^2}{\numprint{17292}^2 (\numprint{17292}
    - 1)}} = 649.374\text{ degrees of freedom.}
  \end{displaymath}
\end{frame}

\begin{frame}
  \frametitle{Statistical hypothesis testing: example}
  Taking Student's $t$-distribution with 649.374 degrees of freedoms,
  the probability to exceed 1.44927 is 0.0738725.

  \vfill
  \pause

  At a 0.05 significance level, there are \emph{no more} French births
  on full-moon days than on any other day.

  \vfill
  \pause

  A simulation repetitively sub-sampling, in a uniform way, 606 of the
  \numprint{17898} days and summing the number of births confirms that
  result: of \numprint{100000} sub-samples, $7.5\%$ had a total number
  of births of \numprint{1295426} or more.
\end{frame}

\begin{frame}
  \frametitle{Frequentist vs. Bayesian statistics}
  A p-value is the probability of the observations given the null
  hypothesis, which is rejected if the p-value is below an arbitrary
  threshold, \eg, 0.05.  Nevertheless, ``the more extraordinary a fact
  is, the more it needs to be supported by strong evidence''
  (Pierre-Simon Laplace, 1812), a lower threshold.
  % ``extraordinary claims require extraordinary evidence'' (Carl
  % Sagan), a lower threshold.

  \vfill
  \pause

  What matters is the probability of the hypothesis given the
  observations.  By Bayes' theorem and the law of total probability,
  computing it requires the probability of the observations given
  every possible hypothesis and the \emph{prior} probabilities of
  these theories.  Observations modify those prior probabilities.
\end{frame}

\section{Some datasets}

\begin{frame}
  \frametitle{Some datasets (1/3)}
  \begin{itemize}
  \item \href{http://archive.ics.uci.edu/ml/datasets.html}{UCI Machine
    Learning Repository};
  \item \href{http://lib.stat.cmu.edu}{StatLib};
  \item \href{http://billmill.org/open_data.html}{My Name Rhymes};
  \item
    \href{http://www.cs.washington.edu/research/xmldatasets/www/repository.html}{XML
      Data Repository};
  \item
    \href{http://vlado.fmf.uni-lj.si/pub/networks/data/UciNet/UciData.htm}{UCINET
      IV Datasets};
  \item
    \href{http://www.datawrangling.com/some-datasets-available-on-the-web}{Data
      Wrangling};
  \item \href{http://sci2s.ugr.es/keel/datasets.php}{KEEL-dataset}
  \item \href{http://datamarket.com/data}{Data Market};
  \item \href{http://datamob.org/datasets}{Datamob}.
  \end{itemize}
\end{frame}

\begin{frame}
  \frametitle{Some datasets (2/3)}
  \begin{itemize}
  \item \href{https://huggingface.co/datasets}{Hugging Face's
      datasets}
  \item \href{http://dataviva.info/data/}{DataViva} (Brazilian open
    data);
  \item
    \href{http://webscope.sandbox.yahoo.com/catalog.php}{Webscope};
  \item
    \href{http://www.mpi-inf.mpg.de/departments/databases-and-information-systems/research/yago-naga/yago/}{YAGO2s};
  \item \href{http://iv.slis.indiana.edu/db/index.html}{InfoVis
      CyberInfrastructure};
  \item \href{http://dobbs.deri.ie/?page_id=123}{DERI Online Browsing
      Behavior Study};
  \item \href{http://www.memetracker.org/data.html}{MemeTracker Data};
  \item \href{http://netsg.cs.sfu.ca/youtubedata}{YouTube Dataset};
  \item \href{http://www.kaggle.com}{Kaggle Competition}.
  \end{itemize}
\end{frame}

\begin{frame}
  \frametitle{Some datasets (3/3)}
  \begin{itemize}
  \item Chats of StarCraft II's channels on
    \href{http://twitch.tv/}{\texttt{twitch.tv}};
  \item Countries;
  \item 2010 legislative elections in the Rhône, France;
  \item Public bicycle network in Lyon between May 2005 and December
    2007;
  \item Re-tweets on the Brasileirão in 2010--2011 and 2014;
  \item \href{http://distrowatch.com}{\texttt{DistroWatch.com}} logs
    between 2002 and 2010;
  \item BH crimes in 2003;
  \item Patient-doctors relationships;
  \item Flights of the federal government in 2007;
  \item Online purchases of the federal government in 2006;
  \item Vestibular UFMG 2004.
  \end{itemize}
\end{frame}

\begin{frame}
  \frametitle{Building your own dataset}
  \begin{itemize}
  \item Choosing data you have interest in is better;
  \item Eventually, these data should be mainly objects described with
    simple attributes;
  \item You need to understand the application domain;
  \item More attributes mean more possibilities of knowledge
    discovery;
  \item More objects mean discoveries that are statistically more
    relevant... but makes the work harder too.
  \end{itemize}

  \vfill
  \pause

  A significant work (contacts with people, scripts, etc.) to build a
  dataset could be the non-trivial step of your project.
\end{frame}

\section*{Homework}

\begin{frame}
  \frametitle{To read and practice}
  \begin{alertblock}{Reading and practicing for March 31st}
    On \url{http://archive.flossmanuals.net/command-line/}, read and
    practice:
    \begin{itemize}
    \item The whole ``Basics'' section;
    \item The subsections ``Basic commands'', ``Cut down on typing''
      and ``Redirection'' of the ``Commands'' section;
    \item The subsection ``Piping'' of the ``Advanced-ish'' section.
    \end{itemize}
  \end{alertblock}
\end{frame}

\section*{}

\begin{frame}
  \frametitle{License}
  \begin{block}{\copyright 2012--2025 Loïc Cerf}
    \includegraphics[height=1.5ex]{img/licenses/cc-by-sa}\hskip1pt
    These slides are licensed under the Creative Commons
    Attribution-ShareAlike 4.0 International License.
  \end{block}
\end{frame}

\end{document}