Last active
September 8, 2021 00:04
-
-
Save MohamedKari/ef826d72e188ea0f2b41f35dee453951 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# TODO: refactor for future usage | |
# TODO: Bonferroni-correct for number of questions | |
import pandas as pd | |
import scikit_posthocs as sp | |
import statsmodels.api as sa | |
def load_questionnaire(): | |
q = pd.read_csv("questionnaire.csv", delimiter=";") | |
q = q.melt(id_vars=["Technique", "QuestionId"], value_vars=[f"P{i}" for i in range(1, 13)], var_name="ParticipantId", value_name="Response") | |
return q | |
def test_question(question_id, questionnaire): | |
q_samples = questionnaire[questionnaire["QuestionId"] == question_id] | |
test_result = sp.posthoc_wilcoxon(q_samples, val_col="Response", group_col="Technique", p_adjust="bonferroni") | |
return pd.DataFrame(test_result) | |
def test_all_questions(alpha): | |
questionnaire = load_questionnaire() | |
interesting_questions = {} | |
for q_id in questionnaire["QuestionId"].unique(): | |
test_result = test_question(q_id, questionnaire) | |
if True in (test_result < alpha).values: | |
interesting_questions[q_id] = test_result | |
return interesting_questions | |
q = load_questionnaire() | |
qs = test_all_questions(alpha=.05) | |
qs | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment