Python for Introductory Statistics: Lab WorkbookXYZ Homework Edition

⇩ Download ▾

Margin of Error for Confidence Interval

from scipy import stats

Mean μ\mu with zz distribution with confidence level C, (population) standard deviation std and sample size n:

E = (std/n**.5)*stats.norm.ppf(C+(1-C)/2,0,1)

Mean μ\mu with tt distribution with confidence level C, sample standard deviation std and sample size n:

E = (std/n**.5)*stats.t.ppf(C+(1-C)/2,0,1)

Proportion pp with zz distribution with confidence level C, sample proportion p and sample size n:

E = (p(p*(1-p)/n)**.5)*stats.norm.ppf(C+(1-C)/2,0,1)

Adapted from Python for Introductory Statistics: Student's Lab Workbook, by Simon Aman (Truman College, City Colleges of Chicago), licensed under CC BY 4.0. Changes were made: reformatted as an accessible XYZ web edition with live in-browser code cells. License: CC-BY-4.0.

These eBooks are a prerelease and are not yet certified conformant with WCAG 2.1 AA or ADA Title II. Every page is built against an automated accessibility gate, and the published editions will meet ADA Title II requirements when they release in late September 2026. If something is unusable, please tell us.