Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

2/2/23, 6:38 PM BDA LAB 2.

ipynb - Colaboratory

import numpy as np
from scipy import stats
import pandas as pd
pd.options.display.float_format = '{:,.4f}'.format

import os
for dirname, _, filenames in os.walk('/kaggle/input'):
  for filename in filenames:
    print(os.path.join(dirname, filename))

def check_normality(data):
  test_stat_normality, p_value_normality=stats.shapiro(data)
  print("p value:%.4f" % p_value_normality)
  if p_value_normality <0.05:
    print("Reject null hypothesis >> The data is not normally distributed")
  else:
    print("Fail to reject null hypothesis >> The data is normally distributed")

def check_variance_homogeneity(group1, group2):
  test_stat_var, p_value_var= stats.levene(group1,group2)
  print("p value:%.4f" % p_value_var)
  if p_value_var <0.05:
    print("Reject null hypothesis >> The variances of the samples are different.")
  else:
    print("Fail to reject null hypothesis >> The variances of the samples are same.")

sync = np.array([94. , 84.9, 82.6, 69.5, 80.1, 79.6, 81.4, 77.8, 81.7, 78.8, 73.2,
87.9, 87.9, 93.5, 82.3, 79.3, 78.3, 71.6, 88.6, 74.6, 74.1, 80.6])
asyncr =np.array([77.1, 71.7, 91. , 72.2, 74.8, 85.1, 67.6, 69.9, 75.3, 71.7,65.7, 72.6, 71.5, 78.2])

check_normality(sync)
check_normality(asyncr)

p value:0.6556
Fail to reject null hypothesis >> The data is normally distributed
p value:0.0803
Fail to reject null hypothesis >> The data is normally distributed

check_variance_homogeneity(sync, asyncr)

p value:0.8149
Fail to reject null hypothesis >> The variances of the samples are same.

P Value

ttest,p_value = stats.ttest_ind(sync,asyncr)
print("p value:%.8f" % p_value)
print("since the hypothesis is one sided >> use p_value/2 >> p_value_one_sided %.4f" %(p_value/2))
if p_value/2 <0.05:
  print("Reject null hypothesis")
else:
  print("Fail to reject null hypothesis")

p value:0.00753598
since the hypothesis is one sided >> use p_value/2 >> p_value_one_sided 0.0038
Reject null hypothesis

Z Score

import scipy.stats as st
S =st.norm.cdf(p_value)
print("The Z score is:", S)

The Z score is: 0.5030063943219184

https://colab.research.google.com/drive/1YTSiV3yZWj2Zth7UWZONA4dU3MxEOnPa#scrollTo=H1XwQ4cOPSm2&printMode=true 1/2
2/2/23, 6:38 PM BDA LAB 2.ipynb - Colaboratory

check 0s completed at 6:37 PM

https://colab.research.google.com/drive/1YTSiV3yZWj2Zth7UWZONA4dU3MxEOnPa#scrollTo=H1XwQ4cOPSm2&printMode=true 2/2

You might also like