Home Python C Language C ++ HTML 5 CSS Javascript Java Kotlin SQL DJango Bootstrap React.js R C# PHP ASP.Net Numpy Dart Pandas Digital Marketing

Learn Statistics Estimating Population Means



A population proportion is the share of a population that belongs to a particular category.

Confidence intervals are used to estimate population proportions.



Estimating Population Proportions


A statistic from a sample is used to estimate a parameter of the population.

The most likely value for a parameter is the point estimate.

Additionally, we can calculate a lower bound and an upper bound for the estimated parameter.

The margin of error is the difference between the lower and upper bounds from the point estimate.

Together, the lower and upper bounds define a confidence interval.




Calculating a Confidence Interval


The following steps are used to calculate a confidence interval:


  1. Check the conditions
  2. Find the point estimate
  3. Decide the confidence level
  4. Calculate the margin of error
  5. Calculate the confidence interval

For example:



We can take a sample and see how many of them were born in the US.

The sample data is used to make an estimation of the share of all the Nobel Prize winners born in the US.

By randomly selecting 30 Nobel Prize winners we could find that:


6 out of 30 Nobel Prize winners in the sample were born in the US

From this data we can calculate a confidence interval with the steps below.




Checking the Conditions


The conditions for calculating a confidence interval for a proportion are:



In our example, we randomly selected 6 people that were born in the US.

The rest were not born in the US, so there are 24 in the other category.

The conditions are fulfilled in this case


Note: It is possible to calculate a confidence interval without having 5 of each category. But special adjustments need to be made.



Finding the Point Estimate


Learn Statistics Estimating Population Proportions



Deciding the Confidence Level


Learn Statistics Estimating Population Proportions

Note: A 95% confidence level means that if we take 100 different samples and make confidence intervals for each:

The true parameter will be inside the confidence interval 95 out of those 100 times.


We use the standard normal distribution to find the margin of error for the confidence interval.

The remaining probabilities (α) are divided in two so that half is in each tail area of the distribution.

The values on the z-value axis that separate the tails area from the middle are called critical z-values.

Below are graphs of the standard normal distribution showing the tail areas (α) for different confidence levels.


Learn Statistics Estimating Population Proportions



Calculating the Margin of Error


The margin of error is the difference between the point estimate and the lower and upper bounds.

The margin of error (E) for a proportion is calculated with a critical z-value and the standard error:


Learn Statistics Estimating Population Proportions

Example

With Python use the Scipy Stats library norm.ppf() function find the Z-value for an /2 = 0.025


import scipy.stats as stats
print(stats.norm.ppf(1-0.025))


Example

With R use the built-in qnorm() function to find the Z-value for an /2 = 0.025


qnorm(1-0.025)

Learn Statistics Estimating Population Proportions



Calculate the Confidence Interval


Learn Statistics Estimating Population Proportions

The 95% confidence interval for the proportion of Nobel Prize winners born in the US is between 5.7% and 34.4%


Calculating a Confidence Interval with Programming

A confidence interval can be calculated with many programming languages.

Using software and programming to calculate statistics is more common for bigger sets of data, as calculating manually becomes difficult.


Example

With Python, use the scipy and math libraries to calculate the confidence interval for an estimated proportion. Here, the sample size is 30 and the occurrences is 6.


import scipy.stats as stats
import math

# Specify sample occurrences (x), sample size (n) and confidence level
x = 6
n = 30
confidence_level = 0.95

# Calculate the point estimate, alpha, the critical z-value, the standard error, and the margin of error
point_estimate = x/n
alpha = (1-confidence_level)
critical_z = stats.norm.ppf(1-alpha/2)
standard_error = math.sqrt((point_estimate*(1-point_estimate)/n))
margin_of_error = critical_z * standard_error

# Calculate the lower and upper bound of the confidence interval
lower_bound = point_estimate - margin_of_error
upper_bound = point_estimate + margin_of_error

# Print the results
print("Point Estimate: {:.3f}".format(point_estimate))
print("Critical Z-value: {:.3f}".format(critical_z))
print("Margin of Error: {:.3f}".format(margin_of_error))
print("Confidence Interval: [{:.3f},{:.3f}]".format(lower_bound,upper_bound))
print("The {:.1%} confidence interval for the population proportion is:".format(confidence_level))
print("between {:.3f} and {:.3f}".format(lower_bound,upper_bound))


Example

With R, use the built-in math and statistics functions to calculate the confidence interval for an estimated proportion. Here, the sample size is 30 and the occurrences is 6.


# Specify sample occurrences (x), sample size (n) and confidence level
x = 6
n = 30
confidence_level = 0.95

# Calculate the point estimate, alpha, the critical z-value, the standard error, and the margin of error
point_estimate = x/n
alpha = (1-confidence_level)
critical_z = qnorm(1-alpha/2)
standard_error = sqrt(point_estimate*(1-point_estimate)/n)
margin_of_error = critical_z * standard_error

# Calculate the lower and upper bound of the confidence interval
lower_bound = point_estimate - margin_of_error
upper_bound = point_estimate + margin_of_error

# Print the results
sprintf("Point Estimate: %0.3f", point_estimate)
sprintf("Critical Z-value: %0.3f", critical_z)
sprintf("Margin of Error: %0.3f", margin_of_error)
sprintf("Confidence Interval: [%0.3f,%0.3f]", lower_bound, upper_bound)
sprintf("The %0.1f%% confidence interval for the population proportion is:", confidence_level*100)
sprintf("between %0.4f and %0.4f", lower_bound, upper_bound)


Note: R also has a built in function for calculating a confidence interval for a population mean.


Example

R can use the built-in t.test() function to calculate the confidence interval for an estimated mean. Here, the sample is 30 randomly generated values with a mean of 60 and standard deviation is 12.5 using the rnorm() function to generate the sample.


# Specify sample size (n) and confidence level
n = 30
confidence_level = 0.95

# Set random seed and generate sample data with mean of 60 and standard deviation of 12.5
set.seed(3)
sample <- rnorm(n, 6012.5)

# t.test function for sample data, confidence level, and selecting the $conf.int option
t.test(sample, conf.level = confidence_level)$conf.int



Advertisement





Q3 Schools : India


Online Complier

HTML 5

Python

java

C++

C

JavaScript

Website Development

HTML

CSS

JavaScript

Python

SQL

Campus Learning

C

C#

java