{"id":14066992,"url":"https://github.com/ketchbrookanalytics/migrate","last_synced_at":"2025-10-22T03:56:17.825Z","repository":{"id":56022515,"uuid":"313478914","full_name":"ketchbrookanalytics/migrate","owner":"ketchbrookanalytics","description":"An R package for building state transition matrices","archived":false,"fork":false,"pushed_at":"2024-07-10T19:51:53.000Z","size":4155,"stargazers_count":7,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-10-22T03:56:05.103Z","etag":null,"topics":["credit-risk","finance","risk-management","rstats-package"],"latest_commit_sha":null,"homepage":"https://ketchbrookanalytics.github.io/migrate/","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/ketchbrookanalytics.png","metadata":{"files":{"readme":"README.Rmd","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":"2020-11-17T01:58:05.000Z","updated_at":"2025-10-06T09:33:57.000Z","dependencies_parsed_at":"2024-06-25T17:30:24.283Z","dependency_job_id":"d9c1062b-e33c-4d26-a967-5d1f23f7fa27","html_url":"https://github.com/ketchbrookanalytics/migrate","commit_stats":{"total_commits":71,"total_committers":2,"mean_commits":35.5,"dds":0.3380281690140845,"last_synced_commit":"17da3d127e2cdde572f27813dd49ee8f47ebdcd8"},"previous_names":["mthomas-ketchbrook/migrate"],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/ketchbrookanalytics/migrate","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ketchbrookanalytics%2Fmigrate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ketchbrookanalytics%2Fmigrate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ketchbrookanalytics%2Fmigrate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ketchbrookanalytics%2Fmigrate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ketchbrookanalytics","download_url":"https://codeload.github.com/ketchbrookanalytics/migrate/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ketchbrookanalytics%2Fmigrate/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":280376547,"owners_count":26320275,"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","status":"online","status_checked_at":"2025-10-22T02:00:06.515Z","response_time":63,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["credit-risk","finance","risk-management","rstats-package"],"created_at":"2024-08-13T07:05:22.215Z","updated_at":"2025-10-22T03:56:17.795Z","avatar_url":"https://github.com/ketchbrookanalytics.png","language":"R","funding_links":[],"categories":["R"],"sub_categories":[],"readme":"---\noutput: github_document\n---\n\n\u003c!-- README.md is generated from README.Rmd. Please edit that file --\u003e\n\n```{r, include = FALSE}\noptions(width = 999)\n\nknitr::opts_chunk$set(\n  collapse = TRUE,\n  comment = \"#\u003e\",\n  fig.path = \"man/figures/README-\",\n  out.width = \"100%\"\n)\n\ndevtools::load_all()\n```\n\n# migrate \u003cimg src='man/figures/logo.png' align=\"right\" height=\"200\" /\u003e\n\n\u003c!-- badges: start --\u003e\n[![lifecycle](https://img.shields.io/badge/lifecycle-stable-green.svg)](https://lifecycle.r-lib.org/articles/stages.html#stable)\n[![CRAN status](https://www.r-pkg.org/badges/version/migrate)](https://CRAN.R-project.org/package=migrate)\n[![metacran downloads](https://cranlogs.r-pkg.org/badges/migrate)](https://cran.r-project.org/package=migrate)\n[![R-CMD-check](https://github.com/ketchbrookanalytics/migrate/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/ketchbrookanalytics/migrate/actions/workflows/R-CMD-check.yaml)\n\u003c!-- badges: end --\u003e\n\nThe goal of {migrate} is to provide users with an easy set of tools for building *state transition matrices*.\n\n\u003cbr\u003e\n\n![](man/figures/gt_tbl.png)\n\n## Methodology\n\n{migrate} provides an easy way to calculate absolute or percentage migration within a credit portfolio. The above image shows a typical credit migration matrix using the *absolute* approach; each cell in the grid represents the total balance in the portfolio at 2020-06-30 that started at the Risk Rating represented on the left-hand vertical axis and ended (at 2020-09-30) at the Risk Rating represented on the upper horizontal axis of the matrix. For example, $6.58M moved from a Risk Rating **AAA** at 2020-06-30 to a Risk Rating **AA** at 2020-09-30.\n\nWhile the above, *absolute*, migration example is typically more of a reporting function, the *percentage* (or probabilistic) methodology is often more of a statistical modeling exercise, often used in credit portfolio risk management. Currently, this package only supports the simple \"cohort\" methodology. This estimates the probability of moving from state *i* to state *j* in a single time step, echoing a Markov process. We can visualize this in a matrix, for a credit portfolio with *N* unique, ordinal states:\n\n![](man/figures/markov_matrix.png)\n\n### Future Plans for {migrate}\n\nFuture development plans for this package include building functionality for the more complex **duration**/**hazard** methodology, including both the *time-homogeneous* and *non-homogeneous* implementations.\n\n## Installation\n\nYou can install the released version of {migrate} from [CRAN](https://CRAN.R-project.org) with:\n\n``` {r, eval = FALSE}\ninstall.packages(\"migrate\")\n```\n\nAnd the development version from [GitHub](https://github.com/) with:\n\n``` {r, eval = FALSE}\n# install.packages(\"devtools\")\ndevtools::install_github(\"ketchbrookanalytics/migrate\")\n```\n\n## Practical Usage\n\n{migrate} currently only handles transitions between exactly two (2) timepoints. Under the hood, `migrate()` finds the earliest \u0026 latest dates in the given *time* variable, and filters out any observations where the *time* value does not match those two dates.\n\nIf you are writing a SQL query to get data to be used with `migrate()`, the query would likely look something like this:\n\n```{r, eval = FALSE}\n# -- Get the *State* risk status and *Balance* dollar amount for each ID, at two distinct dates\n\n# SELECT ID, Date, State, Balance\n# FROM my_database\n# WHERE Date IN ('2020-12-31', '2021-06-30')\n```\n\nBy default, `migrate()` drops observations that belong to IDs found at a single timepoint. However, users can define a *filler state* so that IDs with a single timepoint are not removed but rather migrated from or to this *filler state*. This allows for more flexible handling of such data, ensuring that no information is lost during the migration process. Check [Handle IDs with observations at a single timepoint](https://ketchbrookanalytics.github.io/migrate/articles/migrate.html#handle-ids-with-observations-at-a-single-timepoint) for more information.\n\n## Example\n\nFirst, load the package using `library()`\n\n```{r load, eval = FALSE}\nlibrary(migrate)\n```\n\nThe package has a built-in mock dataset, which can be loaded into the environment like so:\n\n```{r data, eval = FALSE}\ndata(\"mock_credit\")\n\nhead(mock_credit[order(mock_credit$customer_id), ])   # sort by 'customer_id'\n```\n\n```{r data_tbl, echo = FALSE}\nhead(mock_credit[order(mock_credit$customer_id), ]) |\u003e\n  knitr::kable(row.names = FALSE)\n```\n\nNote that an important feature of the `mock_credit` dataset is that there are exactly two (2) unique values in the `date` column variable; if the `time` argument passed to `migrate()` has more than two (2) unique values, the function will throw an error.\n\n```{r dates}\nunique(mock_credit$date)\n```\n\nTo summarize the migration within the data, use the `migrate()` function\n\n```{r migrate}\nmigrated_df \u003c- migrate(\n  data = mock_credit,\n  id = customer_id,\n  time = date,\n  state = risk_rating,\n)\nhead(migrated_df)\n```\n\nTo create the state transition matrix, use the `build_matrix()` function\n```{r matrix}\nbuild_matrix(migrated_df)\n```\n\nOr, to do it all in one shot, use the `|\u003e`\n```{r pipe}\nmock_credit |\u003e\n  migrate(\n    id = customer_id,\n    time = date,\n    state = risk_rating,\n    metric = principal_balance,\n    percent = FALSE,\n    verbose = FALSE\n  ) |\u003e\n  build_matrix(\n    state_start = risk_rating_start,\n    state_end = risk_rating_end,\n    metric = principal_balance\n  )\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fketchbrookanalytics%2Fmigrate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fketchbrookanalytics%2Fmigrate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fketchbrookanalytics%2Fmigrate/lists"}