Preview:
Practical - 1
Test for single proportion using Python
1. In a survey of 600 persons 350 were found to be vegetarians. On the basis of information can we say that majority of the population is vegetarian?
  
Sol:
# Large sample test for single proportion

#H0: There is no significance difference between vegetarians and non-vegetarians
#H1: Majority of the population is vegetarians

import numpy as np
import pandas as pd
from statsmodels.stats.proportion import proportions_ztest

# Given,
significance = 0.05
sample_size = 600
no_of_vegitarians = 350
null_hypothesis = 0.5

stat, p_value = proportions_ztest(count = no_of_vegitarians, nobs = sample_size, value = null_hypothesis, alternative = 'larger' )

stat, p_value

(OR)

stat, p_value = proportions_ztest(count = 350, nobs = 600, value = 0.5, alternative = 'larger' )

stat, p_value

if p_value > 0.05:
print("Accept H0")
else:
print("Reject H0")
downloadDownload PNG downloadDownload JPEG downloadDownload SVG

Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!

Click to optimize width for Twitter