# -*- coding: utf-8 -*- """ Created on Thu Sep 2 15:55:14 2021 @author: Rene """ import pandas as pd import numpy as np from scipy.stats import t from scipy.stats import norm def get_conf_int_var_known(x,alpha,sigma): n = len(x) x_bar = np.mean(x) st_dev_x_bar = sigma/(n**0.5) half_width = norm.ppf(1-(alpha/2),0,1)*st_dev_x_bar bounds = np.zeros(2) bounds[0] = x_bar-half_width bounds[1] = x_bar+half_width return(bounds) def get_conf_int_var_unknown(x,alpha): n = len(x) x_bar = np.mean(x) st_dev_x_bar = np.std(x,ddof=1)/(n**0.5) half_width = t.ppf(1-(alpha/2),n-1)*st_dev_x_bar bounds = np.zeros(2) bounds[0] = x_bar-half_width bounds[1] = x_bar+half_width return(bounds) df = pd.read_csv('coal.csv') CalContent = df["Calorific Content"] alpha=0.05 the_sigma = 0.1 conf_bounds_known = get_conf_int_var_known(CalContent,alpha,the_sigma) print(conf_bounds_known) conf_bounds_unknown = get_conf_int_var_unknown(CalContent,alpha) print(conf_bounds_unknown)