{"id":26822659,"url":"https://github.com/dylanpieper/episodes","last_synced_at":"2025-03-30T08:20:09.920Z","repository":{"id":284241518,"uuid":"954297091","full_name":"dylanpieper/episodes","owner":"dylanpieper","description":"Time Series Segmentation for Longitudinal Data Analysis","archived":false,"fork":false,"pushed_at":"2025-03-24T22:09:06.000Z","size":0,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-24T22:29:20.533Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://dylanpieper.github.io/episodes/","language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dylanpieper.png","metadata":{"files":{"readme":"README.md","changelog":"NEWS.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-03-24T21:37:35.000Z","updated_at":"2025-03-24T22:06:18.000Z","dependencies_parsed_at":"2025-03-24T22:39:23.973Z","dependency_job_id":null,"html_url":"https://github.com/dylanpieper/episodes","commit_stats":null,"previous_names":["dylanpieper/episodes"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dylanpieper%2Fepisodes","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dylanpieper%2Fepisodes/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dylanpieper%2Fepisodes/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dylanpieper%2Fepisodes/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dylanpieper","download_url":"https://codeload.github.com/dylanpieper/episodes/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246291584,"owners_count":20753900,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-03-30T08:20:09.345Z","updated_at":"2025-03-30T08:20:09.902Z","avatar_url":"https://github.com/dylanpieper.png","language":"R","funding_links":[],"categories":[],"sub_categories":[],"readme":"# episodes \u003cimg src=\"man/figures/episodes-hex.svg\" align=\"right\" width=\"140\"/\u003e\n\n[![R-CMD-check](https://github.com/dylanpieper/episodes/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/dylanpieper/episodes/actions/workflows/R-CMD-check.yaml)\n\nSegment longitudinal data into meaningful episodes based on temporal gaps and variable changes. It's designed for analyzing treatment patterns, patient journeys, and other time series data where interruptions and changes in covariates are significant. This tool is useful for survival analyses and other time-varying statistical methods requiring structured temporal data.\n\nFeatures:\n\n-   Identify episodes based on gaps between dates\n-   Track how variables change within episodes\n-   Analyze continuation (i.e., retention) across episodes\n-   Support for grouped data workflows in the tidyverse style\n-   Track progress during long-running operations on large datasets\n\n## Installation\n\nFrom CRAN:\n\n``` r\ninstall.packages(\"episodes\")\n```\n\nDevelopment version:\n\n``` r\n# install.packages(\"pak\")\npak::pak(\"dylanpieper/episodes\")\n```\n\n## Basic Usage\n\n### Segmenting client treatment episodes\n\n``` r\nlibrary(episodes)\n\nepisodes \u003c- substance_use |\u003e\n  group_by(client_id) |\u003e\n  segment_episodes(\n    visit_date,\n    gap_threshold = 2,\n    gap_unit = \"months\"\n  )\n```\n\nAdditional fixed variables are included in the results, while varying variables are excluded. Use `segment_episodes_by_covars()` to track changes in specific variables.\n\n### Identifying active vs. inactive episodes\n\nBy default, `segment_episodes()` assigns the status of episodes as:\n\n-   **Active**: Recent episodes (based on `inactive_threshold`)\n-   **Inactive**: Episodes that ended before the inactive threshold\n-   **Gap**: Episodes that are followed by another episode\n\n``` r\nstatus_check \u003c- substance_use |\u003e\n  group_by(client_id) |\u003e\n  segment_episodes(\n    visit_date, \n    gap_threshold = 2, \n    gap_unit = \"months\",\n    inactive_threshold = 3,\n    inactive_unit = \"months\"\n  ) |\u003e\n  count(status)\n```\n\n### Including covariate changes\n\nTrack when important variables change within episodes using `segment_episodes_by_covars()`:\n\n``` r\nepisodes_by_covars \u003c- substance_use |\u003e\n  group_by(client_id) |\u003e\n  segment_episodes_by_covars(\n    visit_date,\n    covar_cols = c(\"substance_use_past_week\", \n                   \"quality_of_life_score\", \n                   \"medication_dose_mg\"),\n    gap_threshold = 2,\n    gap_unit = \"months\"\n  ) |\u003e\n  arrange(client_id, episode_id, segment_id)\n```\n\nAn additional status for **ongoing** episodes is included for the segmentation of episodes by changes in the covariates.\n\n### Analyzing continuation (i.e., retention)\n\nThe `split_episode()` function helps analyze whether episodes continue past specific time thresholds:\n\n``` r\nretention \u003c- episodes |\u003e\n  split_episode(\n    thresholds = c(30, 12, 6), \n    units = c(\"days\", \"weeks\", \"months\")\n  )\n```\n\nThe function adds columns for each threshold:\n\n-   `*_date`: The date corresponding to threshold after episode start\n-   `*_eligible`: Whether enough time has passed to evaluate this threshold\n-   `*_continued`: Whether the episode continued past this threshold\n\n## Dataset\n\nThe package includes a simulated substance use treatment dataset:\n\n``` r\nglimpse(substance_use)\n```\n\nRead more about how to use this data to run survival analyses using `vignette(\"survival\", package = \"episodes\")`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdylanpieper%2Fepisodes","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdylanpieper%2Fepisodes","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdylanpieper%2Fepisodes/lists"}