Learn R Programming

matchingR (version 1.3.3)

roommate.checkStability: Check if a roommate matching is stable

Description

This function checks if a particular roommate matching is stable. A matching is stable if there is no roommate r1 that would rather be matched to some other roommate d2 than to his current roommate r2 and the other roommate d2 would rather be matched to r1 than to his current roommate d1.

Usage

roommate.checkStability(utils = NULL, pref = NULL, matching)

Arguments

utils

is a matrix with cardinal utilities for each individual in the market. If there are n individuals, then this matrix will be of dimension n-1 by n. Column j refers to the payoff that individual j receives from being matched to individual 1, 2, ..., j-1, j+1, ...n. If a square matrix is passed as utils, then the main diagonal will be removed.

pref

is a matrix with the preference order of each individual in the market. This argument is only required when utils is not provided. If there are n individuals, then this matrix will be of dimension n-1 by n. The i,jth element refers to j's ith most favorite partner. Preference orders can either be specified using R-indexing (starting at 1) or C++ indexing (starting at 0). The matrix pref must be of dimension n-1 by n. Otherwise, the function will throw an error.

matching

is a vector of length n corresponding to the matchings that were formed. E.g. if the 4th element of this vector is 6 then individual 4 was matched with individual 6.

Value

true if stable, false if not

Examples

Run this code
# NOT RUN {
# define preferences
pref <- matrix(c(
  3, 1, 2, 3,
  4, 3, 4, 2,
  2, 4, 1, 1
), byrow = TRUE, ncol = 4)
pref
# compute matching
results <- roommate(pref = pref)
results
# check if matching is stable
roommate.checkStability(pref = pref, matching = results)
# }

Run the code above in your browser using DataLab