<jupyter_start><jupyter_text>Effects of Fitbit Monitored Activity on Evening MoodUsing the activity data to see the relationship with end-of-day mood<jupyter_code>import warnings
warnings.filterwarnings('ignore')

import pandas as pd
import numpy as np

from scipy import stats<jupyter_output><empty_output><jupyter_text>Data Import<jupyter_code>data = pd.read_csv("../data/interim/mood_prediction/fitbit-beiwe-activity-ema_evening.csv",index_col=0,parse_dates=["timestamp","date"],infer_datetime_format=True)
data.drop(["timestamp","redcap","beacon","date"],axis="columns",inplace=True)
data.head()<jupyter_output><empty_output><jupyter_text>Pre-Processing  Adding Step Goal<jupyter_code>data["step_goal"] = [1 if steps>10000 else 0 for steps in data["steps"]]<jupyter_output><empty_output><jupyter_text>Adding Discontent<jupyter_code>data["discontent"] = 3 - data["content"]<jupyter_output><empty_output><jupyter_text>Analyzing<jupyter_code>def compare_mood_scores(df_in,act_param="step_goal",moods=["discontent","stress","sad","lonely","energy"],f=np.nanmean):
    """
    Compares the mood scores between the extreme and non-extreme cases
    """
    df = df_in.copy()
    res = {"mean_low":[],"mean_high":[],"p":[]}
    
    high_steps = df[df[act_param] == 1]
    low_steps = df[df[act_param] == 0]
    print(f"High: \t{len(high_steps)}\nLow:\t{len(low_steps)}")
    
    for mood in moods:
        high_mean = round(np.nanmean(high_steps[mood]),2)
        low_mean = round(np.nanmean(low_steps[mood]),2)
        high_std = round(np.nanstd(high_steps[mood]),2)
        low_std = round(np.nanstd(low_steps[mood]),2)
        u, p = stats.mannwhitneyu(low_steps[mood].values,high_steps[mood].values)
        if p < 0.05:
            p = f"{round(p,3)}*"
        elif p < 0.1:
            p = f"{round(p,3)}**"
        else:
            p = f"{round(p,3)}"
        for key, val in zip(res.keys(),[(low_mean,low_std),(high_mean,high_std),p]):
            if len(val) == 2:
                res[key].append(f"{val[0]} ({val[1]})")
            else:
                res[key].append(val)
                
    Moods = [mood.title() for mood in moods]
    print(pd.DataFrame(data=res,index=Moods).to_latex())
compare_mood_scores(data)<jupyter_output>High: 	141
Low:	1858
\begin{tabular}{llll}
\toprule
{} &     mean\_low &    mean\_high &       p \\
\midrule
Discontent &  0.98 (0.83) &  0.79 (0.69) &  0.006* \\
Stress     &   0.85 (0.9) &  0.61 (0.72) &  0.003* \\
Sad        &   0.44 (0.7) &  0.27 (0.57) &  0.001* \\
Lonely     &  0.48 (0.75) &  0.48 (0.66) &   0.271 \\
Energy     &  1.98 (1.03) &  2.16 (0.98) &  0.038* \\
\bottomrule
\end{tabular}
{'fraction_non_alphanumeric': 0.1728954322385806, 'fraction_numerical': 0.04190260475651189, 'mean_word_length': 3.537671232876712, 'pattern_counts': {'":': 3, '<': 22, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '655037', 'license': 'MIT', 'n_tokens_mistral': 1093, 'n_tokens_neox': 1030, 'n_words': 163, 'path': 'notebooks/4.9.7-hef-fitbit_beiwe-activity_on_mood.ipynb', 'repo_name': 'intelligent-environments-lab/utx000', 'size': '2649'}