Skip to content

Instantly share code, notes, and snippets.

@MohamedKari
Last active September 8, 2021 00:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MohamedKari/ef826d72e188ea0f2b41f35dee453951 to your computer and use it in GitHub Desktop.
Save MohamedKari/ef826d72e188ea0f2b41f35dee453951 to your computer and use it in GitHub Desktop.
# 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