---
title: "Units of analysis, replication, and study design"
subtitle: "People, specimens, cells, and the comparisons a design supports."
guide-status: "Available"
---
**Before reading:** The population and observation record in [From a research question to an identified estimand](question-to-estimand.qmd), elementary means, variance, and basic regression.
## Count the units that support the claim
A study can contain thousands of features, hundreds of specimens, and only a few independently sampled people. Those counts answer different questions. More technical measurements can improve the precision of a person's measurement without providing more independent evidence about variation between people.
A biological replicate is defined relative to the scientific comparison. A person may be the replicate for a patient–control question; a culture or independently randomized animal may be the replicate in another experiment. A specimen is collected material. An aliquot or assay run is a technical measurement. A cell is nested in a specimen and person unless the design supports another independence argument.
Write the sampling and treatment-assignment units separately. Randomization establishes a known assignment mechanism; independent sampling supports population generalization under the sampling model. Neither follows from having one row per measurement.
For example, a donor may supply two tissues, several assay runs, and thousands of cells. The cells describe within-donor variation; the independently sampled donors supply between-donor evidence. In a trial randomized by clinic, people can also share a clinic-level assignment and dependence. State the largest relevant shared unit instead of assuming that “person” is always sufficient. The target's averaging unit, assignment unit, and independent sampling unit can differ, and the analysis must connect them.
## Weighting visits changes the target
Suppose one person has one visit with mean outcome 0 and another has four visits with mean outcome 4. A pooled visit mean weights the second person four times as heavily. A mean of person means weights the people equally.
```{r}
d <- data.frame(person = c("p1", rep("p2", 4)), y = c(0, 4, 4, 4, 4))
person_mean <- tapply(d$y, d$person, mean)
answers <- c(visit_weighted = mean(d$y), person_weighted = mean(person_mean))
answers
```
<span id="fig-visit-weights"></span>
The pooled calculation is $(0+4+4+4+4)/5=3.2$. The person calculation is $(0+4)/2=2$. Both use the same measurements, but answer different averaging questions. These two people illustrate weighting; they do not provide a reliable population SE by themselves.
For a population of independent person records, these correspond to $E[\sum_tY_{it}]/E[M_i]$ and $E[M_i^{-1}\sum_tY_{it}]$, respectively, when every person has at least one visit and the relevant expectations exist. They need not coincide if visit count $M_i$ is related to outcomes. A balanced schedule removes this particular weighting difference, but not dependence within a person.
Write each person's recorded-visit average as $\bar Y_i$. The difference between the population visit-weighted and person-weighted means is
$$
\begin{aligned}
\mu_{\rm visit}&=\frac{E[M_i\bar Y_i]}{E[M_i]},\\
\mu_{\rm person}&=E[\bar Y_i],\\
\mu_{\rm visit}-\mu_{\rm person}
&=\frac{\operatorname{Cov}(M_i,\bar Y_i)}{E[M_i]}.
\end{aligned}
$$
This identifies the mechanism: people with more measurements receive more weight, and the summaries differ when measurement count co-varies with their recorded average. Even a person-weighted recorded-visit mean is not automatically a fixed-time trajectory if visits are triggered by disease activity. Equal person weights address weighting, not informative observation times.
## Why pseudoreplication makes uncertainty too small
For a balanced model with $J$ independent people, $m$ measurements per person, marginal variance $\sigma^2$, and common within-person correlation $\rho$, the grand mean has variance
$$
\operatorname{Var}(\bar Y)=\frac{\sigma^2}{Jm}\{1+(m-1)\rho\}.
$$
To derive it, one person's sum has m variance terms and $m(m-1)$ covariance terms. There are J independent such sums, and the grand mean divides their total by Jm:
$$
\begin{aligned}
\operatorname{Var}\!\left(\sum_{t=1}^mY_{it}\right)&=m\sigma^2+m(m-1)\rho\sigma^2,\\
\operatorname{Var}(\bar Y)&=\frac{J\{m\sigma^2+m(m-1)\rho\sigma^2\}}{(Jm)^2}.
\end{aligned}
$$
For positive $\rho$, treating rows as independent omits a factor greater than one. The often-used effective sample size $Jm/\{1+(m-1)\rho\}$ follows from this particular balanced model; it is not a universal formula for longitudinal or single-cell data.
```{r}
set.seed(12)
J <- 30; m <- 4
person <- rep(seq_len(J), each = m)
y <- rnorm(J)[person] + rnorm(J * m) # theoretical ICC = 1/2
c(naive_SE = sd(y) / sqrt(length(y)),
person_level_SE = sd(tapply(y, person, mean)) / sqrt(J),
theoretical_inflation = sqrt(1 + (m - 1) * 0.5))
```
The sample ratio varies. The model calculation predicts an inflation factor of $\sqrt{2.5}$ relative to independent measurement sampling. This is a statement about the grand mean; other contrasts and unbalanced designs require their own variance calculation.
### What more measurements can and cannot buy
The simulation uses a random intercept: $Y_{it}=\mu+U_i+\varepsilon_{it}$, with independent person terms of variance $\tau^2$ and independent measurement errors of variance $\sigma_e^2$. Then
$$
\operatorname{Var}(\bar Y)=\frac{\tau^2}{J}+\frac{\sigma_e^2}{Jm}.
$$
More measurements reduce the second term. With J fixed, they do not remove the first, which reflects variation between sampled people. More independent people reduce both terms. This is why reducing assay noise and increasing biological replication are different design decisions.
```{r}
#| label: fig-replication-precision
#| echo: false
#| fig-width: 7
#| fig-height: 4.6
#| fig-cap: "Exact model SEs as measurements per person increase, holding the number of independent people at 30. Between-person and measurement-error variances are both one. Correct uncertainty approaches a between-person floor; treating every row as independent incorrectly predicts continued reduction toward zero. These are model calculations, not estimated SEs from a simulated dataset."
#| fig-alt: "The correct SE curve levels off above a horizontal between-person floor, while an independence-based curve keeps falling as measurements are added to the same people."
grid_m <- seq(1, 40, length.out = 200)
correct_se <- sqrt(1/30 + 1/(30*grid_m))
naive_se <- sqrt(2/(30*grid_m))
par(mar = c(4.5, 4.5, 1, 1))
plot(grid_m, correct_se, type = "l", lwd = 2, col = "#2F80C8",
ylim = c(0, 0.28), xaxt = "n", xlab = "Measurements per person (m)",
ylab = "SE of the grand mean")
axis(1, at = c(1, 10, 20, 30, 40))
lines(grid_m, naive_se, lwd = 2, lty = 2, col = "#D55E00")
abline(h = sqrt(1/30), lty = 3, col = "gray45")
legend("topright", c("Correct: 30 independent people", "Naive: all rows independent",
"Between-person floor"),
col = c("#2F80C8", "#D55E00", "gray45"), lty = 1:3, lwd = c(2, 2, 1),
bty = "n", cex = 0.85)
```
## Match the design to the contrast
For a paired before/after question, define $D_i=Y_{i1}-Y_{i0}$ and analyze the independent person-level differences. Its mean has variance $\operatorname{Var}(D_i)/J$, incorporating the within-person covariance. An unpaired analysis discards that structure.
Here positive within-person correlation can improve precision: $\operatorname{Var}(D_i)=\operatorname{Var}(Y_{i1})+\operatorname{Var}(Y_{i0})-2\operatorname{Cov}(Y_{i1},Y_{i0})$. Shared person-level variation cancels in the difference. Thus “dependence always inflates every SE” is the wrong lesson. The lesson is to derive uncertainty for the chosen contrast using the actual independent records.
For a subject-level treatment randomized to people, keep each person's records together in a randomization test. For an observational group comparison, whole-person relabeling additionally needs a justified null exchangeability argument. Merely preserving clusters does not make the labels exchangeable.
For a within-person factor, the allowed relabeling depends on the assignment or symmetry assumptions within that person; an arbitrary shuffle of visit times can destroy a time trend. Use the [Multivariate comparisons: permutation and distance-based tests](../analysis-problems/multivariate-comparisons.qmd) page to connect these distinctions to permutation tests.
## Design and adjustment have different jobs
A design matrix describes the modeled mean; a covariance model or cluster-robust variance handles residual dependence. Including a person fixed effect can support within-person comparisons, but cannot separately estimate a group effect constant within person when the indicators are collinear. A mixed model can use between-person information under its assumptions; it does not create independent subjects.
If every patient is measured in one batch and every control in another, a mean model cannot separate the group and batch contributions without additional restrictions or data. Adding both variable names to a formula does not create the missing comparison. Conversely, a full-rank mean design does not establish independence of repeated specimens. Check what the design identifies and how sampling uncertainty is calculated as separate tasks.
Similarly, technical batch correction is not a substitute for modeling within-person sampling. The [single-cell pseudoreplication study by Zimmerman and colleagues](https://www.nature.com/articles/s41467-021-21038-1) documents the practical importance of distinguishing cells from independent individuals. Model choice still depends on the target, design, and measurement distribution.
## Resampling and prediction use the same unit decision
If the goal is generalization to a new person, keep all visits or cells from that person in one validation fold. Otherwise the fitting procedure can see the person's other measurements. Bootstrap independent person records, not arbitrary rows, when that is the sampling model. For a visit-specific target conditional on an existing person, a different validation question may be appropriate; name it explicitly.
Before collecting or analyzing data, record the population, assignment unit, sampling unit, nesting, pairing, timing, planned weights, and which contrasts are identifiable. Inspect whether group varies within each technical batch and whether follow-up counts differ by group. These checks connect replication to the estimand rather than to a universal preferred model.
For the corresponding contribution and SE calculations, continue to [Dependent observations and cluster-aware inference](../estimation-and-inference/dependent-observations.qmd).
## Exercises
Try each checkpoint before opening its hint or solution.
::: {#checkpoint-des-02 .checkpoint}
### Checkpoint · DES-02 — Choose a unit, weighting, and resampling design {.unnumbered}
**Task type:** Derivation and design.
A study enrolls 20 controls and 20 patients. Each control has two visits and each patient has six. The target is the equally person-weighted mean of each person's recorded-visit average, contrasted between groups. Describe a matching estimator, variance/resampling unit, and fold allocation. In this fixed-count-per-group design, do pooled and person-summary group means differ? Which part of an independent-row analysis is still wrong, and what can change if visit counts vary within groups? Explain why whole-person label permutation is not automatically valid in this observational setting.
For the balanced random-intercept model, derive the grand-mean variance and its limit as measurements per person increase with the number of people fixed.
**Ready to continue when:** you can connect target weights and independent records to estimation, derive the grand-mean variance, and choose an uncertainty and validation unit.
**Transfer:** If follow-up is triggered by worsening disease within each group, does averaging recorded visits identify a fixed-time disease trajectory?
<details class="checkpoint-help">
<summary>Hint</summary>
Start by forming one defined summary per person; then ask which labels were randomized or exchangeable.
</details>
<details class="checkpoint-help">
<summary>Solution outline — open after trying</summary>
Average the recorded outcomes within each person, then compare the 20 independent summaries per group, with a variance model appropriate for their heterogeneity. Bootstrap whole people within the appropriate sampling strata and assign whole people to validation folds. A row-level mean weights records according to visit count; in this particular fixed-count-per-group design the within-group means coincide with averages of person means, but a row-level independent-error standard error is still wrong. With variable counts within groups the point-estimate weights can differ as well. The random-intercept variance is $\tau^2/J+\sigma_e^2/(Jm)$ and approaches $\tau^2/J$ as m increases with J fixed. Observational group labels and unequal follow-up structures need their own exchangeability justification; keeping a cluster intact is necessary for some schemes but not sufficient for validity.
</details>
:::
### Additional practice (optional) {.unnumbered}
1. Derive the balanced-cluster variance formula by summing variances and covariances.
2. Simulate paired measurements with increasing correlation and compare paired and unpaired interval widths.
3. Draw the nesting structure for a single-cell experiment with donors, tissues, technical runs, and cells.
## Reading
- Zimmerman, Espeland, and Langefeld (2021), [pseudoreplication in single-cell studies](https://www.nature.com/articles/s41467-021-21038-1).
<span id="continue-through-the-collection"></span>