Add SAM event and period analysis.
parent
48d7be780c
commit
e8005aadc6
|
@ -102,22 +102,114 @@ df_esm_SAM = df_esm_preprocessed[
|
|||
(df_esm_preprocessed["questionnaire_id"] >= 87)
|
||||
& (df_esm_preprocessed["questionnaire_id"] <= 93)
|
||||
]
|
||||
df_esm_SAM_clean = clean_up_esm(df_esm_SAM)
|
||||
|
||||
# %% [markdown]
|
||||
# ## Stressful events
|
||||
|
||||
# %%
|
||||
clean_up_esm(df_esm_SAM)[["esm_user_answer", "esm_user_answer_numeric"]].head(9)
|
||||
df_esm_SAM_event = df_esm_SAM_clean[df_esm_SAM_clean["questionnaire_id"] == 87].assign(
|
||||
stressful_event=lambda x: (x.esm_user_answer_numeric > 0)
|
||||
)
|
||||
|
||||
# %%
|
||||
df_esm_PANAS_clean[["esm_user_answer", "esm_user_answer_numeric"]].head(n=10)
|
||||
df_esm_SAM_daily_events = (
|
||||
df_esm_SAM_event.groupby(["participant_id", "date_lj"])
|
||||
.stressful_event.agg("mean")
|
||||
.reset_index()
|
||||
.rename(columns={"stressful_event": "SAM_event_ratio"})
|
||||
)
|
||||
|
||||
# %% [markdown]
|
||||
# Calculate the daily mean of YES (1) or NO (0) answers to the question about a stressful events. This is then the daily ratio of EMA sessions that included a stressful event.
|
||||
|
||||
# %%
|
||||
df_esm_SAM[
|
||||
[
|
||||
"esm_instructions",
|
||||
"question_id",
|
||||
"questionnaire_id",
|
||||
"esm_user_answer",
|
||||
"esm_type",
|
||||
df_esm_SAM_event_summary_participant = (
|
||||
df_esm_SAM_daily_events.groupby(["participant_id"])
|
||||
.agg(["mean", "median", "std"])
|
||||
.reset_index(col_level=1)
|
||||
)
|
||||
df_esm_SAM_event_summary_participant.columns = df_esm_SAM_event_summary_participant.columns.get_level_values(
|
||||
1
|
||||
)
|
||||
|
||||
# %%
|
||||
sns.displot(data=df_esm_SAM_event_summary_participant, x="mean", binwidth=0.1)
|
||||
|
||||
# %%
|
||||
sns.displot(data=df_esm_SAM_event_summary_participant, x="std", binwidth=0.05)
|
||||
|
||||
# %% [markdown]
|
||||
# ### Threat and challenge
|
||||
|
||||
# %% [markdown]
|
||||
# * Example of threat: "Did this event make you feel anxious?"
|
||||
# * Example of challenge: "How eager are you to tackle this event?"
|
||||
# * Possible answers: 0 - Not at all, 1 - Slightly, 2 - Moderately, 3 - Considerably, 4 - Extremely
|
||||
|
||||
# %%
|
||||
df_esm_SAM_daily = (
|
||||
df_esm_SAM_clean.groupby(["participant_id", "date_lj", "questionnaire_id"])
|
||||
.esm_user_answer_numeric.agg("mean")
|
||||
.reset_index()
|
||||
.rename(columns={"esm_user_answer_numeric": "esm_numeric_mean"})
|
||||
)
|
||||
|
||||
# %%
|
||||
df_esm_SAM_daily_threat_challenge = df_esm_SAM_daily[
|
||||
(df_esm_SAM_daily["questionnaire_id"] == 88)
|
||||
| (df_esm_SAM_daily["questionnaire_id"] == 89)
|
||||
]
|
||||
].head(n=10)
|
||||
|
||||
# %%
|
||||
df_esm_SAM_summary_participant = (
|
||||
df_esm_SAM_daily.groupby(["participant_id", "questionnaire_id"])
|
||||
.agg(["mean", "median", "std"])
|
||||
.reset_index(col_level=1)
|
||||
)
|
||||
df_esm_SAM_summary_participant.columns = df_esm_SAM_summary_participant.columns.get_level_values(
|
||||
1
|
||||
)
|
||||
|
||||
# %%
|
||||
df_esm_SAM_threat_challenge_summary_participant = df_esm_SAM_summary_participant[
|
||||
(df_esm_SAM_summary_participant["questionnaire_id"] == 88)
|
||||
| (df_esm_SAM_summary_participant["questionnaire_id"] == 89)
|
||||
]
|
||||
df_esm_SAM_threat_challenge_summary_participant[
|
||||
"event_subscale"
|
||||
] = df_esm_SAM_threat_challenge_summary_participant.questionnaire_id.astype(
|
||||
"category"
|
||||
).cat.rename_categories(
|
||||
{88: "threat", 89: "challenge"}
|
||||
)
|
||||
|
||||
# %%
|
||||
sns.displot(
|
||||
data=df_esm_SAM_threat_challenge_summary_participant,
|
||||
x="mean",
|
||||
hue="event_subscale",
|
||||
binwidth=0.2,
|
||||
)
|
||||
|
||||
# %%
|
||||
sns.displot(
|
||||
data=df_esm_SAM_threat_challenge_summary_participant,
|
||||
x="std",
|
||||
hue="event_subscale",
|
||||
binwidth=0.1,
|
||||
)
|
||||
|
||||
# %% [markdown]
|
||||
# ## Stressfulness of period
|
||||
|
||||
# %%
|
||||
df_esm_SAM_period_summary_participant = df_esm_SAM_summary_participant[
|
||||
df_esm_SAM_summary_participant["questionnaire_id"] == 93
|
||||
]
|
||||
|
||||
# %%
|
||||
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)
|
||||
|
|
Loading…
Reference in New Issue