Published and tested 22 November 2026.
Which code change produces this result?
equal-size design effect is 1+(m−1)ρ; n=100,m=5,ρ=0.25 gives effect 2 and effective n=50. I use the 101 rows in data.csv in their original order.
This article uses simulated example data.


What changes in the actual output?
I get 50 for cluster effective n from the expression 100/(1+4*.25).
| intracluster_correlation | design_effect | effective_n |
|---|---|---|
| 0.0 | 1.0 | 100.0 |
| 0.01 | 1.04 | 96.15384615384615 |
| 0.02 | 1.08 | 92.59259259259258 |
| 0.03 | 1.12 | 89.28571428571428 |
| 0.04 | 1.16 | 86.20689655172414 |
| 0.05 | 1.2 | 83.33333333333334 |
| 0.06 | 1.24 | 80.64516129032258 |
| 0.07 | 1.28 | 78.125 |
| 0.08 | 1.32 | 75.75757575757575 |
| 0.09 | 1.3599999999999999 | 73.52941176470588 |
| 0.1 | 1.4 | 71.42857142857143 |
| 0.11 | 1.44 | 69.44444444444444 |
The table shows the first 12 rows; the CSV contains all rows. (101)
What should I check before using this setting?
This approximation assumes equal cluster size and a common intracluster correlation; unequal clusters need more care.
How can I reproduce the figures?
Run python example.py in a writable folder. Tested with Python 3.12.4, Matplotlib 3.8.4 and NumPy 1.26.4. The script writes data.csv, before.png, after.png and after.pdf beside itself.
These are the code, data and result files used in this article. Choose a file below to run the example or compare your results.
- example.pyComplete example code to run on your computer.
- data.csvThe input data used in the example; open it as a table.
- before.pngThe figure before the change, for comparison.
- after.pngThe figure after applying the settings in this article.
- after.pdfThe result in PDF format, for viewing and page layout.
- Usage license · LICENSE.txtTerms for reusing the code, data and figures, with source and font notices.
File verification
- hashes.jsonChecksums for checking whether the downloaded files are complete.
Complete Python code
# Original Bopbun example code and synthetic input: CC0-1.0.
# Python 3.12.4, NumPy 1.26.4, Matplotlib 3.8.4. See LICENSE.txt for font rights.
from pathlib import Path
import csv,json,math,itertools
import numpy as np
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
from matplotlib import colors,patches
OUT=Path(__file__).resolve().parent
plt.rcdefaults()
plt.rcParams.update({'font.family':'DejaVu Sans','font.size':11,'figure.dpi':120,'savefig.dpi':160,'pdf.fonttype':42})
def pair():
f0,a0=plt.subplots(figsize=(7.2,4.5),layout='constrained')
f1,a1=plt.subplots(figsize=(7.2,4.5),layout='constrained')
return f0,a0,f1,a1
def data_file(names,rows):
with (OUT/'data.csv').open('w',newline='',encoding='utf-8') as f:
w=csv.writer(f);w.writerow(names);w.writerows(rows)
before,a0,after,ax=pair()
rho=np.linspace(0,1,101);de=1+4*rho;neff=100/de;data_file(['intracluster_correlation','design_effect','effective_n'],zip(rho,de,neff));a0.plot(rho,de);a0.set(xlabel='Intracluster correlation',ylabel='Design effect',title='Five observations per equal-size cluster')
ax.plot(rho,neff);ax.plot([.25],[50],'ro');ax.set(xlabel='Intracluster correlation',ylabel='Effective sample size approximation',title='100 correlated observations can carry less information');metric=100/(1+4*.25)
before.savefig(OUT/'before.png')
after.savefig(OUT/'after.png')
after.savefig(OUT/'after.pdf',metadata={'CreationDate':None,'ModDate':None})
after.canvas.draw()
print(json.dumps({'metric':float(metric),'axes':len(after.axes),'beforeTitle':a0.get_title(),'afterTitle':ax.get_title(),'afterXLabel':ax.get_xlabel(),'afterYLabel':ax.get_ylabel(),'inputRows':sum(1 for _ in (OUT/'data.csv').open())-1}))
plt.close('all')
Which sources and licenses apply?
Original code and data: CC0-1.0. Figures use DejaVu Sans; its font license remains separate. Install Matplotlib and NumPy locally to run the code.
Learn R

