From 8bf21ab272a1dd9caeaeef9f21f61ff1dc80a415 Mon Sep 17 00:00:00 2001 From: junos Date: Mon, 5 Jul 2021 18:32:35 +0200 Subject: [PATCH] Explore JCQ demand and control. --- exploration/expl_esm_labels.py | 52 ++++++++++++++++++++++++++++++++++ features/esm_JCQ.py | 2 +- 2 files changed, 53 insertions(+), 1 deletion(-) diff --git a/exploration/expl_esm_labels.py b/exploration/expl_esm_labels.py index 5f7aa2f..487b5e1 100644 --- a/exploration/expl_esm_labels.py +++ b/exploration/expl_esm_labels.py @@ -1,3 +1,4 @@ +# -*- coding: utf-8 -*- # --- # jupyter: # jupytext: @@ -24,6 +25,7 @@ if nb_dir not in sys.path: sys.path.append(nb_dir) import participants.query_db from features.esm import * +from features.esm_JCQ import * # %% participants_inactive_usernames = participants.query_db.get_usernames( @@ -213,3 +215,53 @@ sns.displot(data=df_esm_SAM_period_summary_participant, x="mean", binwidth=0.2) # %% sns.displot(data=df_esm_SAM_period_summary_participant, x="std", binwidth=0.1) + +# %% [markdown] +# # Job demand and control + +# %% +df_esm_JCQ_demand_control = df_esm_preprocessed[ + (df_esm_preprocessed["questionnaire_id"] >= 10) + & (df_esm_preprocessed["questionnaire_id"] <= 11) +] +df_esm_JCQ_demand_control_clean = clean_up_esm(df_esm_JCQ_demand_control) + +# %% +df_esm_JCQ_demand_control_reversed = reverse_jcq_demand_control_scoring( + df_esm_JCQ_demand_control_clean +) + +# %% +df_esm_JCQ_daily = ( + df_esm_JCQ_demand_control_reversed.groupby( + ["participant_id", "date_lj", "questionnaire_id"] + ) + .esm_user_score.agg("mean") + .reset_index() + .rename(columns={"esm_user_score": "esm_score_mean"}) +) +df_esm_JCQ_summary_participant = ( + df_esm_JCQ_daily.groupby(["participant_id", "questionnaire_id"]) + .agg(["mean", "median", "std"]) + .reset_index(col_level=1) +) +df_esm_JCQ_summary_participant.columns = df_esm_JCQ_summary_participant.columns.get_level_values( + 1 +) +df_esm_JCQ_summary_participant[ + "JCQ_subscale" +] = df_esm_JCQ_summary_participant.questionnaire_id.astype( + "category" +).cat.rename_categories( + {10: "job demand", 11: "job control"} +) + +# %% +sns.displot( + data=df_esm_JCQ_summary_participant, x="mean", hue="JCQ_subscale", binwidth=0.1, +) + +# %% +sns.displot( + data=df_esm_JCQ_summary_participant, x="std", hue="JCQ_subscale", binwidth=0.05, +) diff --git a/features/esm_JCQ.py b/features/esm_JCQ.py index 3750a5d..88073ce 100644 --- a/features/esm_JCQ.py +++ b/features/esm_JCQ.py @@ -101,7 +101,7 @@ def reverse_jcq_demand_control_scoring( - x.esm_user_score ) # Reverse the items that require it. - except KeyError as e: + except AttributeError as e: print("Please, clean the dataframe first using features.esm.clean_up_esm.") print(e)