Explore JCQ demand and control.

communication
junos 2021-07-05 18:32:35 +02:00
parent e2808422db
commit 8bf21ab272
2 changed files with 53 additions and 1 deletions

View File

@ -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,
)

View File

@ -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)