---
title: "Randomization 1: Some common types of randomization | *Randomisation 1 : Quelques types courants de randomisation*"
author: "Adikath + Yannick; Vin + Vincent"
date: today
bibliography: assets/learningdays-book.bib
format:
  revealjs:
    embed-resources: true
---

## Some common types of randomization | *Quelques types courants de randomisation*

```{r, include= FALSE}
library(DeclareDesign)
```

::: {.columns}
::: {.column .lang-en width="50%"}

1. Simple
2. Complete
3. Block
4. Cluster
5. Block-Cluster

6. Design: Multi-arm

:::
::: {.column .lang-fr width="50%"}

1. Simple
2. Complète
3. Par bloc (ou stratifiée)
4. Par grappe (cluster)
5. Combinaison par bloc et par grappe

6. Conceptions à plusieurs bras

:::
:::

## 1. Simple randomization (coin-flipping) | *Randomisation simple (tirage au sort)*

::: {.columns}
::: {.column .lang-en width="50%"}

- For each unit, flip a coin to see if it will be treated. Then you measure outcomes at the same level as the coin.
- The coins don't have to be fair (50-50), but you have to know the probability of treatment assignment.

:::
::: {.column .lang-fr width="50%"}

- Pour chaque unité, lancez une pièce pour voir si elle sera traitée. Ensuite, vous mesurez les résultats au même niveau que la pièce.
- Les pièces ne doivent pas nécessairement être équitables (50-50), mais vous devez connaître la probabilité d'assignation du traitement.

:::
:::

## 1. Simple randomization (coin-flipping) | *Randomisation simple (tirage au sort)*

![](images/simple_randomization_wide.png){width="360px" fig-align="center"}

## 1. Simple randomization (coin-flipping) | *Randomisation simple (tirage au sort)*

::: {.columns}
::: {.column .lang-en width="50%"}

- Advantage: Simple randomization can handle not knowing the total size of your sample in advance.
- Disadvantage: You can't guarantee a specific number of treated units and control units.

:::
::: {.column .lang-fr width="50%"}

- Avantage : la randomisation simple permet de ne pas connaître à l'avance la taille totale de l'échantillon.
- Désavantage : vous ne pouvez pas garantir un nombre précis d'unités traitées et d'unités de contrôle.

:::
:::

```{r, echo = TRUE}
simple_ra(3)
simple_ra(3)
```

## 2. Complete randomization (drawing from an urn) | *Randomisation complète (tirage d'une urne)*

::: {.columns}
::: {.column .lang-en width="50%"}

- A fixed number $m$ out of $N$ units are assigned to treatment.
- The probability a unit is assigned to treatment is $m/N$.
- This is like having an urn or bowl with $N$ balls, of which $m$ are marked as treatment and $N-m$ are marked as control. Public lotteries use this method.

:::
::: {.column .lang-fr width="50%"}

- Un nombre fixe de $m$ sur $N$ unités est assigné au traitement.
- La probabilité qu'une unité soit assignée au traitement est de $m/N$.
- C'est comme avoir une urne avec $N$ boules, dont $m$ sont marquées comme traitement et $N-m$ comme contrôle. La loterie publique utilise cette méthode.

:::
:::

## 2. Complete randomization (drawing from an urn) | *Randomisation complète (tirage d'une urne)*

![](images/complete_randomization_wide.png){width="380px" fig-align="center"}

## 2. Complete randomization (drawing from an urn) | *Randomisation complète (tirage d'une urne)*

::: {.columns}
::: {.column .lang-en width="50%"}

- Advantage: Particularly useful when you have a small number of units to avoid having all units in only one condition.
- Disadvantage: You need to know the total number of units in advance.

:::
::: {.column .lang-fr width="50%"}

- Avantage : particulièrement utile lorsque vous avez un petit nombre d'unités pour éviter que toutes les unités soient dans une seule condition.
- Désavantage : il faut connaître à l'avance le nombre total d'unités.

:::
:::

```{r, echo = TRUE}
complete_ra(4)
complete_ra(4)
```


## 3. Block (or stratified) randomization | *Randomisation par bloc (ou stratifiée)*

::: {.columns}
::: {.column .lang-en width="50%"}

- We create groups of units (blocks) and randomize separately within each block.
- We are doing mini-experiments in each block so **we have both treated and control units in each block**.

:::
::: {.column .lang-fr width="50%"}

- Nous créons des blocs d'unités et randomisons séparément dans chaque bloc.
- Nous faisons des mini-expériences dans chaque bloc. De ce fait, **nous avons des unités traitées et des unités de contrôle dans chaque bloc**.

:::
:::

## 3. Block (or stratified) randomization | *Randomisation par bloc (ou stratifiée)*

![](images/block_randomization.png){width="360px" fig-align="center"}

::: {.columns}
::: {.column .lang-en width="50%"}

- Example: block = region, units = municipalities. We randomize treatment at the municipality level **within region** and also measure outcomes at the municipality level.

:::
::: {.column .lang-fr width="50%"}

- Exemple : bloc = région, unités = communautés. Nous randomisons le traitement au niveau communautaire **au sein de la région** et mesurons également les résultats au niveau communautaire.

:::
:::

## 3. Block (or stratified) randomization | *Randomisation par bloc (ou stratifiée)*

![](images/block_randomization_diffsize.png){width="360px" fig-align="center"}

::: {.columns}
::: {.column .lang-en width="50%"}

- Blocks can be of different sizes.

:::
::: {.column .lang-fr width="50%"}

- La taille des blocs peut varier.

:::
:::

## 3. Block (or stratified) randomization | *Randomisation par bloc (ou stratifiée)*

![](images/block_randomization_diffprob.png){width="360px" fig-align="center"}

::: {.columns}
::: {.column .lang-en width="50%"}

- Blocks can have different probabilities of treatment assignment.

:::
::: {.column .lang-fr width="50%"}

- La probabilité de sélection des individus dans le groupe de traitement peut varier d'un bloc à un autre.

:::
:::

## 3. Block (or stratified) randomization | *Randomisation par bloc (ou stratifiée)*

::: {.columns}
::: {.column .lang-en width="50%"}

How should you define your blocks?

1. Create subgroups for which you want to learn the ATE. The average causal effect for a particular subgroup is known as a Conditional Average Treatment Effect (CATE). You can use these to learn differences in CATEs for one group as compared with another group.

:::
::: {.column .lang-fr width="50%"}

Comment définir vos blocs ?

1. Créez des sous-groupes pour lesquels vous souhaitez estimer l'ATE. L'effet moyen de traitement pour un sous-groupe est aussi appelé effet moyen de traitement conditionnel (CATE). Vous pouvez les utiliser pour connaître les différences entre les CATE d'un groupe et d'un autre.

:::
:::

## 3. Block (or stratified) randomization | *Randomisation par bloc (ou stratifiée)*

::: {.columns}
::: {.column .lang-en width="50%"}

How should you define your blocks?

2. By variables that predict the outcome. This will increase the precision of your estimates.

:::
::: {.column .lang-fr width="50%"}

Comment définir vos blocs ?

2. Par des variables qui prédisent le résultat. Cela augmentera la précision de vos estimations.

:::
:::

## 3. Block (or stratified) randomization | *Randomisation par bloc (ou stratifiée)*

::: {.columns}
::: {.column .lang-en width="50%"}

- Advantage: You avoid unlucky randomizations that create treatment and control groups that differ on the variables used to create the blocks. Blocks are generally very helpful.
- This is especially useful for rare subgroups.
- But we need data to form the blocks before the randomization.

:::
::: {.column .lang-fr width="50%"}

- Avantage : vous évitez les randomisations malheureuses qui créent des groupes de traitement et de contrôle différents selon la variable utilisée pour créer les blocs. Les blocs sont généralement très utiles.
- Particulièrement utile lorsque vous avez un groupe rare.
- Mais nous avons besoin de données pour former des blocs avant la randomisation.

:::
:::

## 3. Block (or stratified) randomization | *Randomisation par bloc (ou stratifiée)*

```{r, echo = TRUE}
blocks <- c(1,1,1,1,2,2,2,2)
block_ra(blocks = blocks)
block_ra(blocks = blocks)
```


## 4. Cluster randomization | *Randomisation par grappe (cluster)*

::: {.columns}
::: {.column .lang-en width="50%"}

- In a cluster-randomized study, all units in a group of units (the cluster) are assigned to the **same** treatment status.

:::
::: {.column .lang-fr width="50%"}

- Dans une étude randomisée par grappe, toutes les unités de la grappe sont assignées au **même** statut de traitement.

:::
:::

## 4. Cluster randomization | *Randomisation par grappe (cluster)*

![](images/cluster_randomization.png){width="360px" fig-align="center"}

::: {.columns}
::: {.column .lang-en width="50%"}

- Treatment is randomized at the cluster level.
- Outcomes are measured at the unit level.

:::
::: {.column .lang-fr width="50%"}

- Le traitement est assigné au niveau de la grappe.
- Le résultat est mesuré au niveau de l'unité.

:::
:::

## 4. Cluster randomization | *Randomisation par grappe (cluster)*

::: {.columns}
::: {.column .lang-en width="50%"}

- When should you do cluster randomization? If the intervention has to work at the cluster level.
- Don't if you can avoid it! Cluster randomization generally reduces statistical power. *How much* depends on the intra-cluster correlation (ICC or $\rho$). Higher $\rho$ is worse.

:::
::: {.column .lang-fr width="50%"}

- Quand procéder à une randomisation par grappe ? Si l'intervention doit fonctionner au niveau de la grappe.
- Ne le faites pas si vous pouvez l'éviter ! La randomisation par grappe réduit généralement la puissance statistique. La quantité dépend de la corrélation intra-groupe (ICC ou $\rho$). Un $\rho$ plus élevé est pire.

:::
:::

## 4. Cluster randomization | *Randomisation par grappe (cluster)*

::: {.columns}
::: {.column .lang-en width="50%"}

- If you must use cluster randomization, having more clusters helps.
- Having fewer clusters hurts our ability to detect treatment effects and may cause misleading $p$-values and confidence intervals (or even estimates).

:::
::: {.column .lang-fr width="50%"}

- Si vous devez utiliser la randomisation par grappe, il est préférable d'en avoir un plus grand nombre.
- Un nombre réduit de grappes nuit à votre capacité à détecter les effets du traitement et conduit à des $p$-valeurs et des intervalles de confiance (ou même des estimations) trompeurs.

:::
:::

## 4. Cluster randomization | *Randomisation par grappe (cluster)*

```{r, echo = TRUE}
my_clusters <- c(1,1,1,1,2,2,2,2)
cluster_ra(clusters = my_clusters)
cluster_ra(clusters = my_clusters)
```

## 5. You can combine blocks and clusters | *Vous pouvez combiner blocs et grappes*

![](images/blockcluster_randomization.png){width="300px" fig-align="center"}

::: {.columns}
::: {.column .lang-en width="50%"}

- You can have clusters within blocks.
- Can you have blocks within clusters?

:::
::: {.column .lang-fr width="50%"}

- Vous pouvez avoir des grappes dans des blocs.
- Est-ce que vous pouvez avoir des blocs dans les grappes ?

:::
:::


## 5. You can combine blocks and clusters | *Vous pouvez combiner blocs et grappes*

```{r, echo = TRUE}
my_blocks <- c(1,1,1,1,2,2,2,2)
my_clusters <- c(1,1,2,2,3,3,4,4)
block_and_cluster_ra(blocks = my_blocks, clusters = my_clusters)
block_and_cluster_ra(blocks = my_blocks, clusters = my_clusters)
```

## 6. Multi-arm design | *Conception à plusieurs bras*

::: {.columns}
::: {.column .lang-en width="50%"}

- You can randomize units to more conditions (arms) than just one treatment arm and one control arm.
- For example, we might have a cash transfer arm, a job training arm, and a control arm with no intervention.

:::
::: {.column .lang-fr width="50%"}

- Vous pouvez randomiser les unités dans plus de conditions (bras) qu'un seul bras de traitement et un bras de contrôle.
- Par exemple, nous pourrions avoir un groupe de transfert d'argent, un groupe de formation à l'emploi, et un groupe de contrôle sans intervention.

:::
:::

## 6. Multi-arm design | *Conception à plusieurs bras*

![](images/multiarm_design_wide.png){width="250px" fig-align="center"}

::: {.columns}
::: {.column .lang-en width="50%"}

- An example with complete randomization

:::
::: {.column .lang-fr width="50%"}

- Un exemple avec une randomisation complète

:::
:::

## 6. Multi-arm design | *Conception à plusieurs bras*

::: {.columns}
::: {.column .lang-en width="50%"}

- Advantages: We can compare each treatment to control or to each other.
- Disadvantages: We can quickly end up with a very large number of hypothesis tests, which can be a problem.

:::
::: {.column .lang-fr width="50%"}

- Avantages : nous pouvons comparer chaque traitement au contrôle ou l'un à l'autre.
- Désavantage : on peut rapidement se retrouver avec un très grand nombre de tests d'hypothèses, ce qui pose des problèmes.

:::
:::

## 6. Multi-arm design | *Conception à plusieurs bras*

```{r, echo = TRUE}
complete_ra(12, num_arms = 3)
complete_ra(12, prob_each = c(.1, .2, .7))
```

## Resource | *Ressource*

::: {.columns}
::: {.column .lang-en width="50%"}

EGAP Methods Guide on Randomization: <https://egap.org/resource/10-things-to-know-about-randomization/>

:::
::: {.column .lang-fr width="50%"}

Guide des méthodes EGAP sur la randomisation : <https://egap.org/fr/resource/10-choses-a-savoir-sur-la-randomisation/>

:::
:::
