forked from igorcesarec/math-econ-code_masterclass
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPAM.R
32 lines (24 loc) · 970 Bytes
/
PAM.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#################################################
### Optimal Transport Methods in Economics ###
#################################################
########## Alfred Galichon ##########
#################################################
########## Princeton University Press ##########
#################################################
#
#
#################################################
## PE 4.1: Positive Assortative Matching ##
#################################################
cdf_P = punif
quantile_P = qunif
cdf_P = pnorm
quantile_Q = qnorm
Phi = function(x,y) (x*y)
dPhi_dx = function(x,y) (y)
dPhi_dy = function(x,y) (x)
Tx = function (x) (quantile_Q(cdf_P(x)))
Tinvy = function (y) (quantile_P(cdf_Q(y)))
ux = function(x) (integrate(f = function(z) (dPhi_dx(z,Tx(z))),lower = 0,upper = x )$value)
vy = function(y) (integrate(f = function(z) (dPhi_dy(Tinvy(z),z)),lower = Tx(0),upper = y )$value
) - Phi(0,Tx(0))