Learn R Programming

migrate (version 0.2.0)

build_matrix: Build a migration (transition) matrix

Description

`build_matrix()` creates a credit migration (i.e., "transition") matrix from summarized data representing each credit risk rating & a continuous metric at two distinct points in time.

Usage

build_matrix(data, rating_start = NULL, rating_end = NULL, metric = NULL)

Arguments

data

A data frame or data frame extension (e.g., a tibble or data.table) containing a minimum of three (3) column variables representing a starting credit risk rating, an ending credit risk rating, and a metric containing values representing the movement (i.e., "transition) in that metric between the starting credit risk rating point in time and the ending credit risk rating point in time. This style of data frame is output by the `migrate()` function also within this package.

rating_start

(Optional) A symbol or string, representing the column variable of the `data` data frame argument that contains the starting credit risk rating values. If left null, function will attempt to find it for you.

rating_end

(Optional) A symbol or string, representing the column variable of the `data` data frame argument that contains the starting credit risk rating values. If left null, function will attempt to find it for you.

metric

(Optional) A symbol or string, representing the column variable of the `data` data frame argument that contains the metric for which the grouped difference in value between the starting credit risk rating period and ending credit risk rating period was computed.

Value

A matrix object, where the first (row) dimension represents the starting credit risk rating, the second (column) dimension represents the ending credit risk rating, and the values within the matrix represent the transitioned amount based upon the values in the `metric` continuous column variable from the `data` data frame.

Note: A matrix object can be coerced to a data frame using `as.data.frame()`.

Examples

Run this code
# NOT RUN {
# Let `build_matrix()` guess which column variables represent `rating_start`,
# `rating_end` and `metric`
mock_credit %>%
  migrate(
    date = date,
    rating = risk_rating,
    metric = principal_balance
  ) %>%
  build_matrix()

# Specify which column variables represent `rating_start`, `rating_end` and
# `metric`
mock_credit %>%
  migrate(
    date = date,
    rating = risk_rating,
    metric = principal_balance,
    percent = TRUE
  ) %>%
  build_matrix(
    rating_start = risk_rating_start,
    rating_end = risk_rating_end,
    metric = principal_balance
  )
# }

Run the code above in your browser using DataLab