stabchk.Rd
Checks a given two sided matching for blocking pairs.
stabchk(matching, c.prefs, s.prefs, nColleges = ncol(c.prefs), nStudents = ncol(s.prefs))
matching | data frame or matrix of dimension ( |
---|---|
c.prefs | matrix of dimension |
s.prefs | matrix of dimension |
nColleges | integer indicating the number of colleges |
nStudents | integer indicating the number of students |
stabchk
returns a data frame with as many rows as blocking pairs were found. Column 1 indicates the college and column 2 indicate the student of the blocking pairs. Returns NULL
if no blocking pair is found.
## 1-a. Generate preferences for colleges c.prefs = matrix(c(1,2,3, 3,2,1, 3,2,1), byrow = FALSE, ncol = 3); c.prefs#> [,1] [,2] [,3] #> [1,] 1 3 3 #> [2,] 2 2 2 #> [3,] 3 1 1## 1-b. Generate preferences for students s.prefs = matrix(c(1,2,3, 3,2,1, 2,1,3), byrow = FALSE, ncol = 3);s.prefs#> [,1] [,2] [,3] #> [1,] 1 3 2 #> [2,] 2 2 1 #> [3,] 3 1 3#> [,1] [,2] #> [1,] 1 2 #> [2,] 2 1 #> [3,] 3 3## 1-d. Check stability stabchk(matching = matching, c.prefs = c.prefs, s.prefs = s.prefs)#> college student #> 1 1 1 #> 2 2 3 #> 3 2 2## 2-a. Generate new matching without blocking pairs as a data frame matching = data.frame('colleges' = c(1,2,3), 'student' = c(1,3,2)) stabchk(matching = matching, c.prefs = c.prefs, s.prefs = s.prefs)#> [1] "No blocking pairs!"#> NULL## 3-a. Example with missing values: matching <- matrix(c(1,1,2,2,3,3), byrow = FALSE, ncol = 2) c.prefs <- matrix(c(1,1,3,rep(NA, 6)), byrow = TRUE, ncol = 3) s.prefs <- matrix(c(2,2,3,rep(NA, 6)), byrow = TRUE, ncol = 3) stabchk(matching = matching, c.prefs = c.prefs, s.prefs = s.prefs)#> college student #> 1 2 1 #> 2 3 3