47 lines
1.3 KiB
Python
47 lines
1.3 KiB
Python
|
|
import scipy.stats
|
||
|
|
import pandas as pd
|
||
|
|
import os
|
||
|
|
import numpy as np
|
||
|
|
import matplotlib.pyplot as plt
|
||
|
|
|
||
|
|
curdir = os.getcwd()
|
||
|
|
path_delim = '/'
|
||
|
|
df = pd.read_excel(curdir + path_delim + "data/tests_28_10_2023_19_16.xlsx", sheet_name="data")
|
||
|
|
|
||
|
|
df = df[["calculatedRatio", "deviceRatio", "led1Average", "led1Buffer", "led1Sample", "led2Average", "led2Buffer", "led2Sample"]]
|
||
|
|
# print(df.to_numpy())
|
||
|
|
|
||
|
|
# # Contingency table
|
||
|
|
# observed = [
|
||
|
|
# [25, 15, 10],
|
||
|
|
# [10, 20, 15],
|
||
|
|
# [15, 10, 20]
|
||
|
|
# ]
|
||
|
|
|
||
|
|
observed = df
|
||
|
|
# # Perform the chi-square test for independence
|
||
|
|
chi2, p, dof, expected = scipy.stats.chi2_contingency(observed)
|
||
|
|
|
||
|
|
print(f"Chi-square statistic: {chi2}")
|
||
|
|
print(f"P-value: {p}")
|
||
|
|
print(f"Degrees of freedom: {dof}")
|
||
|
|
print("Expected frequencies:")
|
||
|
|
print(expected)
|
||
|
|
|
||
|
|
df['calculatedRatio'].plot.kde()
|
||
|
|
df['deviceRatio'].plot.kde()
|
||
|
|
# plt.legend(['calculatedRatio'])
|
||
|
|
plt.legend(["calculatedRatio", "deviceRatio"], loc ="upper right")
|
||
|
|
plt.show()
|
||
|
|
|
||
|
|
# Observed frequencies
|
||
|
|
observed = np.array(df['led1Buffer'].to_numpy())
|
||
|
|
|
||
|
|
# Expected frequencies
|
||
|
|
expected = np.array(df['led2Buffer'].to_numpy()) # Assuming equal expected frequencies
|
||
|
|
|
||
|
|
# Perform the chi-square goodness-of-fit test
|
||
|
|
chi2, p = scipy.stats.chisquare(observed, f_exp=expected)
|
||
|
|
|
||
|
|
print(f"Chi-square statistic: {chi2}")
|
||
|
|
print(f"P-value: {p}")
|