initial commit
This commit is contained in:
commit
352c2f87c5
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
.gitignore
|
||||
responses.csv
|
3
.idea/.gitignore
generated
vendored
Normal file
3
.idea/.gitignore
generated
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
6
.idea/inspectionProfiles/profiles_settings.xml
generated
Normal file
6
.idea/inspectionProfiles/profiles_settings.xml
generated
Normal file
@ -0,0 +1,6 @@
|
||||
<component name="InspectionProjectProfileManager">
|
||||
<settings>
|
||||
<option name="USE_PROJECT_PROFILE" value="false" />
|
||||
<version value="1.0" />
|
||||
</settings>
|
||||
</component>
|
8
.idea/modules.xml
generated
Normal file
8
.idea/modules.xml
generated
Normal file
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/stereotypes.iml" filepath="$PROJECT_DIR$/.idea/stereotypes.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
9
main.py
Normal file
9
main.py
Normal file
@ -0,0 +1,9 @@
|
||||
import phi_star
|
||||
import csv
|
||||
|
||||
if __name__ == '__main__':
|
||||
with open("responses.csv", encoding="utf-8") as file:
|
||||
reader = csv.reader(file)
|
||||
for row in reader:
|
||||
print(row)
|
||||
print(phi_star.calculate_phi_star([[1, 1], [1, 1]]))
|
46
phi_star.py
Normal file
46
phi_star.py
Normal file
@ -0,0 +1,46 @@
|
||||
import math
|
||||
|
||||
def calculate_phi_star(table):
|
||||
"""
|
||||
Вычисляет эмпирическое значение φ* по 2x2 таблице сопряжённости.
|
||||
|
||||
Параметры:
|
||||
table: Список списков 2x2, где
|
||||
table[0][0] — количество «есть эффект» в группе 1,
|
||||
table[0][1] — количество «нет эффекта» в группе 1,
|
||||
table[1][0] — количество «есть эффект» в группе 2,
|
||||
table[1][1] — количество «нет эффекта» в группе 2.
|
||||
|
||||
Возвращает:
|
||||
phi_star — рассчитанное значение φ*,
|
||||
"""
|
||||
# Извлекаем данные из таблицы
|
||||
group1_ef = table[0][0]
|
||||
group1_ne = table[0][1]
|
||||
group2_ef = table[1][0]
|
||||
group2_ne = table[1][1]
|
||||
|
||||
# Суммарные значения по группам
|
||||
total_group1 = group1_ef + group1_ne
|
||||
total_group2 = group2_ef + group2_ne
|
||||
total = total_group1 + total_group2
|
||||
|
||||
# Суммы по столбцам (категориям)
|
||||
total_ef = group1_ef + group2_ef
|
||||
total_ne = group1_ne + group2_ne
|
||||
|
||||
# Вычисляем ожидаемые частоты для каждой категории
|
||||
expected_group1_ef = total_group1 * total_ef / total
|
||||
expected_group1_ne = total_group1 * total_ne / total
|
||||
expected_group2_ef = total_group2 * total_ef / total
|
||||
expected_group2_ne = total_group2 * total_ne / total
|
||||
|
||||
# Вычисляем вклад по каждому элементу (χ²)
|
||||
chi_squared_1 = ((group1_ef - expected_group1_ef) ** 2 / expected_group1_ef) + \
|
||||
((group1_ne - expected_group1_ne) ** 2 / expected_group1_ne)
|
||||
|
||||
chi_squared_2 = ((group2_ef - expected_group2_ef) ** 2 / expected_group2_ef) + \
|
||||
((group2_ne - expected_group2_ne) ** 2 / expected_group2_ne)
|
||||
|
||||
# Вычисляем φ*
|
||||
return math.sqrt(chi_squared_1 + chi_squared_2)
|
Loading…
x
Reference in New Issue
Block a user