Lawfare Group → Knowledge Institute → Lawfare Academy

Reproduce the worked examples

Copy the complete code below into a UTF-8 file named verify.py and run python verify.py with Python 3. It uses only the standard library and performs exact or rational synthetic calculations. It does not access a network or learner records. Assertions fail if the expected synthetic results change.

These checks verify the stated arithmetic and query behavior, not independent academic acceptance or production migration safety.

"""Known-variance synthetic study; no network or learner records."""
import math,json,statistics
def main():
 se=math.sqrt(25/100+25/100);z=4/se;p=math.erfc(abs(z)/math.sqrt(2));critical=statistics.NormalDist().inv_cdf(1-.05/40)
 ordinary=[4-1.96*se,4+1.96*se];simultaneous=[4-critical*se,4+critical*se]
 assert ordinary[0]>0 and ordinary[0]<3 and ordinary[1]>5
 assert simultaneous[0]>0 and simultaneous[0]<3 and simultaneous[1]>6
 assert abs(p-1.541725790028e-8)<1e-18
 design_effect=1+19*.1;scaled=se*math.sqrt(design_effect)
 assert abs(scaled-1.20415945787923)<1e-12
 x=[1,2,3,4];y=[3,5,7,9];xb=statistics.mean(x);yb=statistics.mean(y)
 sxx=sum((v-xb)**2 for v in x);sxy=sum((a-xb)*(b-yb) for a,b in zip(x,y));slope=sxy/sxx;intercept=yb-slope*xb
 assert (sxx,sxy,slope,intercept)==(5,10,2,1)
 result=dict(passed=True,standardError=se,z=z,pValue=p,ordinaryInterval=ordinary,simultaneousInterval=simultaneous,designEffect=design_effect,illustrativeClusterScale=scaled,slope=slope,intercept=intercept,limits="Clustering result is a design-effect sensitivity, not a valid small-cluster trial interval. Exact observational fit is not causal evidence.")
 print(json.dumps(result,indent=2));return result
if __name__=='__main__':main()

Related chapters