Confidence Interval Calculator
Calculate confidence intervals for means and proportions.
Lower Bound
46.2718
Upper Bound
53.7282
Margin of Error
3.7282
Critical Value
2.0420
We are 95% confident that the true mean lies between 46.2718 and 53.7282.
Using t(29)-distribution · SE = 1.8257
About this tool
A confidence interval is a range of values that likely contains an unknown population parameter, such as the mean or proportion. Rather than guessing a single value, confidence intervals quantify uncertainty by showing a lower and upper bound, with a specified confidence level (typically 95%) that indicates how often the interval would capture the true value if repeated many times. This tool calculates confidence intervals for both population means and proportions, essential for anyone analyzing sample data in research, quality control, marketing, or scientific studies.
Using this calculator is straightforward: enter your sample data (sample mean or proportion, sample size, and standard deviation if calculating for means), select your confidence level, and the tool computes the margin of error and the resulting confidence interval bounds. For proportions, you only need the number of successes and total sample size. The results show exactly how confident you can be in your estimate, whether you're estimating average customer satisfaction, product defect rates, or average test scores from a sample.
Frequently Asked Questions
Code Implementation
import math
import scipy.stats as stats
import numpy as np
# --- Manual confidence interval for mean (known sigma) ---
def ci_mean_known_sigma(mean, sigma, n, confidence=0.95):
z = stats.norm.ppf((1 + confidence) / 2)
margin = z * (sigma / math.sqrt(n))
return mean - margin, mean + margin
lower, upper = ci_mean_known_sigma(50, 10, 100, 0.95)
print(f"95% CI: [{lower:.4f}, {upper:.4f}]")
# 95% CI: [48.0400, 51.9600]
# --- t-distribution CI (unknown sigma, from sample) ---
data = [52, 48, 55, 47, 50, 53, 49, 51, 46, 54]
mean = np.mean(data)
sem = stats.sem(data) # standard error of mean
ci = stats.t.interval(0.95, df=len(data)-1, loc=mean, scale=sem)
print(f"Mean: {mean:.2f}, 95% CI: [{ci[0]:.4f}, {ci[1]:.4f}]")
# --- Proportion confidence interval (Wilson score) ---
def ci_proportion(successes, n, confidence=0.95):
p = successes / n
z = stats.norm.ppf((1 + confidence) / 2)
center = (p + z**2/(2*n)) / (1 + z**2/n)
spread = z * math.sqrt(p*(1-p)/n + z**2/(4*n**2)) / (1 + z**2/n)
return center - spread, center + spread
lo, hi = ci_proportion(45, 100, 0.95)
print(f"Proportion CI: [{lo:.4f}, {hi:.4f}]")Comments & Feedback
Comments are powered by Giscus. Sign in with GitHub to leave a comment.