Title: | Analysis of Stable Matchings |
---|---|
Description: | Implements structural estimators to correct for the sample selection bias from observed outcomes in matching markets. This includes one-sided matching of agents into groups (Klein, 2015) <https://www.econ.cam.ac.uk/research-files/repec/cam/pdf/cwpe1521.pdf> as well as two-sided matching of students to schools (Aue et al., 2020) <https://ftp.zew.de/pub/zew-docs/dp/dp20032.pdf>. The package also contains algorithms to find stable matchings in the three most common matching problems: the stable roommates problem (Irving, 1985) <doi:10.1016/0196-6774(85)90033-1>, the college admissions problem (Gale and Shapley, 1962) <doi:10.2307/2312726>, and the house allocation problem (Shapley and Scarf, 1974) <doi:10.1016/0304-4068(74)90033-0>. |
Authors: | Thilo Klein [aut, cre, cph], Robert Aue [ctb], Fahiem Bacchus [cph], Sven Giegerich [ctb], Matthias Hericks [ctb], Alexander Sauer [ctb], Niklas Sorensson [cph] |
Maintainer: | Thilo Klein <[email protected]> |
License: | GPL (>= 2) |
Version: | 1.0-4 |
Built: | 2024-11-24 06:58:04 UTC |
Source: | CRAN |
The matchingMarkets
package contains R, C++
and Java
code for stable matching
algorithms and the estimation of structural models that correct for the sample selection bias of
observed outcomes in matching markets.
Matching is concerned with who transacts with whom, and how. For example, who works at which job, which students go to which school, who forms a workgroup with whom, and so on.
The empirical analysis of matching markets is naturally subject to sample selection problems. If agents match assortatively on characteristics unobserved to the analyst but correlated with both the exogenous variable and the outcome of interest, regression estimates will generally be biased.
The matchingMarkets
package comprises
Bayes estimators. The estimators implemented in function stabit
and stabit2
correct for the selection bias from endogenous matching.
The current package version provides solutions for two commonly observed matching processes: (i) the group formation problem with fixed group sizes and (ii) the college admissions problem. These processes determine which matches are observed – and which are not – and this is a sample selection problem.
Post-estimation tools. Setting mfx=TRUE
in the summary
function
computes marginal effects from coefficients in binary outcome and selection equations
and khb
implements the Karlson-Holm-Breen test for confounding due to sample selection.
Design matrix generation. The estimators are based on independent variables for all feasible, i.e., observed and counterfactual, matches in the market. Generating the characteristics of all feasible matches from individual-level data is a combinatorial problem. The package returns design matrices based on pre-specified transformations to generate counterfactual matches.
Algorithms. The package also contains matching
algorithms that can be used to simulated matching data: hri
: A constraint model (Posser, 2014)
for the stable marriage and
college admissions problem, a.k.a. hospital/residents
problem (see Gale and Shapley, 1962). sri
: A constraint model for the
stable roommates problem (see Gusfield and
Irving, 1989). ttc
: The top-trading-cycles algorithm for the
housing market problem. These can be used to obtain
stable matchings from simulated or real preference data (see Shapley and Scarf, 1974).
Data. In addition to the baac00
dataset from borrowing groups in Thailands largest agricultural lending program, the package provides functions stabsim
and stabsim2
to simulate one's own data from one-sided and two-sided matching markets.
Why can I not use the classic Heckman correction?
Estimators such as the Heckman (1979) correction (in package sampleSelection
) or double selection models are
inappropriate for this class of selection problems. To see this, note that
a simple first stage discrete choice model assumes that an observed match
reveals match partners' preferences over each other. In a matching market,
however, agents can only choose from the set of partners who would be
willing to form a match with them and we do not observe the players'
relevant choice sets.
Do I need an instrumental variable to estimate the model?
Short answer: No. Long answer: The characteristics of other agents in the market serve as the source of exogenous variation necessary to identify the model. The identifying exclusion restriction is that characteristics of all agents in the market affect the matching, i.e., who matches with whom, but it is only the characteristics of the match partners that affect the outcome of a particular match once it is formed. No additional instruments are required for identification (Sorensen, 2007).
What are the main assumptions underlying the estimator?
The approach has certain limitations rooted in its restrictive economic assumptions.
The matching models are complete information models. That is, agents are assumed to have a complete knowledge of the qualities of other market participants.
The models are static equilibrium models. This implies that (i) the observed matching must be an equilibrium, i.e., no two agents would prefer to leave their current partners in order to form a new match (definition of pairwise stability), and (ii) the equilibrium must be unique for the likelihood function of the model to be well defined (Bresnahan and Reiss, 1991).
Uniqueness results can be obtained in two ways. First, as is common in the industrial organization literature, by imposing suitable preference restrictions. A suitable restriction on agents' preferences that guarantees a unique equilibrium is alignment (Pycia, 2012). In a group formation model, (pairwise) preference alignment states that any two agents who belong to the same groups must prefer the same group over the other. Second, by choosing a market assigment based on matching algorithms that produce a unique stable matching, such as the well-studied Gale and Shapley (1962) deferred acceptance algorithm.
Finally, the models assume bivariate normality of the errors in selection and outcome equation. If that assumption fails, the estimator is generally inconsistent and can provide misleading inference in small samples.
Whenever using this package, please cite as
Klein, T. (2023). matchingMarkets: Structural Estimator and Algorithms for the Analysis of Stable Matchings. R package version 1.0-4.
Thilo Klein
Bresnahan, T. and Reiss, P. (1991). Empirical models of discrete games. Journal of Econometrics, 48(1-2):57–81.
Gale, D. and Shapley, L.S. (1962). College admissions and the stability of marriage. The American Mathematical Monthly, 69(1):9–15.
Gusfield, D.M. and R.W. Irving (1989). The stable marriage problem: Structure and algorithms, MIT Press.
Heckman, J. (1979). Sample selection bias as a specification error. Econometrica, 47(1):153–161.
Prosser, P. (2014). Stable Roommates and Constraint Programming. Lecture Notes in Computer Science, CPAIOR 2014 Edition. Springer International Publishing, 8451: 15–28.
Pycia, M. (2012). Stability and preference alignment in matching and coalition formation. Econometrica, 80(1):323–362.
Shapley, L. and H. Scarf (1974). On cores and indivisibility. Journal of Mathematical Economics, 1(1):23–37.
Sorensen, M. (2007). How smart is smart money? A two-sided matching model of venture capital. The Journal of Finance, 62(6):2725–2762.
The baac00
data frame contains data of 292 borrowers from Thailand's largest
agricultural lending program.
These data are collected as part of the Townsend Thai Project Bank for
Agriculture and Agricultural Cooperatives (BAAC) Annual Resurvey
(Townsend, 2000).
The 292 borrowers are nested within 68 groups and 39 markets. This nestedness
makes the dataset particularly relevant for matching applications.
A more complete discussion of the data is
found in Ahlin (2009), Section 3, and Klein (2015a).
data(baac00)
data(baac00)
This data frame contains the following columns:
group identifier.
market identifier.
repayment outcome: BAAC never raised interest rate as a penalty for late repayment.
success probability: measure of group members' project success probability.
worst year: indicator of economically worst year. 1:last year; 2:year before last year; 101-168:neither.
loan size: average loan size borrowed by the group.
loan size squared.
log group age: log of number of years group has existed.
Townsend, R. (2000). Townsend Thai Project Bank for Agriculture and Agricultural Cooperatives (BAAC) Annual Resurvey, 2000. Available at http://hdl.handle.net/1902.1/12057, Murray Research Archive.
Ahlin, C. (2009). Matching for credit: Risk and diversification in Thai microcredit groups. Working Paper 251, Bureau for Research and Economic Analysis of Development.
Klein, T. (2015a). Does Anti-Diversification Pay? A One-Sided Matching Model of Microcredit. Cambridge Working Papers in Economics, #1521.
Finds all stable matchings in either the hospital/residents problem (a.k.a. college admissions problem) or the related stable marriage problem. Dependent on the problem, the results comprise the student and college-optimal or the men and women-optimal matchings. The implementation allows for incomplete preference lists (some agents find certain agents unacceptable) and unbalanced instances (unequal number of agents on both sides). The function uses the Prosser (2014) constraint encoding based on either given or randomly generated preferences.
hri( nStudents = ncol(s.prefs), nColleges = ncol(c.prefs), nSlots = rep(1, nColleges), s.prefs = NULL, c.prefs = NULL, s.range = NULL, c.range = NULL, randomization = NULL, seed = NULL, check_consistency = TRUE, verbose = FALSE, ... )
hri( nStudents = ncol(s.prefs), nColleges = ncol(c.prefs), nSlots = rep(1, nColleges), s.prefs = NULL, c.prefs = NULL, s.range = NULL, c.range = NULL, randomization = NULL, seed = NULL, check_consistency = TRUE, verbose = FALSE, ... )
nStudents |
integer indicating the number of students (in the college admissions problem)
or men (in the stable marriage problem) in the market. Defaults to |
nColleges |
integer indicating the number of colleges (in the college admissions problem)
or women (in the stable marriage problem) in the market. Defaults to |
nSlots |
vector of length |
s.prefs |
matrix of dimension |
c.prefs |
matrix of dimension |
s.range |
range of two intergers |
c.range |
range of two intergers |
randomization |
determines at which level random lottery numbers for student priorities are drawn. The default is |
seed |
integer setting the state for random number generation. |
check_consistency |
Performs consicentcy checks (Checks if there are columns in the preference matrices that only contains zeros and drops them and checks the matrixes for consistencies if they are given by characters). Defaults to |
verbose |
logical. When set to |
... |
. |
hri
returns a list of the following elements.
s.prefs.smi |
student-side preference matrix for the stable marriage problem with incomplete lists (SMI). |
c.prefs.smi |
college-side preference matrix for the stable marriage problem with incomplete lists (SMI). |
s.prefs.hri |
student-side preference matrix for the college admissions problem (a.k.a. hospital/residents problem) with incomplete lists (HRI). |
c.prefs.hri |
college-side preference matrix for the college admissions problem (a.k.a. hospital/residents problem) with incomplete lists (HRI). |
matchings |
edgelist of matched students and colleges, inculding the number of the match
( |
.
hri
requires the following combination of arguments, subject to the matching problem.
nStudents, nColleges
Marriage problem with random preferences.
s.prefs, c.prefs
Marriage problem with given preferences.
nStudents, nSlots
College admissions problem with random preferences.
s.prefs, c.prefs, nSlots
College admissions problem with given preferences.
Thilo Klein
Gale, D. and L.S. Shapley (1962). College admissions and the stability of marriage. The American Mathematical Monthly, 69(1):9–15.
Morizumi, Y., T. Hayashi and Y. Ishida (2011). A network visualization of stable matching in the stable marriage problem. Artificial Life Robotics, 16:40–43.
Prosser, P. (2014). Stable Roommates and Constraint Programming. Lecture Notes in Computer Science, CPAIOR 2014 Edition. Springer International Publishing, 8451: 15–28.
## ----------------------- ## --- Marriage problem ## 7 men, 6 women, random preferences: hri(nStudents=7, nColleges=6, seed=4) ## 3 men, 2 women, given preferences: s.prefs <- matrix(c(1,2, 1,2, 1,2), 2,3) c.prefs <- matrix(c(1,2,3, 1,2,3), 3,2) hri(s.prefs=s.prefs, c.prefs=c.prefs) ## 3 men, 2 women, given preferences: s.prefs <- matrix(c("x","y", "x","y", "x","y"), 2,3) colnames(s.prefs) <- c("A","B","C") c.prefs <- matrix(c("A","B","C", "A","B","C"), 3,2) colnames(c.prefs) <- c("x","y") hri(s.prefs=s.prefs, c.prefs=c.prefs) ## -------------------------------- ## --- College admission problem ## 7 students, 2 colleges with 3 slots each, random preferences: hri(nStudents=7, nSlots=c(3,3), seed=21) ## 7 students, 2 colleges with 3 slots each, given preferences: s.prefs <- matrix(c(1,2, 1,2, 1,NA, 1,2, 1,2, 1,2, 1,2), 2,7) c.prefs <- matrix(c(1,2,3,4,5,6,7, 1,2,3,4,5,NA,NA), 7,2) hri(s.prefs=s.prefs, c.prefs=c.prefs, nSlots=c(3,3)) ## 7 students, 2 colleges with 3 slots each, given preferences: s.prefs <- matrix(c("x","y", "x","y", "x",NA, "x","y", "x","y", "x","y", "x","y"), 2,7) colnames(s.prefs) <- c("A","B","C","D","E","F","G") c.prefs <- matrix(c("A","B","C","D","E","F","G", "A","B","C","D","E",NA,NA), 7,2) colnames(c.prefs) <- c("x","y") hri(s.prefs=s.prefs, c.prefs=c.prefs, nSlots=c(3,3)) ## 7 students, 3 colleges with 3 slots each, incomplete preferences: hri(nStudents=7, nSlots=c(3,3,3), seed=21, s.range=c(1,3)) s.prefs <- matrix(c('S1', 'S2', NA, 'S3', 'S1', NA, 'S1', NA, NA, NA, NA,NA, 'S2', 'S1', 'S5'), nrow = 3, ncol = 5) # Note that we explicitly allow for the existence of entries refering to colleges # that do not exist. A warning is generated and the entry is ignored. colnames(s.prefs) <- c('A', 'B', 'C', 'D', 'E') c.prefs <- matrix(c('B', 'C','D', 'A', 'C', 'D', NA, NA, 'D', 'B', 'A', 'E'), nrow = 4, ncol = 3) colnames(c.prefs) <- c('S1', 'S2', 'S3') hri(s.prefs=s.prefs, c.prefs=c.prefs, nSlots=c(3,3,3), check_consistency = TRUE) ## -------------------- ## --- Summary plots ## 200 students, 200 colleges with 1 slot each res <- hri(nStudents=200, nColleges=200, seed=12) plot(res) plot(res, energy=TRUE)
## ----------------------- ## --- Marriage problem ## 7 men, 6 women, random preferences: hri(nStudents=7, nColleges=6, seed=4) ## 3 men, 2 women, given preferences: s.prefs <- matrix(c(1,2, 1,2, 1,2), 2,3) c.prefs <- matrix(c(1,2,3, 1,2,3), 3,2) hri(s.prefs=s.prefs, c.prefs=c.prefs) ## 3 men, 2 women, given preferences: s.prefs <- matrix(c("x","y", "x","y", "x","y"), 2,3) colnames(s.prefs) <- c("A","B","C") c.prefs <- matrix(c("A","B","C", "A","B","C"), 3,2) colnames(c.prefs) <- c("x","y") hri(s.prefs=s.prefs, c.prefs=c.prefs) ## -------------------------------- ## --- College admission problem ## 7 students, 2 colleges with 3 slots each, random preferences: hri(nStudents=7, nSlots=c(3,3), seed=21) ## 7 students, 2 colleges with 3 slots each, given preferences: s.prefs <- matrix(c(1,2, 1,2, 1,NA, 1,2, 1,2, 1,2, 1,2), 2,7) c.prefs <- matrix(c(1,2,3,4,5,6,7, 1,2,3,4,5,NA,NA), 7,2) hri(s.prefs=s.prefs, c.prefs=c.prefs, nSlots=c(3,3)) ## 7 students, 2 colleges with 3 slots each, given preferences: s.prefs <- matrix(c("x","y", "x","y", "x",NA, "x","y", "x","y", "x","y", "x","y"), 2,7) colnames(s.prefs) <- c("A","B","C","D","E","F","G") c.prefs <- matrix(c("A","B","C","D","E","F","G", "A","B","C","D","E",NA,NA), 7,2) colnames(c.prefs) <- c("x","y") hri(s.prefs=s.prefs, c.prefs=c.prefs, nSlots=c(3,3)) ## 7 students, 3 colleges with 3 slots each, incomplete preferences: hri(nStudents=7, nSlots=c(3,3,3), seed=21, s.range=c(1,3)) s.prefs <- matrix(c('S1', 'S2', NA, 'S3', 'S1', NA, 'S1', NA, NA, NA, NA,NA, 'S2', 'S1', 'S5'), nrow = 3, ncol = 5) # Note that we explicitly allow for the existence of entries refering to colleges # that do not exist. A warning is generated and the entry is ignored. colnames(s.prefs) <- c('A', 'B', 'C', 'D', 'E') c.prefs <- matrix(c('B', 'C','D', 'A', 'C', 'D', NA, NA, 'D', 'B', 'A', 'E'), nrow = 4, ncol = 3) colnames(c.prefs) <- c('S1', 'S2', 'S3') hri(s.prefs=s.prefs, c.prefs=c.prefs, nSlots=c(3,3,3), check_consistency = TRUE) ## -------------------- ## --- Summary plots ## 200 students, 200 colleges with 1 slot each res <- hri(nStudents=200, nColleges=200, seed=12) plot(res) plot(res, energy=TRUE)
Implements the Roth Peranson matching algorithm for the hospital/residents problem with couples as described in Roth and Peranson (1999). The function is based on an adoption of Bacchus (2018) and the SAT-solver of Sorenssen (2013).
hri2( nStudents = ncol(s.prefs), nColleges = ncol(c.prefs), nSlots = rep(1, nColleges), nCouples = ncol(co.prefs), s.prefs = NULL, c.prefs = NULL, co.prefs = NULL, randomization = "multiple", seed = NULL, check_consistency = TRUE, verbose = FALSE, ... )
hri2( nStudents = ncol(s.prefs), nColleges = ncol(c.prefs), nSlots = rep(1, nColleges), nCouples = ncol(co.prefs), s.prefs = NULL, c.prefs = NULL, co.prefs = NULL, randomization = "multiple", seed = NULL, check_consistency = TRUE, verbose = FALSE, ... )
nStudents |
integer indicating the number of students (in the college admissions problem)
or men (in the stable marriage problem) in the market. Defaults to |
nColleges |
integer indicating the number of colleges (in the college admissions problem)
or women (in the stable marriage problem) in the market. Defaults to |
nSlots |
vector of length |
nCouples |
integer indicating the number of couples (in the college admissions problem)
or men (in the stable marriage problem) in the market. Defaults to |
s.prefs |
matrix of dimension |
c.prefs |
matrix of dimension |
co.prefs |
matrix of dimension |
randomization |
determines at which level and in which order random lottery numbers for student priorities are drawn. The default is |
seed |
integer setting the state for random number generation. |
check_consistency |
Performs additional consicentcy checks if the preference matrices are given by characters. Defaults to |
verbose |
logical. When set to |
... |
. |
hri2
returns a list of the following elements:
matchings |
List of matched students and colleges. |
summary |
Detailed report of the matching result, including futher information on ranks. |
hri2
requires the following combination of arguments, subject to the matching problem.
nStudents, nColleges
Residence hospital problem without couples and random preferences
nStudents, nColleges, nCouples, nSlots
Residence hospital problem with couples and random preferences.
s.prefs, c.prefs, co.prefs, nSlots
Residence hospital problem with couples and given preferences.
Fahiem Bacchus, Sven Giegerich, Thilo Klein, Niklas Sorensson
Bacchus, F. (2018). Stable matching suite. GitHub repository.
Gale, D. and L.S. Shapley (1962). College admissions and the stability of marriage. The American Mathematical Monthly, 69(1):9–15.
Roth, A. E., & Peranson, E. (1999). The redesign of the matching market for American physicians: Some engineering aspects of economic design. American economic review, 89(4), 748-780.
Kojima, F., Pathak, P. A., & Roth, A. E. (2013). Matching with couples: Stability and incentives in large markets. The Quarterly Journal of Economics, 128(4), 1585-1632.
Sorenssen, N. (2013). minisat. GitHub repository.
## Example with given preferences s.prefs <- matrix(c(4,2,3,5, 2,1,3,NA, 1,2,3,4), 4,3) c.prefs <- matrix(rep(1:5,5), 5,5) co.prefs <- matrix(c(rep(4,3), rep(5,3), 3,3,NA, 3,NA,3), 3,4) res <- hri2(s.prefs=s.prefs, c.prefs=c.prefs, co.prefs=co.prefs, nSlots=rep(1,5)) res$matchings # summary(res) ## Example with random preferences nStudents <- 50 nColleges <- 30 nCouples <- 4 nSlots <- sample(1:nStudents, nColleges) res <- hri2(nStudents=nStudents, nColleges=nColleges, nCouples=nCouples, nSlots=nSlots) res$matchings # summary(res) ## Example with characters in the preferences matrices s.prefs <- matrix(c("Micro1", NA, NA, "Micro2", "Micro1", "Macro", "Macro",NA ,NA), ncol = 3) colnames(s.prefs) <- c('Lea', 'Mia', 'Kai') c.prefs <- matrix(c("Niklas", "Kai", "Mia", "Anna", "Lea", "Kai", "Anna",NA, "Kai", "Mia", "Lea",NA), ncol = 3) colnames(c.prefs) <- c('Micro1', 'Micro2', 'Macro') col1 <- c(rep("Niklas",4),rep("Anna",5)) col2 <- c(rep("Jan",4),rep("Lisa",5)) col3 <- c("Micro1","Macro","Micro1",NA,"Macro", NA,"Micro2","Micro2","Macro") col4 <- c("Micro2","Micro1",NA,"Macro","Macro", "Micro1","Micro2","Macro",NA) co.prefs <- matrix(c(col1,col2,col3,col4), ncol = 4) res <- hri2(s.prefs=s.prefs, c.prefs=c.prefs, co.prefs=co.prefs, nSlots=c(2,1,1)) res$matching ## Example if students are allowed to apply and be accepted by two courses col12 <- c(rep(c(rep("Niklas",4),rep("Anna",2)),2)) col3 <- c("Micro1","Macro","Micro1","Macro","Macro","Macro") col4 <- c("Micro2","Micro1",NA,NA,"Micro1","Micro2") co.prefs <- matrix(c(col12,col3,col4), ncol = 4) res <- hri2(s.prefs=s.prefs, c.prefs=c.prefs, co.prefs=co.prefs, nSlots=c(2,1,1)) res$matching
## Example with given preferences s.prefs <- matrix(c(4,2,3,5, 2,1,3,NA, 1,2,3,4), 4,3) c.prefs <- matrix(rep(1:5,5), 5,5) co.prefs <- matrix(c(rep(4,3), rep(5,3), 3,3,NA, 3,NA,3), 3,4) res <- hri2(s.prefs=s.prefs, c.prefs=c.prefs, co.prefs=co.prefs, nSlots=rep(1,5)) res$matchings # summary(res) ## Example with random preferences nStudents <- 50 nColleges <- 30 nCouples <- 4 nSlots <- sample(1:nStudents, nColleges) res <- hri2(nStudents=nStudents, nColleges=nColleges, nCouples=nCouples, nSlots=nSlots) res$matchings # summary(res) ## Example with characters in the preferences matrices s.prefs <- matrix(c("Micro1", NA, NA, "Micro2", "Micro1", "Macro", "Macro",NA ,NA), ncol = 3) colnames(s.prefs) <- c('Lea', 'Mia', 'Kai') c.prefs <- matrix(c("Niklas", "Kai", "Mia", "Anna", "Lea", "Kai", "Anna",NA, "Kai", "Mia", "Lea",NA), ncol = 3) colnames(c.prefs) <- c('Micro1', 'Micro2', 'Macro') col1 <- c(rep("Niklas",4),rep("Anna",5)) col2 <- c(rep("Jan",4),rep("Lisa",5)) col3 <- c("Micro1","Macro","Micro1",NA,"Macro", NA,"Micro2","Micro2","Macro") col4 <- c("Micro2","Micro1",NA,"Macro","Macro", "Micro1","Micro2","Macro",NA) co.prefs <- matrix(c(col1,col2,col3,col4), ncol = 4) res <- hri2(s.prefs=s.prefs, c.prefs=c.prefs, co.prefs=co.prefs, nSlots=c(2,1,1)) res$matching ## Example if students are allowed to apply and be accepted by two courses col12 <- c(rep(c(rep("Niklas",4),rep("Anna",2)),2)) col3 <- c("Micro1","Macro","Micro1","Macro","Macro","Macro") col4 <- c("Micro2","Micro1",NA,NA,"Micro1","Micro2") co.prefs <- matrix(c(col12,col3,col4), ncol = 4) res <- hri2(s.prefs=s.prefs, c.prefs=c.prefs, co.prefs=co.prefs, nSlots=c(2,1,1)) res$matching
Finds the optimal assignment of students to colleges in the
college admissions problem
based on the Boston mechanism. The algorithmen is also applicable to the stable marriage problem. The option acceptance="deferred"
instead uses the Gale-Shapley
(1962) Deferred Acceptance Algorithm with student offer. The function works with either
given or randomly generated preferences.
iaa( nStudents = ncol(s.prefs), nColleges = ncol(c.prefs), nSlots = rep(1, nColleges), s.prefs = NULL, c.prefs = NULL, acceptance = "immediate", short_match = TRUE, seed = NULL )
iaa( nStudents = ncol(s.prefs), nColleges = ncol(c.prefs), nSlots = rep(1, nColleges), s.prefs = NULL, c.prefs = NULL, acceptance = "immediate", short_match = TRUE, seed = NULL )
nStudents |
integer indicating the number of students (in the college admissions problem)
or men (in the stable marriage problem) in the market. Defaults to |
nColleges |
integer indicating the number of colleges (in the college admissions problem)
or women (in the stable marriage problem) in the market. Defaults to |
nSlots |
vector of length |
s.prefs |
matrix of dimension |
c.prefs |
matrix of dimension |
acceptance |
if |
short_match |
(Optional) If |
seed |
(Optional) integer setting the state for random number generation. |
iaa
returns a list with the following elements.
s.prefs |
student-side preference matrix. |
c.prefs |
college-side preference matrix. |
iterations |
number of interations required to find the stable matching. |
matchings |
edgelist of matches |
singles |
identifier of single (or unmatched) students/men. |
iaa
requires the following combination of arguments, subject to the matching problem.
nStudents, nColleges
Marriage problem with random preferences.
s.prefs, c.prefs
Marriage problem with given preferences.
nStudents, nSlots
College admissions problem with random preferences.
s.prefs, c.prefs, nSlots
College admissions problem with given preferences.
Thilo Klein
Gale, D. and Shapley, L.S. (1962). College admissions and the stability of marriage. The American Mathematical Monthly, 69(1):9–15.
Kojima, F. and M.U. Unver (2014). The "Boston" school-choice mechanism. Economic Theory, 55(3): 515–544.
## -------------------------------- ## --- College admission problem s.prefs <- matrix(c(1,2,3, 1,2,3, 1,2,3, 2,1,3, 2,1,3), byrow = FALSE, ncol = 5, nrow = 3) c.prefs <- matrix(c(1,4,2,3,5, 5,2,3,4,1, 1,2,3,4,5), byrow = FALSE, ncol = 3, nrow = 5) nSlots <- c(2,2,1) ## Boston mechanism iaa(s.prefs = s.prefs, c.prefs = c.prefs, nSlots = nSlots)$matchings ## Gale-Shapley algorithm iaa(s.prefs = s.prefs, c.prefs = c.prefs, nSlots = nSlots, acceptance="deferred")$matchings ## Same results for the Gale-Shapley algorithm with hri2() function (but different format) set.seed(123) iaa(nStudents=7, nSlots=c(3,3), acceptance="deferred")$matchings set.seed(123) hri2(nStudents=7, nSlots=c(3,3))$matchings
## -------------------------------- ## --- College admission problem s.prefs <- matrix(c(1,2,3, 1,2,3, 1,2,3, 2,1,3, 2,1,3), byrow = FALSE, ncol = 5, nrow = 3) c.prefs <- matrix(c(1,4,2,3,5, 5,2,3,4,1, 1,2,3,4,5), byrow = FALSE, ncol = 3, nrow = 5) nSlots <- c(2,2,1) ## Boston mechanism iaa(s.prefs = s.prefs, c.prefs = c.prefs, nSlots = nSlots)$matchings ## Gale-Shapley algorithm iaa(s.prefs = s.prefs, c.prefs = c.prefs, nSlots = nSlots, acceptance="deferred")$matchings ## Same results for the Gale-Shapley algorithm with hri2() function (but different format) set.seed(123) iaa(nStudents=7, nSlots=c(3,3), acceptance="deferred")$matchings set.seed(123) hri2(nStudents=7, nSlots=c(3,3))$matchings
Significance test for confounding; that is, the difference between regression coefficients from same-sample nested logit and probit models. The test procedure follows Karlson et al (2012), Section 3.4.
khb(X, y, z)
khb(X, y, z)
X |
data frame comprising independent variables including confounding variable. |
y |
vector of dependent variable. |
z |
character string giving the name of the confounding variable in |
khb
returns for all model coefficients the p-value for the null hypothesis that the change in coefficients is not attributable to confounding by z.
Thilo Klein
Karlson, K.B., A. Holm and R. Breen (2012). Comparing regression coefficients between same-sample nested models using logit and probit: A new method. Sociological Methodology, 42(1):286–313.
## 1. load results from Klein (2015a) data(klein15a) ## 2. apply KHB method with(klein15a$variables, khb(X=X, y=Y, z="eta"))
## 1. load results from Klein (2015a) data(klein15a) ## 2. apply KHB method with(klein15a$variables, khb(X=X, y=Y, z="eta"))
MCMC results in Klein (2015a).
data(klein15a)
data(klein15a)
A list containing the following elements:
.
.
Klein, T. (2015a). Does Anti-Diversification Pay? A One-Sided Matching Model of Microcredit. Cambridge Working Papers in Economics, #1521.
Results of Monte Carlo Simulations in Klein (2015b) for 40 two-group markets.
data(klein15b)
data(klein15b)
A list containing the following elements:
Benchmark study, OLS: coefficient estimates for 40 markets with groups of 5. Data for all 5 group members is observed.
Benchmark study, structural model.
Experiment 1, OLS: coefficient estimates for 40 markets with groups of 6. Only Data for 5 group members is observed.
Experiment 1, structural model.
Experiment 2, OLS: coefficient estimates for 40 markets with groups of 6. Data for all 6 group members is observed but only a random sample of 250 of the 922 counterfactual groups is used in the analysis.
Experiment 2, structural model.
Klein, T. (2015a). Does Anti-Diversification Pay? A One-Sided Matching Model of Microcredit. Cambridge Working Papers in Economics, #1521.
Klein, T. (2015b). Analysis of stable matchings in R: Package matchingMarkets. Vignette to R package matchingMarkets, The Comprehensive R Archive Network.
## Plot of posterior distributions data(klein15b) tpe <- c(rep("Benchmark",2), rep("Experiment 1",2), rep("Experiment 2",2)) for(i in seq(1,length(klein15b)-1,2)){ ntu <- klein15b[[i]] ols <- klein15b[[i+1]] ntu <- ntu[,colnames(ntu) == "beta.wst.ieq"] ols <- ols[,colnames(ols) == "beta.wst.ieq"] if(i == 1){ draws <- data.frame(Structural=ntu, OLS=ols, type=tpe[i]) #, stringsAsFactors=FALSE } else{ draws <- rbind(draws, data.frame(Structural=ntu, OLS=ols, type=tpe[i])) } } library(lattice) lattice.options(default.theme = standard.theme(color = FALSE)) keys <- list(text=c("Structural model","OLS"), space="top", columns=2, lines=TRUE) densityplot( ~ Structural + OLS | type, plot.points=FALSE, auto.key=keys, data = draws, xlab = "coefficient draws", ylab = "density", type = "l", panel = function(x,...) { panel.densityplot(x,...) panel.abline(v=-1, lty=3) }) ## Modes of posterior distributions ## load data data(klein15b) ## define function to obtain the mode mode <- function(x){ d <- density(x,bw="SJ") formatC(round(d$x[which.max(d$y)], 3), format='f', digits=3) } ## Benchmark study apply(klein15b$exp.5.5.ntu, 2, mode) apply(klein15b$exp.5.5.ols, 2, mode) ## Experiment 1 apply(klein15b$exp.6.5.ntu, 2, mode) apply(klein15b$exp.6.5.ols, 2, mode) ## Experiment 2 apply(klein15b$exp.6.6.ntu, 2, mode) apply(klein15b$exp.6.6.ols, 2, mode)
## Plot of posterior distributions data(klein15b) tpe <- c(rep("Benchmark",2), rep("Experiment 1",2), rep("Experiment 2",2)) for(i in seq(1,length(klein15b)-1,2)){ ntu <- klein15b[[i]] ols <- klein15b[[i+1]] ntu <- ntu[,colnames(ntu) == "beta.wst.ieq"] ols <- ols[,colnames(ols) == "beta.wst.ieq"] if(i == 1){ draws <- data.frame(Structural=ntu, OLS=ols, type=tpe[i]) #, stringsAsFactors=FALSE } else{ draws <- rbind(draws, data.frame(Structural=ntu, OLS=ols, type=tpe[i])) } } library(lattice) lattice.options(default.theme = standard.theme(color = FALSE)) keys <- list(text=c("Structural model","OLS"), space="top", columns=2, lines=TRUE) densityplot( ~ Structural + OLS | type, plot.points=FALSE, auto.key=keys, data = draws, xlab = "coefficient draws", ylab = "density", type = "l", panel = function(x,...) { panel.densityplot(x,...) panel.abline(v=-1, lty=3) }) ## Modes of posterior distributions ## load data data(klein15b) ## define function to obtain the mode mode <- function(x){ d <- density(x,bw="SJ") formatC(round(d$x[which.max(d$y)], 3), format='f', digits=3) } ## Benchmark study apply(klein15b$exp.5.5.ntu, 2, mode) apply(klein15b$exp.5.5.ols, 2, mode) ## Experiment 1 apply(klein15b$exp.6.5.ntu, 2, mode) apply(klein15b$exp.6.5.ols, 2, mode) ## Experiment 2 apply(klein15b$exp.6.6.ntu, 2, mode) apply(klein15b$exp.6.6.ols, 2, mode)
Finds the stable matching in the stable roommates problem with transferable utility. Uses the Partitioning Linear Programme formulated in Quint (1991).
plp(V = NULL, N = NULL)
plp(V = NULL, N = NULL)
V |
valuation matrix of dimension |
N |
integer (divisible by 2) that gives the number of players in the market. |
plp
returns a list with the following items.
Valuation.matrix |
input values of V. |
Assignment.matrix |
upper triangular matrix of dimension |
Equilibrium.groups |
matrix that gives the |
Thilo Klein
Quint, T. (1991). Necessary and sufficient conditions for balancedness in partitioning games. Mathematical Social Sciences, 22(1):87–91.
## Roommate problem with 10 players, transferable utility and random preferences: plp(N=10) ## Roommate problem with 10 players, transferable utility and given preferences: V <- matrix(rep(1:10, 10), 10, 10) plp(V=V)
## Roommate problem with 10 players, transferable utility and random preferences: plp(N=10) ## Roommate problem with 10 players, transferable utility and given preferences: V <- matrix(rep(1:10, 10), 10, 10) plp(V=V)
Calculate predicted values for matching models fitted with functions stabit
and stabit2
.
## S3 method for class 'stabit2' predict(object, newdata = NULL, ...)
## S3 method for class 'stabit2' predict(object, newdata = NULL, ...)
object |
a fitted object of class |
newdata |
optionally, a data frame in which to look for variables with which to predict. If omitted, the fitted linear predictors or the fitted response values are returned. |
... |
. |
predict.stabit2
returns a vector of predicted values for the latent outcome variable of an object of class stabit
.
Thilo Klein
Klein, T. (2015a). Does Anti-Diversification Pay? A One-Sided Matching Model of Microcredit. Cambridge Working Papers in Economics, #1521.
## load the results from Klein (2015) paper data(klein15a) ## predict the latent outcome variable predict(klein15a)
## load the results from Klein (2015) paper data(klein15a) ## predict the latent outcome variable predict(klein15a)
Implements the random serial dictatorship algorithm algorithm for a fair division of indivisible objects among individuals. The mechanism takes individuals' prioirty order as an input or alternatively draws a random permutation of the agents form the uniform distribution. Individuals are then successively assigned an object in that order (so the first agent in the ordering gets the first pick and so on).
rsd( nIndividuals = ncol(prefs), nObjects = nrow(prefs), prefs, priority, seed = NULL, nSlots = rep(1, nObjects) )
rsd( nIndividuals = ncol(prefs), nObjects = nrow(prefs), prefs, priority, seed = NULL, nSlots = rep(1, nObjects) )
nIndividuals |
integer indicating the number of individuals in the matching problem. Defaults to ncol(prefs). |
nObjects |
integer indication the number of objects in the matching problem. Defaults to nrow(prefs). |
prefs |
matrix of dimension |
priority |
(Optional) vector of length |
seed |
(Optional) integer setting the state for random number generation. Defaults to seed = 123. |
nSlots |
(Optional) vector of length |
rsd
returns a data frame containing the final matching of individuals (ind) to objects (obj).
Thilo Klein, Alexander Sauer
## Generate preference-matrix prefs <- matrix(c(1,2,3, 3,1,2, 1,3,2), byrow = FALSE, ncol = 3) priority <- c(1,2,3) nSlots <- c(1,1,1) rsd(prefs = prefs, priority = priority, nSlots = nSlots)
## Generate preference-matrix prefs <- matrix(c(1,2,3, 3,1,2, 1,3,2), byrow = FALSE, ncol = 3) priority <- c(1,2,3) nSlots <- c(1,1,1) rsd(prefs = prefs, priority = priority, nSlots = nSlots)
Finds all stable matchings (if one exists) in the stable roommates problem with incomplete lists using the Prosser (2014) constraint encoding based on either given or randomly generated preferences.
sri(prefs = NULL, nAgents = NULL, seed = NULL, p.range = NULL)
sri(prefs = NULL, nAgents = NULL, seed = NULL, p.range = NULL)
prefs |
valuation matrix of dimension |
nAgents |
integer that gives the number of players in the market. |
seed |
integer setting the state for random number generation. |
p.range |
range of two intergers |
sri
returns a list with the following items.
prefs |
agents' preference list. |
matching |
edgelist of matched pairs, inculding the number of the match ( |
Thilo Klein
Gusfield, D.M. and R.W. Irving (1989). The Stable Marriage Problem: Structure and Algorithms, MIT Press.
Prosser, P. (2014). Stable Roommates and Constraint Programming. Lecture Notes in Computer Science, CPAIOR 2014 Edition. Springer International Publishing, 8451: 15–28.
Irving, R.W. (1985). An efficient algorithm for the "stable roommates" problem. Journal of Algorithms, 6(4): 577–595.
Irving, R.W. and S. Scott (2007). The stable fixtures problem: A many-to-many extension of stable roommates. Discrete Applied Mathematics, 155: 2118–2129.
## Roommate problem with 10 players, given preferences: prefs <- matrix(rep(1:10, 10), 10, 10) sri(prefs=prefs) ## Roommate problem with 10 players, random preferences: sri(nAgents=10, seed=1) ## Roommate problem with no equilibrium matching: sri(nAgents=10, seed=2) ## Roommate problem with 3 equilibria: sri(nAgents=10, seed=3)
## Roommate problem with 10 players, given preferences: prefs <- matrix(rep(1:10, 10), 10, 10) sri(prefs=prefs) ## Roommate problem with 10 players, random preferences: sri(nAgents=10, seed=1) ## Roommate problem with no equilibrium matching: sri(nAgents=10, seed=2) ## Roommate problem with 3 equilibria: sri(nAgents=10, seed=3)
Checks a given two sided matching for blocking pairs.
stabchk( matching, c.prefs, s.prefs, nColleges = ncol(c.prefs), nStudents = ncol(s.prefs) )
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.
Thilo Klein, Alexander Sauer
## 1-a. Generate preferences for colleges c.prefs = matrix(c(1,2,3, 3,2,1, 3,2,1), byrow = FALSE, ncol = 3) ## 1-b. Generate preferences for students s.prefs = matrix(c(1,2,3, 3,2,1, 2,1,3), byrow = FALSE, ncol = 3) ## 1-c. Generate matching matching = matrix(c(1,2, 2,1, 3,3), byrow = TRUE, ncol = 2) ## 1-d. Check stability stabchk(matching = matching, c.prefs = c.prefs, s.prefs = s.prefs) ## 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) ## 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)
## 1-a. Generate preferences for colleges c.prefs = matrix(c(1,2,3, 3,2,1, 3,2,1), byrow = FALSE, ncol = 3) ## 1-b. Generate preferences for students s.prefs = matrix(c(1,2,3, 3,2,1, 2,1,3), byrow = FALSE, ncol = 3) ## 1-c. Generate matching matching = matrix(c(1,2, 2,1, 3,3), byrow = TRUE, ncol = 2) ## 1-d. Check stability stabchk(matching = matching, c.prefs = c.prefs, s.prefs = s.prefs) ## 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) ## 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)
The function provides a Gibbs sampler for a structural matching model that estimates preferences and corrects for sample selection bias when the selection process is a one-sided matching game; that is, group/coalition formation.
The input is individual-level data of all group members from one-sided matching marktes; that is, from group/coalition formation games.
In a first step, the function generates a model matrix with characteristics of all feasible groups of the same size as the observed groups in the market.
For example, in the stable roommates problem with students
sorting into groups of 2, we have
feasible groups:
(1,2)(3,4) (1,3)(2,4) (1,4)(2,3).
In the group formation problem with students
sorting into groups of 3, we have
feasible groups.
For the same students sorting into groups of sizes 2 and 4, we have
feasible groups.
The structural model consists of a selection and an outcome equation. The Selection Equation
determines which matches are observed () and which are not (
).
Here, is a vector of latent valuations of all feasible matches, ie observed and
unobserved, and
is the Iverson bracket.
A match is observed if its match valuation is in the set of valuations
that satisfy the equilibrium condition (see Klein, 2015a). This condition differs for matching
games with transferable and non-transferable utility and can be specified using the
method
argument.
The match valuation is a linear function of
, a matrix of characteristics for
all feasible groups, and
, a vector of random errors.
is a paramter
vector to be estimated.
The Outcome Equation determines the outcome for observed matches. The dependent
variable can either be continuous or binary, dependent on the value of the binary
argument. In the binary case, the dependent variable is determined by a threshold
rule for the latent variable
.
Here, is a linear function of
, a matrix of characteristics for observed
matches, and
, a vector of random errors.
is a paramter vector to
be estimated.
The structural model imposes a linear relationship between the error terms of both equations
as , where
is a vector of random errors and
is the covariance paramter to be estimated. If
were zero, the marginal distributions
of
and
would be independent and the selection problem would vanish.
That is, the observed outcomes would be a random sample from the population of interest.
stabit( x, m.id = "m.id", g.id = "g.id", R = "R", selection = NULL, outcome = NULL, simulation = "none", seed = 123, max.combs = Inf, method = "NTU", binary = FALSE, offsetOut = 0, offsetSel = 0, marketFE = FALSE, censored = 0, gPrior = FALSE, dropOnes = FALSE, interOut = 0, interSel = 0, standardize = 0, niter = 10, verbose = FALSE )
stabit( x, m.id = "m.id", g.id = "g.id", R = "R", selection = NULL, outcome = NULL, simulation = "none", seed = 123, max.combs = Inf, method = "NTU", binary = FALSE, offsetOut = 0, offsetSel = 0, marketFE = FALSE, censored = 0, gPrior = FALSE, dropOnes = FALSE, interOut = 0, interSel = 0, standardize = 0, niter = 10, verbose = FALSE )
x |
data frame with individual-level characteristics of all group members including market- and group-identifiers. |
m.id |
character string giving the name of the market identifier variable. Defaults to |
g.id |
character string giving the name of the group identifier variable. Defaults to |
R |
dependent variable in outcome equation. Defaults to |
selection |
list containing variables and pertaining operators in the selection equation. The format is
|
outcome |
list containing variables and pertaining operators in the outcome equation. The format is
|
simulation |
should the values of dependent variables in selection and outcome equations be simulated? Options are |
seed |
integer setting the state for random number generation if |
max.combs |
integer (divisible by two) giving the maximum number of feasible groups to be used for generating group-level characteristics. |
method |
estimation method to be used. Either |
binary |
logical: if |
offsetOut |
vector of integers indicating the indices of columns in |
offsetSel |
vector of integers indicating the indices of columns in |
marketFE |
logical: if |
censored |
draws of the |
gPrior |
logical: if |
dropOnes |
logical: if |
interOut |
two-colum matrix indicating the indices of columns in |
interSel |
two-colum matrix indicating the indices of columns in |
standardize |
numeric: if |
niter |
number of iterations to use for the Gibbs sampler. |
verbose |
logical. When set to |
Operators for variable transformations in selection
and outcome
arguments.
add
sum over all group members and divide by group size.
int
sum over all possible two-way interactions of group members and divide by the number of those, given by
choose(n,2)
.
ieq
sum over all possible two-way equality assertions and divide by the number of those.
ive
sum over all possible two-way interactions of vectors of variables of group members and divide by number of those.
inv
...
dst
sum over all possible two-way distances between players and divide by number of those, where distance is defined as .
stabit
returns for method = "model.frame"
, a list of data from a NTU or TU matching market with the following elements.
OUT |
Model matrix of the outcome data, where |
SEL |
Model matrix of the selection data, again with categorical variables |
combs |
List of length of the number of markets with each element containing a matrix of all counterfactual group constellations in a market. |
For any other setting of method
, a list of the estimation results is returned.
Thilo Klein
Klein, T. (2015a). Does Anti-Diversification Pay? A One-Sided Matching Model of Microcredit. Cambridge Working Papers in Economics, #1521.
Zellner, A. (1986). On assessing prior distributions and Bayesian regression analysis with g-prior distributions, volume 6, pages 233–243. North-Holland, Amsterdam.
## --- SIMULATED EXAMPLE --- ## 1. Simulate one-sided matching data for 200 markets (m=200) with 2 groups ## per market (gpm=2) and 5 individuals per group (ind=5). True parameters ## in selection equation is wst=1, in outcome equation wst=0. ## 1-a. Simulate individual-level, independent variables idata <- stabsim(m=200, ind=5, seed=123, gpm=2) head(idata) ## 1-b. Simulate group-level variables mdata <- stabit(x=idata, simulation="NTU", method="model.frame", selection = list(add="wst"), outcome = list(add="wst"), verbose=FALSE) head(mdata$OUT) head(mdata$SEL) ## 2. Bias from sorting ## 2-a. Naive OLS estimation lm(R ~ wst.add, data=mdata$OUT)$coefficients ## 2-b. epsilon is correlated with independent variables with(mdata$OUT, cor(epsilon, wst.add)) ## 2-c. but xi is uncorrelated with independent variables with(mdata$OUT, cor(xi, wst.add)) ## 3. Correction of sorting bias when valuations V are observed ## 3-a. 1st stage: obtain fitted value for eta lm.sel <- lm(V ~ -1 + wst.add, data=mdata$SEL) lm.sel$coefficients eta <- lm.sel$resid[mdata$SEL$D==1] ## 3-b. 2nd stage: control for eta lm(R ~ wst.add + eta, data=mdata$OUT)$coefficients ## 4. Run Gibbs sampler fit1 <- stabit(x=idata, method="NTU", simulation="NTU", censored=1, selection = list(add="wst"), outcome = list(add="wst"), niter=2000, verbose=FALSE) ## 5. Coefficient table summary(fit1) ## 6. Plot MCMC draws for coefficients plot(fit1) ## --- REPLICATION, Klein (2015a) --- ## 1. Load data data(baac00) ## 2. Run Gibbs sampler klein15a <- stabit(x=baac00, selection = list(inv="pi",ieq="wst"), outcome = list(add="pi",inv="pi",ieq="wst", add=c("loan_size","loan_size2","lngroup_agei")), offsetOut=1, method="NTU", binary=TRUE, gPrior=TRUE, marketFE=TRUE, niter=800000) ## 3. Marginal effects summary(klein15a, mfx=TRUE) ## 4. Plot MCMC draws for coefficients plot(klein15a)
## --- SIMULATED EXAMPLE --- ## 1. Simulate one-sided matching data for 200 markets (m=200) with 2 groups ## per market (gpm=2) and 5 individuals per group (ind=5). True parameters ## in selection equation is wst=1, in outcome equation wst=0. ## 1-a. Simulate individual-level, independent variables idata <- stabsim(m=200, ind=5, seed=123, gpm=2) head(idata) ## 1-b. Simulate group-level variables mdata <- stabit(x=idata, simulation="NTU", method="model.frame", selection = list(add="wst"), outcome = list(add="wst"), verbose=FALSE) head(mdata$OUT) head(mdata$SEL) ## 2. Bias from sorting ## 2-a. Naive OLS estimation lm(R ~ wst.add, data=mdata$OUT)$coefficients ## 2-b. epsilon is correlated with independent variables with(mdata$OUT, cor(epsilon, wst.add)) ## 2-c. but xi is uncorrelated with independent variables with(mdata$OUT, cor(xi, wst.add)) ## 3. Correction of sorting bias when valuations V are observed ## 3-a. 1st stage: obtain fitted value for eta lm.sel <- lm(V ~ -1 + wst.add, data=mdata$SEL) lm.sel$coefficients eta <- lm.sel$resid[mdata$SEL$D==1] ## 3-b. 2nd stage: control for eta lm(R ~ wst.add + eta, data=mdata$OUT)$coefficients ## 4. Run Gibbs sampler fit1 <- stabit(x=idata, method="NTU", simulation="NTU", censored=1, selection = list(add="wst"), outcome = list(add="wst"), niter=2000, verbose=FALSE) ## 5. Coefficient table summary(fit1) ## 6. Plot MCMC draws for coefficients plot(fit1) ## --- REPLICATION, Klein (2015a) --- ## 1. Load data data(baac00) ## 2. Run Gibbs sampler klein15a <- stabit(x=baac00, selection = list(inv="pi",ieq="wst"), outcome = list(add="pi",inv="pi",ieq="wst", add=c("loan_size","loan_size2","lngroup_agei")), offsetOut=1, method="NTU", binary=TRUE, gPrior=TRUE, marketFE=TRUE, niter=800000) ## 3. Marginal effects summary(klein15a, mfx=TRUE) ## 4. Plot MCMC draws for coefficients plot(klein15a)
The function provides a Gibbs sampler for a structural matching model that estimates preferences and corrects for sample selection bias when the selection process is a two-sided matching game; i.e., a matching of students to colleges.
The structural model consists of a selection and an outcome equation. The Selection Equation
determines which matches are observed () and which are not (
).
Here, is a vector of latent valuations of all feasible matches, ie observed and
unobserved, and
is the Iverson bracket.
A match is observed if its match valuation is in the set of valuations
that satisfy the equilibrium condition (see Sorensen, 2007).
The match valuation
is a linear function of
, a matrix of characteristics for
all feasible matches, and
, a vector of random errors.
is a paramter
vector to be estimated.
The Outcome Equation determines the outcome for observed matches. The dependent
variable can either be continuous or binary, dependent on the value of the binary
argument. In the binary case, the dependent variable is determined by a threshold
rule for the latent variable
.
Here, is a linear function of
, a matrix of characteristics for observed
matches, and
, a vector of random errors.
is a paramter vector to
be estimated.
The structural model imposes a linear relationship between the error terms of both equations
as , where
is a vector of random errors and
is the covariance paramter to be estimated. If
were zero, the marginal distributions
of
and
would be independent and the selection problem would vanish.
That is, the observed outcomes would be a random sample from the population of interest.
stabit2( OUT = NULL, SEL = NULL, colleges = NULL, students = NULL, outcome = NULL, selection, binary = FALSE, niter, gPrior = FALSE, censored = 1, thin = 1, nCores = max(1, detectCores() - 1), verbose = FALSE, ... )
stabit2( OUT = NULL, SEL = NULL, colleges = NULL, students = NULL, outcome = NULL, selection, binary = FALSE, niter, gPrior = FALSE, censored = 1, thin = 1, nCores = max(1, detectCores() - 1), verbose = FALSE, ... )
OUT |
data frame with characteristics of all observed matches, including
market identifier |
SEL |
optional: data frame with characteristics of all observed and unobserved matches, including
market identifier |
colleges |
character vector of variable names for college characteristics. These variables carry the same value for any college. |
students |
character vector of variable names for student characteristics. These variables carry the same value for any student. |
outcome |
formula for match outcomes. |
selection |
formula for match valuations. |
binary |
logical: if |
niter |
number of iterations to use for the Gibbs sampler. |
gPrior |
logical: if |
censored |
draws of the |
thin |
integer indicating the level of thinning in the MCMC draws. The default |
nCores |
number of cores to be used in parallel Gibbs sampling. |
verbose |
logical. When set to |
... |
. |
stabit2
returns a list of the estimation results with the following elements.
sigma |
numeric scalar: standard deviation fixed to 1. |
eta |
numeric vector: residuals of the selection equation. |
vcov |
List of variance covariance matrices for coefficients alpha and beta of selection and outcome equations. |
coefficients |
numeric vector: coefficients of selection and outcome equations. |
fitted.values |
numeric vector: fitted values for outcome data. |
residuals |
numeric vector: residuals of the outcome equation. |
df |
integer: degrees of freedom. |
binary |
logical: if |
formula |
estimated formula. |
call |
function call. |
method |
One of "Sorensen", "Klein" or "Klein-selection". Method "Sorensen" is used when a single selection equation is passed. It assumes an equal sharing rule for student and college utility. Method "Klein" is used when two selection equations (one for students, one for schools) and one outcome equations are passed. Method "Klein-selection" only models selection and therefore does not require an outcome equations. |
draws |
List of Gibbs sampling draws for alpha and beta coefficients. |
coefs |
Posterior means of the Gibbs sampling draws. |
variables |
List of data used in the estimation. |
Thilo Klein
Sorensen, M. (2007). How Smart is Smart Money? A Two-Sided Matching Model of Venture Capital. Journal of Finance, 62 (6): 2725-2762.
## --- SIMULATED EXAMPLE --- ## 1. Simulate two-sided matching data for 20 markets (m=20) with 100 students ## (nStudents=100) per market and 20 colleges with quotas of 5 students, each ## (nSlots=rep(5,20)). True parameters in selection and outcome equations are ## all equal to 1. xdata <- stabsim2(m=20, nStudents=100, nSlots=rep(5,20), verbose=FALSE, colleges = "c1", students = "s1", outcome = ~ c1:s1 + eta + nu, selection = ~ -1 + c1:s1 + eta ) head(xdata$OUT) ## 2. Correction for sorting bias when match valuations V are observed ## 2-a. Bias from sorting lm1 <- lm(y ~ c1:s1, data=xdata$OUT) summary(lm1) ## 2-b. Cause of the bias with(xdata$OUT, cor(c1*s1, eta)) ## 2-c. Correction for sorting bias lm2a <- lm(V ~ -1 + c1:s1, data=xdata$SEL); summary(lm2a) etahat <- lm2a$residuals[xdata$SEL$D==1] lm2b <- lm(y ~ c1:s1 + etahat, data=xdata$OUT) summary(lm2b) ## 3. Correction for sorting bias when match valuations V are unobserved ## 3-a. Run Gibbs sampler (when SEL is given) fit2 <- stabit2(OUT = xdata$OUT, SEL = xdata$SEL, outcome = y ~ c1:s1, selection = ~ -1 + c1:s1, niter=1000 ) ## 3-b. Alternatively: Run Gibbs sampler (when SEL is not given) fit2 <- stabit2(OUT = xdata$OUT, colleges = "c1", students = "s1", outcome = y ~ c1:s1, selection = ~ -1 + c1:s1, niter=1000 ) ## 4. Implemented methods ## 4-a. Get coefficients fit2 ## 4-b. Coefficient table summary(fit2) ## 4-c. Get marginal effects summary(fit2, mfx=TRUE) ## 4-d. Also try the following functions #coef(fit2) #fitted(fit2) #residuals(fit2) #predict(fit2, newdata=NULL) ## 5. Plot MCMC draws for coefficients plot(fit2)
## --- SIMULATED EXAMPLE --- ## 1. Simulate two-sided matching data for 20 markets (m=20) with 100 students ## (nStudents=100) per market and 20 colleges with quotas of 5 students, each ## (nSlots=rep(5,20)). True parameters in selection and outcome equations are ## all equal to 1. xdata <- stabsim2(m=20, nStudents=100, nSlots=rep(5,20), verbose=FALSE, colleges = "c1", students = "s1", outcome = ~ c1:s1 + eta + nu, selection = ~ -1 + c1:s1 + eta ) head(xdata$OUT) ## 2. Correction for sorting bias when match valuations V are observed ## 2-a. Bias from sorting lm1 <- lm(y ~ c1:s1, data=xdata$OUT) summary(lm1) ## 2-b. Cause of the bias with(xdata$OUT, cor(c1*s1, eta)) ## 2-c. Correction for sorting bias lm2a <- lm(V ~ -1 + c1:s1, data=xdata$SEL); summary(lm2a) etahat <- lm2a$residuals[xdata$SEL$D==1] lm2b <- lm(y ~ c1:s1 + etahat, data=xdata$OUT) summary(lm2b) ## 3. Correction for sorting bias when match valuations V are unobserved ## 3-a. Run Gibbs sampler (when SEL is given) fit2 <- stabit2(OUT = xdata$OUT, SEL = xdata$SEL, outcome = y ~ c1:s1, selection = ~ -1 + c1:s1, niter=1000 ) ## 3-b. Alternatively: Run Gibbs sampler (when SEL is not given) fit2 <- stabit2(OUT = xdata$OUT, colleges = "c1", students = "s1", outcome = y ~ c1:s1, selection = ~ -1 + c1:s1, niter=1000 ) ## 4. Implemented methods ## 4-a. Get coefficients fit2 ## 4-b. Coefficient table summary(fit2) ## 4-c. Get marginal effects summary(fit2, mfx=TRUE) ## 4-d. Also try the following functions #coef(fit2) #fitted(fit2) #residuals(fit2) #predict(fit2, newdata=NULL) ## 5. Plot MCMC draws for coefficients plot(fit2)
Simulate individual-level data for one-sided matching markets.
stabsim(m, ind, seed = 123, singles = NULL, gpm = 2)
stabsim(m, ind, seed = 123, singles = NULL, gpm = 2)
m |
integer indicating the number of markets to be simulated. |
ind |
integer (or vector) indicating the number of individuals per group. |
seed |
integer setting the state for random number generation. Defaults to |
singles |
integer giving the number of one-group markets. |
gpm |
integer giving the number of groups per market. |
stabsim
returns a data frame with the randomly generated variables
mimicking those in dataset baac00
.
m.id |
categorical: market identifier. |
g.id |
categorical: group identifier. |
wst |
binary: indicator taking the value 1 if last year was worse than the year before; 0 otherwise. |
R |
NA: group outcome is not simulated. It can be obtained using the |
Thilo Klein
## Coalitions [gpm := 2 !] ## Simulate one-sided matching data for 4 markets (m=4) with 2 groups ## per market (gpm=2) and 2 to 4 individuals per group (ind=2:4) idata <- stabsim(m=4, ind=2:4, seed=124, singles=2, gpm=2) ## Rommmates [ind := 2 !] ## Simulate one-sided matching data for 3 markets (m=3) with 3 groups ## per market (gpm=3) and 2 individuals per group (ind=2) idata <- stabsim(m=3, ind=2, seed=124, gpm=3)
## Coalitions [gpm := 2 !] ## Simulate one-sided matching data for 4 markets (m=4) with 2 groups ## per market (gpm=2) and 2 to 4 individuals per group (ind=2:4) idata <- stabsim(m=4, ind=2:4, seed=124, singles=2, gpm=2) ## Rommmates [ind := 2 !] ## Simulate one-sided matching data for 3 markets (m=3) with 3 groups ## per market (gpm=3) and 2 individuals per group (ind=2) idata <- stabsim(m=3, ind=2, seed=124, gpm=3)
Simulate data for two-sided matching markets. In the simulation for the
Sorensen (2007) model with one selection equation, an equal sharing rule of
is used.
stabsim2( m, nStudents, nColleges = length(nSlots), nSlots, colleges, students, outcome, selection, binary = FALSE, seed = 123, verbose = TRUE )
stabsim2( m, nStudents, nColleges = length(nSlots), nSlots, colleges, students, outcome, selection, binary = FALSE, seed = 123, verbose = TRUE )
m |
integer indicating the number of markets to be simulated. |
nStudents |
integer indicating the number of students per market. |
nColleges |
integer indicating the number of colleges per market. |
nSlots |
vector of length |
colleges |
character vector of variable names for college characteristics. These variables carry the same value for any college. |
students |
character vector of variable names for student characteristics. These variables carry the same value for any student. |
outcome |
formula for match outcomes. |
selection |
formula for match valuations. |
binary |
logical: if |
seed |
integer setting the state for random number generation. Defaults to |
verbose |
. |
stabsim2
returns a list with the following items.
OUT |
|
SEL |
|
SELc |
|
SELs |
Thilo Klein
## Simulate two-sided matching data for 2 markets (m=2) with 10 students ## (nStudents=10) per market and 3 colleges (nColleges=3) with quotas of ## 2, 3, and 5 students, respectively. xdata <- stabsim2(m=2, nStudents=10, nSlots=c(2,3,5), verbose=FALSE, colleges = "c1", students = "s1", outcome = ~ c1:s1 + eta + nu, selection = ~ -1 + c1:s1 + eta ) head(xdata$OUT) head(xdata$SEL)
## Simulate two-sided matching data for 2 markets (m=2) with 10 students ## (nStudents=10) per market and 3 colleges (nColleges=3) with quotas of ## 2, 3, and 5 students, respectively. xdata <- stabsim2(m=2, nStudents=10, nSlots=c(2,3,5), verbose=FALSE, colleges = "c1", students = "s1", outcome = ~ c1:s1 + eta + nu, selection = ~ -1 + c1:s1 + eta ) head(xdata$OUT) head(xdata$SEL)
Implements an algorithm for the house allocation problem proposed by Abdulkadiroglu and Sonmez (1999) for a matching problem in which there are both vacant houses and existing tenants.
ttc( nStudents = ncol(s.prefs), nHouses = length(houses), s.prefs, houses, priority = NULL, seed = NULL )
ttc( nStudents = ncol(s.prefs), nHouses = length(houses), s.prefs, houses, priority = NULL, seed = NULL )
nStudents |
integer indicating the number of students. Defaults to |
nHouses |
integer indicating the number of houses. Defaults to |
s.prefs |
matrix of dimension |
houses |
vector of length |
priority |
(Optional) vector of length |
seed |
(Optional) integer setting the state for random number generation. Defaults to seed = NULL |
ttc
returns a data frame of the matching of students (int) to houses (obj) for the house allocation problem based on the Top-Trading-Cycles algorithm.
Thilo Klein, Alexander Sauer
Abdulkadiroglu, A. and T. Sonmez (1999). House Allocation with Existing Tenants. Journal of Economic Theory, 88 (2): 233-260.
Shapley, L. and H. Scarf (1974). On Cores and Indivisibility. Journal of Mathematical Economics, 1(1): 23-37.
## 1-a. Generate matrix of individuals' preference rankings over objects, ## a.k.a. Rank Order Lists (ROL). s.prefs <- matrix(c(3,2,4,1, # ROL of student 1 3,5,6, NA, 3,1, NA,NA, 2,5,6,4, 1,3,2,NA, 2,4,5,6), nrow = 4, ncol = 6, byrow = FALSE) ## 1-b. Generate vector of house occupation objects ('obj') and their owners ('ind') houses <- 1:6 ## 1-c. Find assignment based on TTC algorithm ttc(s.prefs = s.prefs, houses = houses, nHouses = 6, priority = 1:6) ## 2-a.Compare the example in the paper Abdulkadiroglu et al. (1999) ## on page 246-248 (section 5.1 An Example): ## generate matrix of students' preference rankings over houses, a.k.a. Rank Order Lists (ROL) s.prefs <- matrix(c(2,6,5,1,4,3,7,NA, 7,1,6,5,4,3,2,NA, 2,1,4,7,3,6,5,NA, 2,4,3,6,1,7,5,NA, 4,3,7,1,2,5,6,NA), byrow = FALSE, ncol= 5) ## 2-b. Generate house occupation, so student 1 lives in house 1, ..., student 4 lives in house 4 ## and the other houses are vacant. houses <- c(1,2,3,4,NA,NA,NA,NA) ## 2-c. Generate priority ordering priority <- 1:5 ## 2-d. Find assigment ttc(s.prefs = s.prefs, houses = houses, priority = priority)
## 1-a. Generate matrix of individuals' preference rankings over objects, ## a.k.a. Rank Order Lists (ROL). s.prefs <- matrix(c(3,2,4,1, # ROL of student 1 3,5,6, NA, 3,1, NA,NA, 2,5,6,4, 1,3,2,NA, 2,4,5,6), nrow = 4, ncol = 6, byrow = FALSE) ## 1-b. Generate vector of house occupation objects ('obj') and their owners ('ind') houses <- 1:6 ## 1-c. Find assignment based on TTC algorithm ttc(s.prefs = s.prefs, houses = houses, nHouses = 6, priority = 1:6) ## 2-a.Compare the example in the paper Abdulkadiroglu et al. (1999) ## on page 246-248 (section 5.1 An Example): ## generate matrix of students' preference rankings over houses, a.k.a. Rank Order Lists (ROL) s.prefs <- matrix(c(2,6,5,1,4,3,7,NA, 7,1,6,5,4,3,2,NA, 2,1,4,7,3,6,5,NA, 2,4,3,6,1,7,5,NA, 4,3,7,1,2,5,6,NA), byrow = FALSE, ncol= 5) ## 2-b. Generate house occupation, so student 1 lives in house 1, ..., student 4 lives in house 4 ## and the other houses are vacant. houses <- c(1,2,3,4,NA,NA,NA,NA) ## 2-c. Generate priority ordering priority <- 1:5 ## 2-d. Find assigment ttc(s.prefs = s.prefs, houses = houses, priority = priority)
Implements the school matching algorithm proposed in Abdulkadiroglu and Sonmez (2003) for a matching problem
in which both sides have preferences. Missing preferences are handled in the following ways: Suppose that a student only ranked colleges that are already matched
to other students. This student is removed from the matching process and a list with all unmatchable students is printed.
If full_return
is set to TRUE
, a vector with this students is returned as well.
Now suppose during the matching process a student points to a college that still has capacities but does not rank any more students.
We assume now that the college is indifferent over all other students (so we do not allow for free capacieties) and we match the student who wants to go there to the college.
ttc2( nStudents = ncol(s.prefs), nColleges = ncol(c.prefs), s.prefs = NULL, c.prefs = NULL, nSlots = NULL, priority = NULL, seed = NULL, full_return = FALSE, verbose = FALSE )
ttc2( nStudents = ncol(s.prefs), nColleges = ncol(c.prefs), s.prefs = NULL, c.prefs = NULL, nSlots = NULL, priority = NULL, seed = NULL, full_return = FALSE, verbose = FALSE )
nStudents |
integer indicating the number of students in the matching problem. Defaults to |
nColleges |
integer indicating the number of colleges in the matching problem. Defaults to |
s.prefs |
matrix of dimension |
c.prefs |
matrix of dimension |
nSlots |
vector of length |
priority |
(Optional) vector of length |
seed |
(Optional) integer setting the state for random number generation. Defaults to seed = NULL |
full_return |
(Optinal) If |
verbose |
logical. When set to |
ttc2
returns a data frame of the matching of students (ind) to colleges (obj) for the school market problem based on the Top-Trading-Cycles algorithm.
Thilo Klein, Alexander Sauer
Abdulkadiroglu, A. and T. Sonmez (2003). School Choice: A Mechanism Design Approach. American Economic Review, 93 (3): 729-747.
## 1-a. Compare example from the Abdulkadiroglu et al. (2003) (in the Appendix, page 742-744) ## 1-b. Generate matrix of students' preference rankings over schools, a.k.a. Rank Order Lists (ROL) s.prefs <- matrix(c( 2,1,3,4, 1,2,3,4, 3,2,1,4, 3,4,1,2, 1,3,4,2, 4,1,2,3, 1,2,3,4, 1,2,4,3), byrow = FALSE, ncol = 8) ## 1-c. Generate matrix of schools' preference rankings over students, a.k.a. Rank Order Lists (ROL) c.prefs <- matrix(c( 1,2,3,4,5,6,7,8, 3,5,4,8,7,2,1,6, 5,3,1,7,2,8,6,4, 6,8,7,4,2,3,5,1), byrow = FALSE, ncol = 4) ## 1-d. Generate capacities nSlots <- c(2,2,3,3) ## 1-e. Find assignment based on TTC algorithm ttc2(s.prefs = s.prefs, c.prefs = c.prefs, nSlots = nSlots) ## 2-a. Generate college preferences with college 1 only ranking student 1 c.prefs <- matrix(c( 1,rep(NA,7), 3,5,4,8,7,2,1,6, 5,3,1,7,2,8,6,4, 6,8,7,4,2,3,5,1), byrow = FALSE, ncol = 4) ## 2-b. Find assignment based on TTC algorithm ttc2(s.prefs = s.prefs, c.prefs = c.prefs, nSlots = nSlots, priority = 1:8) ## If all schools have the same preferences the two sided ttc and the serial dictator yield ## the same outcome if the preferences are taken to be the prioirty order for the serial dictator # Preferences are the same for all schools: c.prefs <- matrix(c( 5,3,1,7,2,8,6,4, 5,3,1,7,2,8,6,4, 5,3,1,7,2,8,6,4, 5,3,1,7,2,8,6,4), byrow = FALSE, ncol = 4) priority <- c.prefs[,1] match_ttc <- ttc2(s.prefs = s.prefs, c.prefs = c.prefs, nSlots = nSlots) match_sd <- rsd(prefs = s.prefs, priority = priority, nSlots = nSlots) all(match_ttc == match_sd)
## 1-a. Compare example from the Abdulkadiroglu et al. (2003) (in the Appendix, page 742-744) ## 1-b. Generate matrix of students' preference rankings over schools, a.k.a. Rank Order Lists (ROL) s.prefs <- matrix(c( 2,1,3,4, 1,2,3,4, 3,2,1,4, 3,4,1,2, 1,3,4,2, 4,1,2,3, 1,2,3,4, 1,2,4,3), byrow = FALSE, ncol = 8) ## 1-c. Generate matrix of schools' preference rankings over students, a.k.a. Rank Order Lists (ROL) c.prefs <- matrix(c( 1,2,3,4,5,6,7,8, 3,5,4,8,7,2,1,6, 5,3,1,7,2,8,6,4, 6,8,7,4,2,3,5,1), byrow = FALSE, ncol = 4) ## 1-d. Generate capacities nSlots <- c(2,2,3,3) ## 1-e. Find assignment based on TTC algorithm ttc2(s.prefs = s.prefs, c.prefs = c.prefs, nSlots = nSlots) ## 2-a. Generate college preferences with college 1 only ranking student 1 c.prefs <- matrix(c( 1,rep(NA,7), 3,5,4,8,7,2,1,6, 5,3,1,7,2,8,6,4, 6,8,7,4,2,3,5,1), byrow = FALSE, ncol = 4) ## 2-b. Find assignment based on TTC algorithm ttc2(s.prefs = s.prefs, c.prefs = c.prefs, nSlots = nSlots, priority = 1:8) ## If all schools have the same preferences the two sided ttc and the serial dictator yield ## the same outcome if the preferences are taken to be the prioirty order for the serial dictator # Preferences are the same for all schools: c.prefs <- matrix(c( 5,3,1,7,2,8,6,4, 5,3,1,7,2,8,6,4, 5,3,1,7,2,8,6,4, 5,3,1,7,2,8,6,4), byrow = FALSE, ncol = 4) priority <- c.prefs[,1] match_ttc <- ttc2(s.prefs = s.prefs, c.prefs = c.prefs, nSlots = nSlots) match_sd <- rsd(prefs = s.prefs, priority = priority, nSlots = nSlots) all(match_ttc == match_sd)
Implements the Top Trading Cycle and Chains algorithm proposed by Roth et al. (2004) for the kidney exchange problem. The algorithm requires a rule to determine which chain will be used if there is more than one possibility. The chosen rule is to search for the longest chain and remove it from the problem (even the first kidney which was unassigned).
ttcc(nPatients = ncol(prefs), prefs, priority = NULL, seed = NULL)
ttcc(nPatients = ncol(prefs), prefs, priority = NULL, seed = NULL)
nPatients |
integer indicating the number of patient/donor-pairs in the matching problem. Defaults to |
prefs |
matrix of dimension ( |
priority |
(Optional) vector of length |
seed |
(Optional) integer setting the state for random number generation. Defaults to seed = NULL |
ttcc
returns a list with the matching and a vector containing the patients who are assigned to the waiting list. The matching comprises a data frame of the operations to be performed between patient-donor pairs (ind-obj).
Thilo Klein, Alexander Sauer
Roth, A.; T. Sonmez; U. Unver (2004). Kidney Exchange. Quarterly Journal of Economics, 119 (2): 457-488.
## Compare Example 1 from Roth et al. (2004) on page 469 - 475 ## generate matrix of patients' preference rankings over kidneys, a.k.a. Rank Order Lists (ROL) prefs <- matrix(c( 9,10, 1,NA,NA,NA,NA, 11, 3, 5, 6, 2,NA,NA, 2, 4, 5, 6, 7, 8,13, 5, 9, 1, 8,10, 3,13, 3, 7,11, 4, 5,NA,NA, 3, 5, 8, 6,NA,NA,NA, 6, 1, 3, 9,10, 1,13, 6, 4,11, 2, 3, 8,NA, 3,11,13,NA,NA,NA,NA, 11, 1, 4, 5, 6, 7,13, 3, 6, 5,11,NA,NA,NA, 11, 3, 9, 8,10,12,NA), byrow = FALSE, ncol = 12) priority <- 1:12 ttcc(prefs = prefs, priority = priority) ## The final matching differs slightly because in Round 3 another chain is chosen due to a different ## decision rule (compare Figure 3, p472. Here W1 instead of W2 is chosen)
## Compare Example 1 from Roth et al. (2004) on page 469 - 475 ## generate matrix of patients' preference rankings over kidneys, a.k.a. Rank Order Lists (ROL) prefs <- matrix(c( 9,10, 1,NA,NA,NA,NA, 11, 3, 5, 6, 2,NA,NA, 2, 4, 5, 6, 7, 8,13, 5, 9, 1, 8,10, 3,13, 3, 7,11, 4, 5,NA,NA, 3, 5, 8, 6,NA,NA,NA, 6, 1, 3, 9,10, 1,13, 6, 4,11, 2, 3, 8,NA, 3,11,13,NA,NA,NA,NA, 11, 1, 4, 5, 6, 7,13, 3, 6, 5,11,NA,NA,NA, 11, 3, 9, 8,10,12,NA), byrow = FALSE, ncol = 12) priority <- 1:12 ttcc(prefs = prefs, priority = priority) ## The final matching differs slightly because in Round 3 another chain is chosen due to a different ## decision rule (compare Figure 3, p472. Here W1 instead of W2 is chosen)