cardinal_pythonlib.psychiatry.treatment_resistant_depression


Original code copyright (C) 2009-2022 Rudolf Cardinal (rudolf@pobox.com).

This file is part of cardinal_pythonlib.

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.


Helper functions for algorithmic definitions of treatment-resistant depression.

Performance notes:

cardinal_pythonlib.psychiatry.treatment_resistant_depression.timedelta_days(days: int) timedelta64[source]

Convert a duration in days to a NumPy timedelta64 object.

cardinal_pythonlib.psychiatry.treatment_resistant_depression.two_antidepressant_episodes(patient_drug_date_df: DataFrame, patient_colname: str = 'patient_id', drug_colname: str = 'drug', date_colname: str = 'date', course_length_days: int = 28, expect_response_by_days: int = 56, symptom_assessment_time_days: int = 180, n_threads: int = 1, first_episode_only: bool = True) DataFrame[source]

Takes a pandas DataFrame, patient_drug_date_df (or, via reticulate, an R data.frame or data.table). This should contain dated present-tense references to antidepressant drugs (only).

Returns a set of result rows as a DataFrame.

cardinal_pythonlib.psychiatry.treatment_resistant_depression.two_antidepressant_episodes_single_patient(patient_id: str, patient_drug_date_df: DataFrame, patient_colname: str = 'patient_id', drug_colname: str = 'drug', date_colname: str = 'date', course_length_days: int = 28, expect_response_by_days: int = 56, symptom_assessment_time_days: int = 180, first_episode_only: bool = True) DataFrame | None[source]

Processes a single patient for two_antidepressant_episodes() (q.v.).

Implements the key algorithm.