0%
DQDigital Qasas Courses/Medical Statistics with R and Python
Sign inAll courses
  • Why R and Python, and running them in your browser
  • Data frames, import, and tidy medical data
  • Tables and summaries
  • Variables, types, and the question behind the data
  • Displaying data: frequency distributions, histograms, and shape
  • Means, standard deviations and standard errors
  • The normal distribution
  • Confidence interval for a mean
  • Using P-values and confidence intervals
  • Comparison of two means
  • Analysis of variance
  • Linear regression and correlation
  • Multiple regression and diagnostics
  • Transformations
  • Risk, odds, and how to compare them
  • Proportions and the binomial distribution
  • Two proportions: risk ratio, odds ratio, risk difference, and confidence intervals
  • Chi-squared: 2x2 tables, larger tables, trend, and exact tests
  • Confounding and stratification
  • Logistic regression
  • Matched studies
  • Rates and the Poisson distribution
  • Comparing rates and Poisson regression
  • Standardization: direct, indirect, and the SMR
  • Kaplan-Meier survival curves and the log-rank test
  • Cox proportional-hazards regression
  • Likelihood and the generalized linear model
  • Building models, checking assumptions, and clustered data
  • Systematic reviews and meta-analysis
  • Bayesian statistics
  • Linking analysis to study design
  • Sample size and power
  • Measurement error and its consequences
  • Capstone: from a messy dataset to a reported result
16. Study design, sample size, and measurement

Linking analysis to study design

Last updated 30 June 2026

You have learned methods one outcome at a time: means in the comparing-means module, proportions and odds in binary outcomes, incidence rates in the rates-and-Poisson module, time-to-event in survival analysis. This lesson puts them on one map. A real study asks a plainer question than any single method: I ran this design and I measured this kind of outcome, so what do I compute? The design decides what you are allowed to estimate. The outcome type decides which test reports it. Match the analysis to the study you actually ran, never to the study you wish you had run.

The four designs in brief

Four designs cover most of clinical research, and they differ in one thing: how people are sampled. That sampling rule is what fixes the measure you can report.

DesignHow people enter the studyWhat it can estimateNatural measure
Cross-sectionalA snapshot of a population at one timePrevalence (how common a condition is now)Prevalence, prevalence ratio or odds ratio
CohortSampled by exposure, then followed forwardRisk and incidence rate of new diseaseRisk ratio, rate ratio
Case-controlSampled by outcome: cases and controlsThe association only, as an odds ratioOdds ratio
Randomized trialRecruited, then randomly allocated to treatmentThe causal effect of treatmentRisk difference, risk ratio, rate ratio, hazard ratio

A cross-sectional survey of dengue antibody in a Selangor district tells you what fraction carry antibody today, a prevalence. It cannot tell you the rate at which people are newly infected, because it never watches anyone over time. A cohort that follows uninfected residents forward does measure that incidence. A case-control study starts from people who already have the disease and looks backward at exposure, so it can compare exposure between cases and controls but cannot say how common the disease is. A trial adds randomization on top of a cohort-style follow-up, which is what lets it claim cause rather than association.

Matching the measure to the design

Each design hands you one measure naturally, and the reason is always the sampling.

  • Risk and the risk ratio come from a cohort or a trial, because you start with people free of the outcome and watch who develops it. The denominator is real people at risk.
  • The rate ratio comes from person-time data, where follow-up varies between people. You count events and divide by person-years, as in the rates-and-Poisson module. A cohort with staggered entry or losses reports a rate, not a plain risk.
  • The odds ratio is what a case-control study can give. Sampling on outcome fixes the number of cases and controls by your own choice, so any risk or prevalence you compute is an artefact of that choice. The odds ratio survives this because it does not depend on the case-to-control ratio. When the disease is rare, that odds ratio approximates the risk ratio.
  • Prevalence and the prevalence ratio come from a cross-sectional survey, the snapshot measure.

Outcome type and design together pick the method

Once the design has told you the measure, the outcome type names the test. Numerical outcomes use means and the t-test or linear regression. Binary outcomes use the chi-squared test and logistic regression from the binary-outcomes and logistic-regression modules. Person-time rates use a Poisson-based test. Time-to-event outcomes use the log-rank test and Cox regression from survival analysis. The table below is the whole course read as one grid.

Study designNumerical outcomeBinary outcomeRate (person-time)Survival time
Cross-sectionalMean difference, t-testPrevalence ratio or OR, chi-squared / logisticNot estimableNot estimable
CohortMean difference, t-test / linear regressionRisk ratio, chi-squared / logisticRate ratio, Poisson regressionHazard ratio, log-rank / Cox
Randomized trialMean difference, t-test / linear regressionRisk difference or ratio, chi-squared / logisticRate ratio, Poisson regressionHazard ratio, log-rank / Cox
Case-controlNot usedOdds ratio, chi-squared / (conditional) logisticNot estimableNot estimable

Key term

The analysis plan is the named pairing of design and outcome type with the measure and test, written before you see the results. Two facts, the design and the outcome type, fix the cell in the grid above.

Two ways to handle confounding: design or analysis

Confounding, from the confounding module, has two lines of defence. The first is built into the design before any data arrive. The second is applied in the analysis afterwards.

  1. Design tools. Randomization in a trial balances known and unknown confounders in expectation, which is why a well-run trial needs little adjustment. Restriction recruits only one level of a confounder, say only non-smokers, so it cannot confound. Matching forces cases and controls (or exposed and unexposed) to share the confounder distribution.
  2. Analysis tools. Stratification splits the data by the confounder and pools with Mantel-Haenszel, giving one adjusted estimate. Regression (logistic, Poisson, Cox) adjusts for several confounders at once, including continuous ones.

Design handles only the confounders you anticipated. Randomization is the exception, because it handles the ones you never measured. Analysis can only adjust for confounders you recorded, so an unmeasured confounder is beyond rescue at the analysis stage.

Stratified analysis or a regression model?

Both control confounding, so the choice is about transparency against flexibility. Reach for a stratified Mantel-Haenszel analysis when you have one or two categorical confounders and you want a table that shows each stratum, which also lets you eyeball effect modification. Reach for a regression model when confounders are many, when one is continuous (age in years rather than age bands), or when the strata get so thin that the stratified estimate becomes unstable. One rule holds firm: a matched case-control study must be analysed as matched, with conditional logistic regression or McNemar's test, never as if the pairs were independent.

Worked example 1: a case-control study, odds ratio and chi-squared

Betel quid chewing (sireh and pinang) is common in parts of Malaysia and the wider region and is linked to oral cancer. A hospital team recruits 120 oral-cancer cases and 120 cancer-free controls, then asks each about chewing history. The design samples on outcome, so the measure is the odds ratio and the test is chi-squared.

CasesControls
Chewer8040
Non-chewer4080

The odds ratio is the cross-product, . Chewers have four times the odds of oral cancer in this sample. Do not read 80/120 as a risk: that 0.67 is fixed by the team choosing 120 cases.

Build the 2 × 2 table, compute the odds ratio, and run the chi-squared test.

tab <- matrix(c(80, 40, 40, 80), nrow = 2, byrow = TRUE,
              dimnames = list(exposure = c("Chewer", "Non-chewer"),
                              status   = c("Case", "Control")))
or <- # cross-product ratio
chisq.test(tab, correct = FALSE)
or <- (tab[1, 1] * tab[2, 2]) / (tab[1, 2] * tab[2, 1])
ct <- chisq.test(tab, correct = FALSE)
round(c(OR = or, chisq = unname(ct$statistic), p = ct$p.value), 4)
#      OR   chisq       p
#  4.0000 26.6667  0.0000

Build the 2 × 2 table, compute the odds ratio, and run the chi-squared test.

import numpy as np
from scipy.stats import chi2_contingency
tab = np.array([[80, 40],
                [40, 80]])
or_ = # cross-product ratio
or_ = (tab[0, 0] * tab[1, 1]) / (tab[0, 1] * tab[1, 0])
chi2, p, dof, _ = chi2_contingency(tab, correction=False)
print(round(or_, 4), round(chi2, 4), round(p, 6))
# 4.0 26.6667 0.0

A team runs a case-control study of stroke and untreated hypertension, recruiting 200 stroke cases and 200 stroke-free controls. They want to report how much hypertension raises the chance of stroke. Which measure can their design support?

  • The odds ratio, because sampling on outcome leaves the odds ratio estimable while fixing the case-to-control ratio.
  • The risk ratio, since they can divide stroke cases by the total in each exposure group.
  • The prevalence of stroke, read straight from the 200 cases out of 400 people.
Choosing 200 cases and 200 controls fixes the disease totals by design, so any risk or prevalence you compute reflects that choice, not the population. The 200-of-400 figure is an artefact. The odds ratio is the one measure that does not depend on the case-to-control ratio, which is why case-control studies report it. With a rare disease it also approximates the risk ratio, but the study still estimates an odds ratio.

Worked example 2: a cohort with person-time, the rate ratio

A Malaysian HIV clinic follows two groups for incident tuberculosis: people living with HIV and HIV-negative attendees. Follow-up differs between people, so the denominator is person-years and the measure is the rate ratio, tested with a Poisson method (the rates-and-Poisson module).

  1. HIV-positive group: 30 TB cases in 500 person-years, a rate of 60 per 1,000 person-years.
  2. HIV-negative group: 20 TB cases in 2,000 person-years, a rate of 10 per 1,000 person-years.
  3. Rate ratio: .

HIV carries six times the TB incidence rate here. A plain proportion would have been wrong, because the two groups contributed markedly different amounts of follow-up time.

Compute the two rates, the rate ratio, and an exact Poisson test of the ratio.

d  <- c(30, 20)        # incident TB cases
pt <- c(500, 2000)     # person-years
rr <- # ratio of the two rates
poisson.test(d, pt)
rate <- d / pt
rr   <- rate[1] / rate[2]
pt_test <- poisson.test(d, pt)
round(c(rate1 = rate[1], rate2 = rate[2], RR = rr,
        p = pt_test$p.value), 5)
#   rate1   rate2      RR       p
# 0.06000 0.01000 6.00000 0.00000

Compute the rate ratio, and test it with the conditional binomial that underlies the Poisson rate test.

import numpy as np
from scipy.stats import binomtest
d  = np.array([30, 20])       # incident TB cases
pt = np.array([500, 2000])    # person-years
rr = # ratio of the two rates
rate = d / pt
rr   = rate[0] / rate[1]
# conditional on total events, cases in group 1 ~ Binomial(N, pt1 / total pt)
res = binomtest(int(d[0]), int(d.sum()), pt[0] / pt.sum())
print(round(rate[0], 5), round(rate[1], 5), round(rr, 4), round(res.pvalue, 6))
# 0.06 0.01 6.0 0.0

Watch out

The analysis must follow the design, not the reverse. A case-control study cannot hand you a risk or a prevalence, whatever function you call, because the disease totals were set by you. A cross-sectional survey cannot hand you an incidence rate, because it never watched anyone over time. If the measure you want is not in the design's row of the grid, the answer is a different study, not a different command.

Common mistakes

  • Quoting a risk or risk ratio from a case-control study. Sampling on outcome fixes the case-to-control ratio, so any absolute risk reflects your recruiting, not the population. Report the odds ratio, and note it approximates the risk ratio only when the disease is rare.
  • Reading incidence off a cross-sectional survey. A snapshot measures prevalence, which blends incidence with how long disease lasts. For the rate at which new cases arise, you need a cohort with person-time.
  • Significance-testing the baseline table of a trial. Randomization guarantees any baseline imbalance is chance, so a p-value tests a hypothesis already known to be true. Describe a few strong predictors instead and adjust only if one matters.
  • Analysing a matched case-control study as unmatched. Splitting the matched pairs discards the design and biases the odds ratio toward the null. Use conditional logistic regression or McNemar's test.
  • Collapsing person-time data into a plain proportion. When follow-up varies between people, dividing events by headcount ignores time at risk. Count person-years and use a rate.

Tips

  • Write the design and the outcome type at the top of the analysis plan before choosing any function. Those two facts name the cell in the grid and the test follows.
  • For a rare disease, state plainly that the case-control odds ratio is standing in for the risk ratio, so readers interpret it correctly.
  • Use a stratified Mantel-Haenszel analysis when one categorical confounder needs adjusting and you want a transparent per-stratum table. Move to regression once confounders are many or continuous.
  • For person-time outcomes, record events and person-years per group, then a Poisson-based test, rather than reducing the data to a single proportion.
  • No analysis trick repairs a design that cannot estimate the measure you need. Note the limitation honestly and build it into the next study.

A double-blind randomized trial of a new antihypertensive finds the treatment group is, by chance, slightly older than the placebo group. How should the analyst handle age?

  • Treat the imbalance as the expected play of chance, and adjust for age only if it strongly predicts the outcome and the adjustment was pre-specified.
  • Run a significance test on the age difference and adjust only if the p-value is below 0.05.
  • Drop the oldest treatment patients until the two groups match on mean age.
Randomization makes any baseline imbalance chance by construction, so testing it answers a settled question, and selecting the adjustment from that p-value invites bias. Dropping patients breaks the randomization and the intention-to-treat principle. The defensible move is to pre-specify adjustment for strong outcome predictors and otherwise report the simple comparison, since the design already balances confounders in expectation.
← PreviousBayesian statisticsNext →Sample size and power
On this page
  • The four designs in brief
  • Matching the measure to the design
  • Outcome type and design together pick the method
  • Two ways to handle confounding: design or analysis
  • Stratified analysis or a regression model?
  • Worked example 1: a case-control study, odds ratio and chi-squared
  • Worked example 2: a cohort with person-time, the rate ratio
  • Common mistakes
  • Tips