This repository contains the code for the project "Effect of acute psychosocial stress on body posture and movements".
This package contains various helper functions to work with the dataset
(including tpcp
Dataset
representations) and to process the recorded data.
Additionally, it contains analysis experiments performed with the dataset to reproduce all results, figures, etc.
The repository is structured as follows:
├── stresspose_analysis/ # `stresspose-analysis` Python package with helper functions
└── experiments/ # Folder with conducted analysis experiments; each experiment has its own subfolder
├── pilotstudy/ # Data Analysis for the Pilot Study
│ ├── feature_export/ # Exported motion features
│ ├── notebooks/ # Notebooks for data processing, data analysis, classification experiments, plotting, etc. in subfolders
│ ├── output/ # Output of classification experiments (pickled models, input features, etc.)
│ ├── params/ # Hyperparameter settings for classification experiments
│ ├── results/ # Analysis results
│ └── config.json/ # Config file containing location of dataset (ignored because path depend on local configurations)
└── mainstudy/ # Data Analysis for the Main Study
├── feature_export/ # Exported motion features
├── notebooks/ # Notebooks for data processing, data analysis, classification experiments, plotting, etc. in subfolders
├── output/ # Output of classification experiments (pickled models, input features, etc.)
├── params/ # Hyperparameter settings for classification experiments
├── results/ # Analysis results
├── scripts/ # Scripts for feature extraction and classification experiments
└── config.json/ # Config file containing location of dataset (ignored because path depend on local configurations)
In order to run the code, first download the desired dataset(s) from OSF:
Then, create a file named config.json
in the respective experiment
subfolders
(/experiments/pilotstudy
or /experiments/mainstudy
) folder with the following content:
{
"name-of-deployment <e.g., local>": {
"base_path": "<path-to-dataset>"
}
}
This config file is parsed by all notebooks to extract the path to the dataset.
NOTE: This file is ignored by git because the path to the dataset depends on the local configuration!
If you want to use this package to reproduce the analysis results the best way is to clone the repository and install the package via poetry. For that, open a terminal and run the following commands:
git clone [email protected]:empkins/stresspose-analysis.git
cd stresspose-analysis
poetry install # alternative: pip install .
This creates a new python venv in the stresspose-analysis/.venv
folder. Next, register a new IPython kernel for the
venv:
cd stresspose-analysis
poetry run poe register_ipykernel
Finally, go to the experiments
folder and run the Jupyter Notebooks to reproduce all data processing steps (see below).
This analysis was performed for the paper "Machine learning-based detection of acute psychosocial stress from body posture and movements", currently under review at Scientific Reports.
To run the data processing and analysis pipeline, we recommend executing the notebooks in the following order:
- Pilot Study:
- Data Processing and Feature Extraction:
- Motion Features: Run
data_processing/Motion_Data_Preprocessing.ipynb
->data_processing/Motion_Data_Feature_Extraction.ipynb
- Self-reports: Run
data_processing/Questionnaire_Processing.ipynb
- Saliva Data: Run
data_processing/Saliva_Processing.ipynb
- Motion Features: Run
- Classification Experiments: Run
classification/Classification_General.ipynb
andclassification/Classification_Talk.ipynb
- Data Analysis:
- Saliva Data: Run
stress_response/Saliva_Analysis.ipynb
- Self-reports: Run
stress_response/State_Questionnaire_Analysis.ipynb
- Motion Features (statistical): Run
motion_features/Motion_Feature_Overview.ipynb
andmotion_features/Motion_Feature_Analysis.ipynb
- Classification Results: Run
classification/Analysis_Classification_General.ipynb
andclassification/Analysis_Classification_Talk.ipynb
- Saliva Data: Run
- General Plots (plots used in papers, etc.): Run
plotting/Teaserfigure_Plots.ipynb
,plotting/Sensor_Grid_Plots.ipynb
, andplotting/Filter_Pipeline_Plots.ipynb
- Data Processing and Feature Extraction:
- Main Study:
- Data Processing and Feature Extraction:
- Motion Features: Run
movement_data/feature_extraction/Feature_Extraction.ipynb
andmovement_data/feature_extraction/Feature_Extraction_per_Phase.ipynb
(alternative: run the scriptsscripts/feature_extraction.py
andscripts/feature_extraction_per_phase.py
) - Self-reports: Run
questionnaires/Questionnaire_Processing.ipynb
- Saliva Data: Run
biomarker/Saliva_Processing.ipynb
- Motion Features: Run
- Classification Experiments: Run the scripts (not notebooks!)
scripts/classification.py
andscripts/classification_rf.py
. Due to the long runtime of the classification experiments, only a subset of classification pipeline permutations are executed in one script. Thus, the type of feature selection and scaler can be passed as environment variables. See the scripts for more information. - Data Analysis:
- Saliva Data: Run
analysis/stress_response/Saliva_Analysis.ipynb
- Self-reports: Run
analysis/stress_response/State_Questionnaire_Analysis.ipynb
- Motion Features (statistical): Run
analysis/movement_data/Movement_Feature_Overview.ipynb
,analysis/movement_data/Movement_Feature_Analysis.ipynb
, andanalysis/movement_data/Movement_Feature_Analysis_per_Phase.ipynb
- Classification Results: Run
analysis/classification/Analysis_Classification_General.ipynb
andanalysis/classification/Analysis_Classification_Per_Phase.ipynb
- Saliva Data: Run
- Data Processing and Feature Extraction: