estimate.affinity.matrix {affinitymatrix} | R Documentation |
Estimate Dupuy and Galichon's model
Description
This function estimates the affinity matrix of the matching model of Dupuy and Galichon (2014), performs the saliency analysis and the rank tests. The user must supply a matched sample that is treated as the equilibrium matching of a bipartite one-to-one matching model without frictions and with Transferable Utility. For the sake of clarity, in the documentation we take the example of the marriage market and refer to "men" as the observations on one side of the market and to "women" as the observations on the other side. Other applications may include matching between CEOs and firms, firms and workers, buyers and sellers, etc.
Usage
estimate.affinity.matrix(
X,
Y,
w = rep(1, N),
A0 = matrix(0, nrow = Kx, ncol = Ky),
lb = matrix(-Inf, nrow = Kx, ncol = Ky),
ub = matrix(Inf, nrow = Kx, ncol = Ky),
pr = 0.05,
max_iter = 10000,
tol_level = 1e-06,
scale = 1,
nB = 2000,
verbose = TRUE
)
Arguments
X |
The matrix of men's traits. Its rows must be ordered so that the
i-th man is matched with the i-th woman: this means that |
Y |
The matrix of women's traits. Its rows must be ordered so that the
i-th woman is matched with the i-th man: this means that |
w |
A vector of sample weights with length |
A0 |
A vector or matrix with |
lb |
A vector or matrix with |
ub |
A vector or matrix with |
pr |
A probability indicating the significance level used to compute
bootstrap two-sided confidence intervals for |
max_iter |
An integer indicating the maximum number of iterations in the
Maximum Likelihood Estimation. See |
tol_level |
A positive real number indicating the tolerance level in the
Maximum Likelihood Estimation. See |
scale |
A positive real number indicating the scale of the model. Defaults to 1. |
nB |
An integer indicating the number of bootstrap replications used to
compute the confidence intervals of |
verbose |
If |
Value
The function returns a list with elements: X
, the demeaned and
rescaled matrix of men's traits; Y
, the demeaned and rescaled
matrix of men's traits; fx
, the empirical marginal distribution of
men; fy
, the empirical marginal distribution of women;
Aopt
, the estimated affinity matrix; sdA
, the standard
errors of Aopt
; tA
, the Z-test statistics of Aopt
;
VarCovA
, the full variance-covariance matrix of Aopt
;
rank.tests
, a list with all the summaries of the rank tests on
Aopt
; U
, whose columns are the left-singular vectors of
Aopt
; V
, whose columns are the right-singular vectors of
Aopt
; lambda
, whose elements are the singular values of
Aopt
; UCI
, whose columns are the lower and the upper bounds
of the confidence intervals of U
; VCI
, whose columns are
the lower and the upper bounds of the confidence intervals of V
;
lambdaCI
, whose columns are the lower and the upper bounds of the
confidence intervals of lambda
; df.bootstrap
, a data frame
resulting from the nB
bootstrap replications and used to infer the
empirical distribution of the estimated objects.
See Also
Dupuy, Arnaud, and Alfred Galichon. "Personality traits and the marriage market." Journal of Political Economy 122, no. 6 (2014): 1271-1319.
Examples
# Parameters
Kx = 4; Ky = 4; # number of matching variables on both sides of the market
N = 200 # sample size
mu = rep(0, Kx+Ky) # means of the data generating process
Sigma = matrix(c(1, 0.326, 0.1446, -0.0668, 0.5712, 0.4277, 0.1847, -0.2883,
0.326, 1, -0.0372, 0.0215, 0.2795, 0.8471, 0.1211, -0.0902,
0.1446, -0.0372, 1, -0.0244, 0.2186, 0.0636, 0.1489,
-0.1301, -0.0668, 0.0215, -0.0244, 1, 0.0192, 0.0452,
-0.0553, 0.2717, 0.5712, 0.2795, 0.2186, 0.0192, 1, 0.3309,
0.1324, -0.1896, 0.4277, 0.8471, 0.0636, 0.0452, 0.3309, 1,
0.0915, -0.1299, 0.1847, 0.1211, 0.1489, -0.0553, 0.1324,
0.0915, 1, -0.1959, -0.2883, -0.0902, -0.1301, 0.2717,
-0.1896, -0.1299, -0.1959, 1),
nrow=Kx+Ky) # (normalized) variance-covariance matrix of the
# data generating process
labels_x = c("Educ.", "Age", "Height", "BMI") # labels for men's matching variables
labels_y = c("Educ.", "Age", "Height", "BMI") # labels for women's matching variables
# Sample
data = MASS::mvrnorm(N, mu, Sigma) # generating sample
X = data[,1:Kx]; Y = data[,Kx+1:Ky] # men's and women's sample data
w = sort(runif(N-1)); w = c(w,1) - c(0,w) # sample weights
# Main estimation
res = estimate.affinity.matrix(X, Y, w = w, nB = 500)
# Summarize results
show.affinity.matrix(res, labels_x = labels_x, labels_y = labels_y)
show.diagonal(res, labels = labels_x)
show.test(res)
show.saliency(res, labels_x = labels_x, labels_y = labels_y,
ncol_x = 2, ncol_y = 2)
show.correlations(res, labels_x = labels_x, labels_y = labels_y,
label_x_axis = "Husband", label_y_axis = "Wife", ndims = 2)