Multivariate Ranks and Quantiles using Optimal Transport: Consistency, Rates, and Nonparametric Testing

Abstract: In this paper we study multivariate ranks and quantiles, defined using the theory of optimal transport, and build on the work of Chernozhukov et al.(2017) and Hallin et al.(2021). We study the characterization, computation and properties of the multivariate rank and quantile functions and their empirical counterparts. We derive the uniform consistency of these empirical estimates to their population versions, under certain assumptions. In fact, we prove a Glivenko-Cantelli type theorem that shows the asymptotic stability of the empirical rank map in any direction. Under mild structural assumptions, we provide global and local rates of convergence of the empirical quantile and rank maps. We also provide a sub-Gaussian tail bound for the global L_2-loss of the empirical quantile function. Further, we propose tuning parameter-free multivariate nonparametric tests -- a two-sample test and a test for mutual independence -- based on our notion of multivariate quantiles/ranks. Asymptotic consistency of these tests are shown and the rates of convergence of the associated test statistics are derived, both under the null and alternative hypotheses.

\section{Introduction}\label{sec:Intro}
Suppose that $X$ is a random vector in $\mathbb{R}^d$, for $d \ge 1$, with distribution $\nu$. When $d=1$, the rank and quantile functions of $X$ are defined as $F$ and $F^{-1}$ (the inverse\footnote{$F^{-1}(p) := \inf \left\{x\in {\mathbb  {R}}:p\leq F(x)\right\}$.} of $F$), respectively, where $F$ is the cumulative distribution function of $X$. Moreover, when $d=1$, quantile and rank functions and their empirical counterparts are ubiquitous in statistics and form the backbone of what is now known as classical nonparametrics (see e.g.,~\cite{Lehmann75}) and are important tools for inference (see e.g.,~\cite{HW03} and the references therein). In this paper we study many properties of {\it multivariate} (empirical) ranks and quantiles defined using the theory of optimal transport, as introduced in~\citet{Cher17}.

Unlike the real line, the $d$-dimensional Euclidean space $\mathbb{R}^d$, for $d \ge 2$, has no natural ordering. This has been a major impediment in defining analogues of quantiles and ranks in $\mathbb{R}^d$, for $d \ge 2$. Several notions of multivariate quantiles have been proposed in the statistical literature --- some based on data depth ideas (see e.g.,~\cite{Oja83, Liu92, Zou03}) and some based on geometric ideas (see e.g.,~\cite{Chaud96, Kol97, HPS10}); see~\cite{Serfling10} and~\cite{dCHM} for recent surveys on this topic. However, most of these notions do not enjoy the numerous appealing properties that make univariate ranks and quantiles so useful. For example, most of these notions can lead to multivariate quantiles that may take values outside the support of the distribution $\nu$.

To motivate the notions of ranks and quantiles based on the theory of optimal transportation (the subject of our study) let us first consider the case when $d=1$. Suppose that $X \sim \nu$ has a continuous distribution function $F$. An important property of the one-dimensional rank function $F$ is that $F(X) \sim \mu$ where $\mu \equiv $ Uniform$([0,1])$, i.e., $F$ {\it transports} (see \eqref{eq:PushMeasure-1} for the formal definition) the distribution $\nu$ to $\mu$. Similarly, the quantile function $F^{-1}$ (which is the inverse of the rank map) transports $\mu$ to $\nu$, i.e., $F^{-1}(U) \sim X$ where $U \sim \mu$. In fact, it can be easily shown that the quantile function $F^{-1}$ (or $F$) is the unique monotone nondecreasing map that transports $\mu$ to $\nu$ (or $\nu$ to $\mu$). Moreover, if $\nu$ has finite second moment, it can be shown that $F^{-1}$ is the almost everywhere (a.e.) unique map (on $[0,1]$) that transports $\mu$ to $\nu$ and minimizes the expected squared-error cost, i.e.,
\begin{equation}\label{eq:Q-F}
F^{-1} = \arg \min_{T: T(U) \sim \nu} \mathbb{E} [(U - T(U))^2], \qquad \mbox{where} \;\; U \sim \mu
\end{equation}
and the minimization is over all functions $T$ that transport $\mu$ to $\nu$ (and thus the connection to optimal transportation); see Section~\ref{sec:Q-R} for the details. The rank function $F$ also minimizes the expected squared-error cost where now one considers maps that transport $\nu$ to $\mu$.

The multivariate quantile and rank functions using optimal transportation essentially extend the above properties of univariate rank and quantile functions. Now let $\mu$ be an absolutely continuous probability measure with respect to (w.r.t.) Lebesgue measure on $\mathbb{R}^d$ ($d \ge 1$) and supported on a compact convex set $\mathcal{S}$; e.g., we can take $\mu$ to be Uniform$([0,1]^d)$ or uniform on the ball of radius one around $0 \in \mathbb{R}^d$. We often refer to $\mu$ as the \emph{reference distribution} and will define quantiles relative to this reference measure (when $d=1$ we usually take $\mu$ to be Uniform$([0,1])$). Let $\nu$ be another probability measure in $\mathbb{R}^d$ which we term as the \emph{target distribution}; we think of $\nu$ as the population distribution of the observed data. We define the {\it multivariate quantile function} $Q: \mathcal{S} \to \mathbb{R}^d$ of $\nu$ w.r.t.~$\mu$ as the solution to the following optimization problem:
\begin{equation}\label{eq:Multi-Q-F}
Q := \arg \min_{T: T(U) \sim \nu} \mathbb{E} [\|U - T(U)\|^2], \qquad \mbox{where} \;\; U \sim \mu,
\end{equation}
and the minimization is over all functions $T:\mathcal{S} \to \mathbb{R}^d$ that transport $\mu$ to $\nu$; cf.~\eqref{eq:Q-F} and see Section~\ref{sec:Q-R} for the details. Here $\|\cdot \|$ denotes the usual Euclidean norm in $\mathbb{R}^d$. Moreover, if $\nu$ does not have a finite second moment, the above optimization problem might not be meaningful but the notion of multivariate quantiles (using optimal transportation) can still be defined as follows. By Brenier-McCann's theorem (see Theorem~\ref{thm:Brenier}), there exists an a.e.~unique map $Q: \mathcal{S} \to \mathbb{R}^d$ --- which we define as the quantile function of $\nu$ (w.r.t.~the reference measure $\mu$) --- that is the gradient of a convex function\footnote{Note that a convex function is differentiable a.e.~in its domain.} and transports $\mu$ to $\nu$; i.e., $Q(U) \sim \nu$ where $U \sim \mu$. Further, it can be shown that (see Theorem~\ref{thm:Brenier}) when~\eqref{eq:Multi-Q-F} is meaningful, the above two notions yield the same function $Q$. Note that when $d=1$, the gradient of a convex function is a monotone nondecreasing function and thus the above two characterizations of the quantile function $Q$ are the exact analogues of the one-dimensional case described in the previous paragraph.

Although the rank function can be intuitively thought of as the inverse of the quantile function, such an inverse might not always exist --- especially when $\nu$ is a discrete probability measure (which arises naturally when defining the empirical rank map). In Section~\ref{sec:Q-R} we tackle this issue and use the notion of the Legendre-Fenchel transform (see Section~\ref{sec:prelim}) to define the rank function. In Lemma~\ref{lem:QRrelation} we show that the defined notion of rank function is a right inverse of the quantile function a.e.~if the reference and the target distributions are absolutely continuous. Furthermore, Proposition~\ref{thm:Q_prop} shows that, under mild regularity conditions, the quantile and rank functions are continuous bijections (i.e., homeomorphisms) between the (interiors of the) supports of the reference and target distributions and they are inverses of each other. It is worth noting that for $d=1$, a continuous bijective rank map corresponds to the distribution function being continuous and strictly increasing. Lemma~\ref{lem:Monotonicity} states that the one-dimensional projection of the rank map, along any direction, is nondecreasing. Further, in Lemma~\ref{cor:RankProp} we show that, when the rank map is a homeomorphism, it approaches a limit along every ray that depends only on the geometry of $\mathcal{S}$ (and not on $\nu$).

Given $n$ i.i.d.~random vectors $X_1,\ldots, X_n$ in $\mathbb{R}^d$, in Sections~\ref{sec:Emp-Q-R} and~\ref{sec:Comp}, we discuss the characterization and computation (see Lemmas~\ref{lem:ExtremePt} and~\ref{lem:Char3}) of the empirical quantile and rank maps --- which are defined via~\eqref{eq:Multi-Q-F} but with $\nu$ replaced by the empirical distribution of the data. In particular, the empirical quantiles (and ranks) are obtained from the solution of a convex program with $n$ variables. An attractive property of the empirical ranks, when $d=1$, that makes ranks useful for statistical inference, is that they are distribution-free. Lemma~\ref{lem:Uniform} shows that a distribution-free version of multivariate ranks can be obtained by external randomization (also see Lemma~\ref{lem:Distfree}). Although our approach is very similar to that of~\cite{Cher17} there are subtle and important differences; in Section~\ref{sec:Comparison} we discuss these connections in detail. Some useful properties of the above defined quantile and rank functions, including (i) equivariance under orthogonal transformations (see Lemma~\ref{lem:LinTrans-2}), and (ii) decomposition when $X \sim \nu$ has mutually independent coordinates (see Proposition~\ref{prop:Indep}), are given in Section~\ref{sec:Q-R-Prop}.

In Section~\ref{sec:UnifConv} we state our first main theoretical result on the almost sure (a.s.) uniform convergence of the empirical quantile and rank maps to their population counterparts. An informal statement of this result is given below.

\textbf{Uniform convergence of empirical quantile and rank maps} (informal restatement of Theorem~\ref{thm:GCProp}): Suppose that $\mu$ is supported on a compact convex set $\mathcal{S}\subset \mathbb{R}^d$ with non-empty interior. Let $\mathcal{Y}$ be the support of $\nu$ and let $\{\hat{\nu}_n\}_{n\ge 1}$ be a sequence of random probability distributions converging weakly to $\nu$ a.s. Suppose that the quantile map $Q$ of $\nu$ (w.r.t.~$\mu$) is a continuous bijection from $\mathrm{Int}(\mathcal{S})$ (the interior of $\mathcal{S}$)  to $\mathrm{Int}(\mathcal{Y})$. Then, with probability (w.p.) 1, the empirical quantile and rank maps corresponding to $\hat{\nu}_n$ (w.r.t.~$\mu$) --- $\hat{Q}_n$ and $\hat{R}_n$ --- converge  uniformly to $Q$ and $R \equiv Q^{-1}$, respectively, over compacts in $\mathrm{Int}(\mathcal{S})$ and $\mathrm{Int}(\mathcal{Y})$. Moreover, if all the supporting hyperplanes of $\mathcal{S}$ touch its boundary at only one point, then, the empirical rank map $\hat{R}_n$ converges uniformly to $R = Q^{-1}$ over the whole of $\mathbb{R}^d$ a.s.; furthermore, w.p.~1, the tail limit of $\hat{R}_n$ stabilizes along any direction.

We list below some of the novelties of the above result (Theorem~\ref{thm:GCProp}).

\noindent \textbf{(i)} One of the main consequences of Theorem~\ref{thm:GCProp} is the a.s.~convergence of the empirical rank function on the whole of $\mathbb{R}^d$, under certain conditions on the support of the reference distribution $\mu$. This can indeed be thought of as a  generalization of the famous Glivenko-Cantelli theorem for rank functions when $d>1$. Moreover, our result does not need any boundedness assumption on the support of the target distribution $\nu$ and even applies when the second moment of $\nu$ is not finite. This is a major improvement over the corresponding result in \cite[Theorem 3.1]{Cher17}. Also,~\cite[Theorem 3.1]{Cher17} only shows in probability convergence compared to a.s.~convergence in Theorem~\ref{thm:GCProp}. Although~\citet{dCHM} show  the a.s.~convergence of the empirical \emph{center-outward rank functions}, our notion of ranks and quantiles are different from theirs. Furthermore, unlike \cite{dCHM}, $\mu$ can be supported on any compact convex domain with minor restrictions on its boundary. See Section~\ref{sec:Comparison} for a detailed discussion where we compare and contrast the notions of multivariate ranks and quantiles of \cite{Cher17} and~\cite{dCHM} with ours.

\noindent \textbf{(ii)} In Theorem~\ref{thm:GCProp}, one of the assumptions is that the quantile map $Q$ of $\nu$ (w.r.t.~$\mu$) is a homeomorphism (i.e., continuous bijection) from $\mathrm{Int}(\mathcal{S})$ to $\mathrm{Int}(\mathcal{Y})$. Proposition~\ref{thm:Q_prop} provides a sufficient condition for $Q$ to be a homeomorphism. It is shown that
when $\mathcal{S}$ and $\mathcal{Y}$ are convex sets and $\nu$ has bounded nonvanishing density on compacts contained in $\mathrm{Int}(\mathcal{Y})$, then,  $Q:\mathrm{Int}(\mathcal{S})\to \mathrm{Int}(\mathcal{Y})$ is indeed a homeomorphism. This is an improvement over the result in~\citet{Figalli18} which shows a similar result under the assumption that $\nu$ is supported on the whole of $\mathbb{R}^d$. Since \cite{dCHM} appeals to~\cite{Figalli18} for the consistency result of their center-outward ranks, their target distribution $\nu$ has to be supported on the whole of $\mathbb{R}^d$.

\noindent \textbf{(iii)} Our result (see \eqref{eq:Asymptot} of Theorem~\ref{thm:GCProp}) implies that when the population rank map is a homeomorphism, the tail limits of the estimated rank maps $\hat{R}_n$ depend neither on $\nu$ nor on $\mu$; rather they depend on the geometry of $\mathcal{S}$ --- the domain that  supports the reference distribution $\mu$. This is reminiscent of the case when $d=1$ where the limits of the distribution (rank) function towards $-\infty$ and $+\infty$ are always $0$ and $1$, respectively.

\noindent \textbf{(iv)} To prove Theorem~\ref{thm:GCProp}, one needs to develop tools that deal with the convergence of (sub)-gradients of a sequence of convex functions and their Legendre-Fenchel duals. These tools are summarized in three determinstic lemmas in  Section~\ref{sec:UnifConv}. Lemma~\ref{KeyLemma} demonstrates how the (sub)-gradients of a sequence of convex functions and their Legendre-Fenchel duals behave when the corresponding convex functions converge uniformly on some compact subset of $\mathbb{R}^d$. It sets the stage for the application of the last two lemmas in this section, namely~Lemmas~\ref{KeyLemma2} and~\ref{lem:UnifConv}. These results, proved using tools from convex analysis, might also be of independent interest.

Theorem~\ref{thm:GCProp} naturally leads to the following question: ``What is the pointwise rate of convergence of the empirical quantile and rank maps?". This is indeed a hard question and not much is known in the literature. We address this question in Section~\ref{sec:RateSec}. We consider Theorem~\ref{ppn:RateProp1} as a first step towards understanding the local behavior of transportation maps. In Theorem~\ref{ppn:RateProp1}, we show that the local  (uniform) rate of convergence of the empirical quantile and rank maps is tied to their local behavior under the $L_2$-loss. In the special case $\mu \equiv \nu$, in Corollary~\ref{thm:RateTheo}, we obtain an upper bound on this local uniform rate  using the rate of convergence of the $L_2$-Wasserstein distance between the empirical and the true measure $\nu$. The rate of convergence of the $L_2$-Wasserstein distance has been well-studied in the literature (see e.g.,~\cite{Tala1,Tala2,FG15,BL14,WB17}).

In Section~\ref{sec:Goodness-Fit-Test}, we investigate some statistical applications of the multivariate ranks and quantiles studied in this paper --- we propose methodology for nonparametric multivariate two-sample goodness-of-fit testing and testing of mutual independence.
In Section~\ref{sec:2S-Goodness-Fit-Test} we propose a test-statistic --- motivated by the Cram\'{e}r von-Mises one-sample statistic (when $d=1$) --- for two-sample testing, based on the empirical multivariate ranks and quantiles. In Section~\ref{sec:IndepTest} we propose a method for testing the mutual independence of the coordinates of a random vector, given i.i.d.~data. Applying the uniform convergence results of Theorem~\ref{thm:GCProp}, we prove the consistency of these proposed tests, i.e., the power of these tests converges to 1 under fairly general assumptions on the underlying distribution (see Propositions~\ref{lem:Power1} and~\ref{lem:Power2}). This leads to omnibus nonparametric tests that are computationally feasible, and being rank based, do not depend on moment assumptions on the underlying distribution (cf.~\cite{BF04, SR13, EquivRKHS13, SzekelyCorrDist07}). Further, being based on ranks, we suspect that these test statistics, properly normalized, may be (asymptotically) distribution-free --- in Section~\ref{sec:Simul} we provide simulation studies that illustrate this phenomenon.

The paper is organized as follows. We introduce notation and some basic notions from convex analysis and optimal transportation in Section~\ref{sec:prelim}. Section~\ref{sec:Q-R} defines the multivariate quantile and rank maps and their empirical counterparts and investigates some of their properties. The asymptotic results on the uniform a.s.~convergence of the empirical quantile and rank maps and their local rates of convergence are given in Section~\ref{sec:Asymptotics}. Two statistical applications --- multivariate two-sample testing and testing for mutual independence --- based on the studied multivariate ranks and quantiles are given in Section~\ref{sec:Goodness-Fit-Test}. The paper concludes with a discussion (Section~\ref{sec:Disc}). The proofs of our main results, some remarks and plots are given in Appendix~\ref{sec:Proofs}. Additional technical results used in the proofs are relegated to Appendix~\ref{Appendix-B}.

\section{Preliminaries}\label{sec:prelim}
We start with some notation and recall some important concepts from convex analysis that will be relevant for the rest of the paper. For $u, v \in \mathbb{R}^d$, we use $\langle u , v \rangle$ to denote the dot product of $u$ and $v$ and $\|\cdot\|$ denotes the usual Euclidean norm in $\mathbb{R}^d$. For $y_1, \ldots, y_k \in \mathbb{R}^d$ we write $\mathrm{Conv}(y_1,\ldots, y_k)$ to denote the convex hull of $\{y_1, \ldots, y_k\} \subset \mathbb{R}^d$. A {\it convex polyhedron} is the intersection of finitely many closed half-spaces. A {\it convex polytope} is the convex hull of a finite set of points. The interior, closure and boundary of a set $\mathcal{X} \subset \mathbb{R}^d$ will be denoted by Int($\mathcal{X}$), Cl($\mathcal{X}$), and Bd($\mathcal{X}$), respectively. The Lebesgue measure on $\mathbb{R}^d$ is denoted by $\lambda_d$. The Dirac delta measure at $x$ is  denoted by $\delta_x$. For $\delta >0$ and $x \in \mathbb{R}^d$, $B_{\delta}(x) := \{y \in \mathbb{R}^d: \|y - x\| < \delta\}$ denotes the open ball of radius $\delta$ around $x$. The set of natural numbers will be denoted by $\mathbb{N}$.

The {\it domain} of a function $f : \mathbb{R}^d \to \mathbb{R} \cup \{+\infty\}$, denoted by $\operatorname{dom}(f)$, is the set $\{x \in \mathbb{R}^d: f(x) < + \infty\}$. The function $f$ is called {\it proper} if $\operatorname{dom}(f) \ne \emptyset$. We say that $f$ is lower semi-continuous (l.s.c.) at $x_0 \in \mathbb{R}^d$ if $\liminf _{x\to x_{0}}f(x)\geq f(x_{0})$. For a proper function $f : \mathbb{R}^d \to \mathbb{R} \cup \{+\infty\}$, the {\it Legendre-Fenchel dual} (or convex conjugate or simply the dual) of $f$ is the proper function $f^* : \mathbb{R}^d \to \mathbb{R} \cup \{+\infty\}$ defined by
\begin{equation}\label{eq:LF-dual}
f^*(y) := \sup_{x \in \mathbb{R}^d} \left\{ \langle x,y\rangle - f(x) \right\}, \qquad \mbox{for all } y \in \mathbb{R}^d.
\end{equation}
It is well known that $f^*$ is a proper, l.s.c.~convex function. The Legendre-Fenchel duality theorem says that for a proper l.s.c.~convex function $f$, $(f^*)^* = f$. Given a convex function $f : \mathbb{R}^d \to \mathbb{R} \cup \{+\infty\}$ we define the \emph{subdifferential} set of $f$ at $x\in \operatorname{dom}(f)$ by $$\partial f(x) := \{\xi \in \mathbb{R}^d: f(x) + \langle y-x, \xi\rangle \le f(y), \quad \mbox{for all } y \in \mathbb{R}^d\}.$$ Any element in $\partial f(x)$ is called a \emph{subgradient} of $f$ at $x$.  If $f$ is differentiable at $x$ then $\partial f(x) = \{\nabla f(x)\}$.  We follow the convention that if $f(x)= + \infty$ for some $x\in \mathbb{R}^d$, then, $\partial f(x) = \emptyset$. Moreover, for $A \subset \mathbb{R}^d$, we use the following notation:
\begin{eqnarray*}
\partial f(A) & := &\{x \in \mathbb{R}^d: x \in \partial f(u) \;\; \mbox{for some}\;\; u \in A\}, \qquad \mbox{and} \\ (\partial f)^{-1}(A) &:= & \{u \in \mathbb{R}^d: x \in \partial f(u)\;\; \mbox{for some}\;\; x \in A\}.
\end{eqnarray*}
A convex function is a.e.~differentiable (w.r.t.~Lebesgue measure) on Int($\operatorname{dom}(f)$). As a consequence, a convex function is continuous in the interior of its domain.

For a convex function $f : \mathbb{R}^d \to \mathbb{R} \cup \{+\infty\}$ we sometimes just write $\nabla f(x)$ to denote the (sub)-differential of $f$ at $x$ with the understanding that when $f$ is not differentiable at $x$ we can take $\nabla f(x)$ to be any point in the set $\partial f(x)$. This avoids the need to deal with the set-valued function $\partial f$. However, sometimes we will need to view $\partial f$ as a multi-valued mapping, i.e., a mapping from $\mathbb{R}^d$ into the power set of $\mathbb{R}^d$, and we will use the notation $\partial f$ in that case. We will find the following results useful (see e.g.,~\cite[Proposition 2.4]{V03}).

\begin{lemma}[Characterization of subdifferential]\label{lem:SubD}
Let $f:\mathbb{R}^d \to \mathbb{R} \cup \{+ \infty\}$ be a proper l.s.c.~convex function. Then for all $x,y \in \mathbb{R}^d$,
\begin{equation}\label{eq:Charac-Sub}
\langle x,y\rangle = f(x) + f^*(y) \Longleftrightarrow y \in \partial f(x) \Longleftrightarrow x \in \partial f^*(y).
\end{equation}
\end{lemma}

\begin{remark}\label{rem:dualrem}
For a proper l.s.c.~convex function $f:\mathbb{R}^d \to \mathbb{R} \cup \{+ \infty\}$, using \eqref{eq:Charac-Sub}, one can see that
\begin{align}
\big\{y\in \mathbb{R}^d: y\in \partial f(x) \text{ for some }x\in \mathbb{R}^d\big\} &= \big\{y\in \mathbb{R}^d: x\in \partial f^{*}(y)\text{ for some }x\in \mathbb{R}^d \big\}\nonumber\\&= \big\{y\in \mathbb{R}^d: f^{*}(y)< +\infty\big\}
\end{align}
where the last equality follows since $\partial f^{*}(y) = \emptyset$ if and only if $f^{*}(y) = +\infty$.
\end{remark}
Throughout the paper, we will assume that all the convex functions that we will be dealing with are l.s.c.~Lemma~\ref{lem:SubD} shows a one-to-one relation between the subdifferential set of a convex function and its Legendre-Fenchel dual. For instance, if the domain of the Legendre-Fenchel dual of a convex function $f$ is bounded then Remark~\ref{rem:dualrem} shows that the subdifferentials of $f$ are contained in a  bounded set.
\begin{definition}[Set convergence]\label{bd:SetConv}
Let $K_1\subset K_2 \subset \ldots$ be an increasing sequence of sets in $\mathbb{R}^d$. We say that $K_n$ \emph{increases} to $K\subset \mathbb{R}^d$, and write $K_n \uparrow K$, if for any compact set $A \subset \mathrm{Int}(K)$ there exists $n_0=n_0(A) \in \mathbb{N}$ such that $A \subseteq K_n$ for all $n\geq n_0$.

\end{definition}
The above notion is slightly stronger than just assuming $K_1 \subset K_2 \subset \ldots$ and $\lim \inf_{n \to \infty} K_n = K$.

A supporting hyperplane of a set $S \in \mathbb{R}^{d}$ is a hyperplane that has both of the following two properties: (i) $S$ is entirely contained in one of the two closed half-spaces bounded by the hyperplane, and (ii) $S$ has at least one boundary-point on the hyperplane.

Let $\mu$ and $\nu$ be two Borel probability measures supported on $\mathcal{X} \subset \mathbb{R}^d$ and $\mathcal{Y}\subset \mathbb{R}^d$ respectively. The goal of optimal transport (Monge's problem), under the $L_2$-loss, is to find a measurable transport map $T \equiv T_{\mu;\nu} : \mathcal{X} \to \mathcal{Y}$ solving the (constrained) minimization problem
\begin{equation}\label{eq:Meas_Trans-1}
	\inf_T \int_{\mathcal{X}} \|x - T(x)\|^2 d\mu(x)  \qquad \quad \mbox{subject to }\quad T\#\mu  = \nu
\end{equation}
where the minimization is over $T$ (a {\it transport map}), a measurable map from $\mathcal{X}$ to $\mathcal{Y}$, and $T\#\mu$ is the {\it push forward} of $\mu$ by $T$, i.e.,
\begin{align}\label{eq:PushMeasure-1}
T\#\mu(B) = \mu(T^{-1}(B)), \qquad \mbox{for all } B \subset \mathcal{Y}\;\; \mbox{Borel}.
\end{align}
A map $T_{\mu;\nu}$ that attains the infimum in~\eqref{eq:Meas_Trans-1} is called an {\it optimal transport} map  from $\mu$ to $\nu$. We state an important result in this theory, namely Brenier-McCann's theorem (\cite{B91},~\cite{McCann95}); this result will be very useful to us. \begin{theorem}\label{thm:Brenier}
Let $\mu$ and $\nu$ be two Borel probability measures on $\mathbb{R}^d$. Suppose further that $\mu$ has a Lebesgue density. Then there exists a convex function $\psi: \mathbb{R}^d \to \mathbb{R} \cup \{+\infty\}$ whose gradient $G =  \nabla \psi : \mathbb{R}^d \to \mathbb{R}^d$ pushes $\mu$ forward to $\nu$. In fact, there exists only one such $G$ that arises as the gradient of a convex function, i.e., $G$ is unique $\mu$-a.e. Moreover, if $\mu$ and $\nu$ have finite second moments, $G$ uniquely minimizes Monge's problem~\eqref{eq:Meas_Trans-1}.

\end{theorem}
The above result implies that, for the $L_2$-loss, the solution of Monge's problem exists (if $\mu$ and $\nu$ have finite second moments), is ($\mu$-a.e.) unique, and is given by the {\it gradient of a convex function}. See Section~\ref{sec:OT} in the Appendix for a  brief introduction to the field of optimal transportation.

\section{Quantile and rank maps in $\mathbb{R}^d$ when $d \ge 1$}\label{sec:Q-R}
Suppose that $X \sim \nu$ is supported on $\mathcal{Y} \subset \mathbb{R}^d$. Let $\mu$ be a known absolutely continuous distribution on $\mathbb{R}^d$ (i.e., $\mu$ has a density w.r.t.~Lebesgue measure $\lambda_d$ on $\mathbb{R}^d$) with support $\mathcal{S}$ --- a compact convex subset of $\mathbb{R}^d$ with nonempty interior; e.g., we can take $\mu$ to be Uniform$([0,1]^d)$. Other natural choices of $\mu$ are the uniform distribution on the unit ball $B_1(0)$ in $\mathbb{R}^d$ (\cite{Cher17}), and the spherical uniform distribution ($V$ has the spherical uniform distribution if $V = L \varphi$ where $\varphi$ is  uniformly distributed on the unit sphere around $0 \in \mathbb{R}^d$  and  $L$ has the uniform distribution on the interval $[0,1]$ and $L$ and $\varphi$ are mutually independent); see~\cite{dCHM, Figalli18}.

In the following we define the multivariate {\it quantile} and {\it rank} maps for $\nu$ w.r.t.~the distribution $\mu$ using the theory of optimal transportation. We first define the quantile function for $\nu$ and then use it to define the rank map. Recall that, when $d=1$ the (univariate) quantile map $Q(\cdot)$ (for $\nu$) is the monotone nondecreasing map that pushes forward (i.e., transports) the uniform distribution on $[0, 1]$ to $\nu$; i.e., the quantile map $Q(\cdot)$ is the unique nondecreasing map such that if $U \sim $ Uniform($[0, 1]$), then $Q(U) \sim \nu$. This point of view will be the basis of our multivariate generalization of the notion of quantiles; also see~\cite{Galichon16, Galichon17, Cher17}. Our approach is essentially the same as outlined in~\cite{Cher17} although there are some important and subtle differences; see Section~\ref{sec:Comparison} for a detailed discussion.

\begin{definition}[Quantile function]\label{def:Quantile}
The quantile function of the probability measure $\nu$ (w.r.t.~$\mu$) is defined as the $\mu$-a.e.~unique map $Q :\mathcal{S} \to \mathbb{R}^d$ which pushes $\mu$ to $\nu$ and has the form
\begin{equation}\label{eq:Quantile}
Q := \nabla \psi
\end{equation}
where $\psi:\mathbb{R}^d \to \mathbb{R}\cup \{+ \infty\}$ is a convex function. We call such a $\psi(\cdot)$ a potential function.
\end{definition}
\begin{remark}[Uniqueness of $Q$]\label{rem:QUnique}
As the convex function $\psi$ in Definition~\ref{def:Quantile} need not be differentiable everywhere, there is a slight ambiguity in the definition of $Q$. When $\psi$ is not differentiable, say at $u \in \mathcal{S}$, we can define $Q(u)$ to be any element of the subdifferential set $\partial \psi(u)$ (see Section~\ref{sec:prelim} for its formal definition). As a convex function is differentiable a.e.~(on its domain) this convention does not affect the $\mu$-a.e.~uniqueness of $Q$. Further, this convention bypasses the need to define quantiles as a multi-valued map.
\end{remark}

The existence and $\mu$-a.e.~uniqueness of the quantile map $Q(\cdot)$, for any probability measure $\nu$ on $\mathbb{R}^d$, is guaranteed by Theorem~\ref{thm:Brenier}. Further, by Theorem~\ref{thm:Brenier}, if $\nu$ has finite second moment, then $Q(\cdot)$ can be expressed as in~\eqref{eq:Multi-Q-F}.
As discussed in the Introduction, the above notion of quantiles obviously extend our usual definition of quantiles when $d=1$; see Section~\ref{sec:d=1} in the Appendix for a more detailed discussion. A few remarks are in order now.

\begin{remark}[Non-uniqueness of $\psi$]
Although $Q$ is $\mu$-a.e.~unique it is easy to see that $\psi$ (as in Definition~\ref{def:Quantile}) is not unique; in fact, $\psi(\cdot) + c$ where $c\in \mathbb{R}$ is a constant would also suffice (as $\partial (\psi+c) = \partial \psi$). Further, we can change $\psi(\cdot)$ outside the set $\mathcal{S}$ and this does not change $Q$ (as $Q$ has domain $\mathcal{S}$). For this reason, we will consider
\begin{equation}\label{eq:Conv-Cvx}
\psi(u) = +\infty, \qquad \mbox{for } u \in \mathbb{R}^d\setminus \mathcal{S}.
\end{equation}
The above convention will be useful in the subsequent discussion.
\end{remark}

\begin{definition}[Rank map]\label{def:Rank}
Recall the convex function $\psi:\mathbb{R}^d \to \mathbb{R} \cup \{+\infty\}$ whose gradient yields the quantile map (see~\eqref{eq:Quantile}; also see~\eqref{eq:Conv-Cvx}). We define the rank function $R:\mathbb{R}^d \to \mathcal{S}$ of $\nu$ (w.r.t.~$\mu$) as
\begin{equation}\label{eq:Rank}
R := \nabla \psi^*
\end{equation}
where $\psi^*:\mathbb{R}^d \to \mathbb{R} \cup \{+\infty\}$ is the Legendre-Fenchel dual of the convex function $\psi$, i.e.,
$\psi^*(x) := \sup_{y \in \mathbb{R}^d} \{\langle x, y\rangle - \psi(y)\}$, for $x \in \mathbb{R}^d$.
\end{definition}
As $Q \in \partial \psi$, and $R \in \partial \psi^*$ are (sub)-gradients of two convex functions that are convex conjugates of each other, we have the following as a direct consequence of Lemma~\ref{lem:SubD}; see Section~\ref{sec:SubD-1} for a proof.
\begin{lemma}\label{lem:SubD-1}
We have
 \begin{align}\label{eq:EssR-Inv}
x\in \partial \psi(\partial \psi^*(x)), \;\mbox{for} \; x \in \mathbb{R}^d \qquad \mbox{and} \qquad u\in \partial \psi^*(\partial \psi(u)),\;\mbox{for} \;u \in \mathcal{S}.
 \end{align}
Moreover, for every Borel set $B \subset \mathbb{R}^d$, we have $(\partial \psi)^{-1}(B)= \partial \psi^*(B)$.
\end{lemma}
 A few remarks are in order now.
\begin{remark}[The domain of $R$]
Although not immediately clear from its definition, the rank map $R(x)$ is finite for a.e.~$x$; cf.~the quantile map $Q(\cdot)$ which is $\mu$-a.e.~uniquely defined. To see this observe that $\psi^*(x)$ is finite for all $x \in \mathbb{R}^d$ as $\psi^*(x) = \sup_{y \in \mathbb{R}^d} \{\langle x, y\rangle - \psi(y)\} = \sup_{y \in \mathcal{S}} \{\langle x, y\rangle - \psi(y)\}.$ The last equality is a consequence of the fact that for $y \notin \mathcal{S}$, $\psi(y) = + \infty$ (by our convention~\eqref{eq:Conv-Cvx}) and as $\mathcal{S}$ is compact we see that $\psi^*(x) <\infty$ for every $x \in \mathbb{R}^d$ (as $\langle x, \cdot\rangle - \psi(\cdot)$ is continuous  on the compact set $\mathcal{S}$ and hence bounded).
\end{remark}

\begin{remark}[The range of the rank map]
Using Lemma~\ref{lem:SubD} one can argue that $R(x) \in \mathcal{S}$ for a.e.~$x \in \mathbb{R}^d$. This follows from the fact that $R(x) \in \partial \psi^*(x)$ exists for every $x \in \mathbb{R}^d$ (as $\psi^*$ is convex), and by Lemma~\ref{lem:SubD}, $y \in \partial \psi^*(x) \Leftrightarrow  x \in \partial \psi(y).$ Note that as $\partial \psi(y)$ exists we must have $\psi(y) <+\infty$, which in turn implies that $y \in \mathcal{S}$ (as $\psi(y) = +\infty$, for $y \in \mathbb{R}^d\setminus \mathcal{S}$ by~\eqref{eq:Conv-Cvx}).
\end{remark}

\begin{remark}[When $\psi^*$ is not differentiable]
As $\psi^*$ is a convex function it has a gradient a.e. Thus, $R(x)$ is uniquely defined for a.e.~$x$. For $x\in \mathbb{R}^d$ where $\psi^*(x)$ is not differentiable, $R(x)$ is not uniquely defined. Although for such an $x$ we can define $R(x)$ to be any element in the subdifferential set $\partial \psi^*(x)$ (as was done in~\cite{Cher17}), in Section~\ref{sec:R_n} we give a randomized choice of $R(x)$ that leads to the map $R$ having appealing theoretical properties.
\end{remark}

The following result, proved in Section~\ref{sec:QRrelation}, shows that absolute continuity of $\nu$ is a sufficient condition for the rank map $R$ to be the right-inverse of the quantile map $Q$ $\mu$-a.e. This justifies the definition of $R$ via~\eqref{eq:Rank}.
\begin{lemma}\label{lem:QRrelation}
Suppose that $\mu$ and $\nu$ are absolutely continuous w.r.t.~Lebesgue measure. Let $Q$ and $R$ be the quantile and rank maps of $\nu$ (w.r.t.~$\mu$), as defined in~\eqref{eq:Quantile} and \eqref{eq:Rank}. Then:
\begin{enumerate}
 \item[(a)] The rank map $R(\cdot)$ is the essential right-inverse of the quantile function, i.e.,
 \begin{equation}\label{eq:Ess-Inv}
 R \circ Q (u)= u,\qquad\mbox{for}\;\mu\mbox{-a.e.}~u,
 \end{equation}
 and $R\# \nu= \mu$.
\item[(b)] Let $f$ and $g$ be the densities of $\mu$ and $\nu$ respectively. For any Borel set $A\subset \mathbb{R}^d$, define
$\rho_{Q}(A) := \int_{Q(A)} dx$. Then, $\rho_{Q}$ satisfies the Monge-Amp\`{e}re differential equation (see~\cite{PF14}), i.e.,
$
\rho_{Q}(A) = \int_{A}\frac{f(x)}{g(Q(x))} dx.
$
\end{enumerate}
\end{lemma}

Compare part (a) of the above result with~\cite[Theorem 2.1 and Equation (8)]{Cher17} where slightly stronger conditions are assumed on $\nu$ for obtaining similar conclusions. Observe that the rank map, as in Definition~\ref{def:Rank}, clearly extends the notion of the distribution function beyond $d=1$. Part (b) of Lemma~\ref{lem:QRrelation} shows the connection between the quantile map and the celebrated Monge-Amp\'{e}re differential equation; one can find similar results in \cite{Ca1,PF14,CF19}. For the sake of completeness, we have added a proof of this result. In many statistical applications it is often useful to know the regularity of the quantile and rank maps. Due to part (b) of Lemma~\ref{lem:QRrelation}, the regularity of our multivariate notions of quantiles and ranks follow from the regularity theory of the solution of the Monge-Amp\'ere equation which has been extensively studied by many authors in the past (see e.g.,~\cite{Cafa90,PF13,PF15,F10,FRV11,GO17}).

Although we know that $R = Q^{-1} \;\mu$-a.e.~when $\nu$ is absolutely continuous, we may ask if the equality holds everywhere (as opposed to a.e.). Several results have been obtained in this direction that provide sufficient conditions for such an equality. Caffarelli (see \cite{Ca1,Ca2,Ca3}) showed that when $\mathcal{S}$ and $\mathcal{Y}$ are two bounded convex sets in $\mathbb{R}^d$ and $\mu$ and $\nu$ are absolutely continuous with positive densities (on their supports), then, the corresponding optimal transport maps $T:\mathcal{S}\to \mathcal{Y}$ (such that $T\# \mu = \nu$) and $T^{*}:\mathcal{Y}\to \mathcal{S}$ (such that $T^{*}\# \nu= \mu$) are continuous homeomorphisms and $T^*= T^{-1}$ everywhere in $\mathcal{Y}$; see \cite[Pages 317--323]{V09} for other sufficient conditions.
The following result, proved in Section~\ref{sec:Q_prop}, gives another such sufficient condition that may be particularly useful in statistical applications.

 \begin{proposition}\label{thm:Q_prop}
Let $\mathcal{S} \subset \mathbb{R}^d$ be a compact convex set and let $\mathcal{Y} \subset \mathbb{R}^d$ be a convex set. Let $\mu$ be a probability measure supported on $\mathcal{S}$ such that the density of $\mu$ (w.r.t.~Lebesgue measure) is bounded away from zero and bounded above by a constant (on $\mathcal{S}$). Let $\nu$ be a probability measure supported on $\mathcal{Y}$ with density $p_{\mathcal{Y}}$ satisfying the following: there exists a sequence of convex compact sets $\{K_n\}_{n\geq 1}$ with $K_n\uparrow \mathcal{Y}$ and constants $\{\lambda_n, \Lambda_n\}_{n\ge1} \subset \mathbb{R}$ such that
\begin{align}\label{eq:sandwitch}
0<\lambda_n\leq p_{\mathcal{Y}}(x) \leq \Lambda_{n}, \qquad \quad \mbox{for all }\; x\in K_n.
\end{align}
Let $\psi:\mathbb{R}^d\to \mathbb{R}\cup \{+\infty\}$ be a convex function such that $\psi(x) = +\infty$ for $x\notin \mathcal{S}$, $\partial \psi(\mathrm{Int}(\mathcal{S})) = \mathrm{Int}(\mathcal{Y})$ and $\partial \psi \# \mu = \nu$. Let $\psi^{*}:\mathbb{R}^d \to \mathbb{R}\cup \{+\infty\}$ be the Legendre-Fenchel dual of $\psi$. Then:
\begin{enumerate}
\item[(a)] $\nabla \psi^{*}$, restricted on $\mathrm{Int}(\mathcal{Y})$, is a homeomorphism from $\mathrm{Int}(\mathcal{Y})$ to $\mathrm{Int}(\mathcal{S})$.

\item[(b)] $\nabla \psi$ is a homeomorphism from $\mathrm{Int}(\mathcal{S})$ to $\mathrm{Int}(\mathcal{Y})$. Furthermore, we have $\nabla \psi = (\nabla \psi^{*})^{-1}$ in $\mathrm{Int}(\mathcal{S})$.
\end{enumerate}
\end{proposition}

\begin{remark}[Convexity of $\mathcal{S}$ and $\mathcal{Y}$]\label{rem:Cvx-S-Y}
Convexity of the domains, $\mathcal{S}$ and $\mathcal{Y}$, is one of the important conditions for the existence of continuous transport maps. Cafarrelli constructed a counterexample (see e.g.,~\cite[pp.~283--285]{V09}) where he showed that the transport map may fail to be continuous when the two measures are absolutely continuous with bounded densities on two smooth and simply connected non-convex domains.
\end{remark}

\begin{remark}[On condition~\eqref{eq:sandwitch}]\label{rem:Cond-11} We would like to point out that condition \eqref{eq:sandwitch} is important for our proof of Proposition~\ref{thm:Q_prop}. It is one of the sufficient conditions, similar in flavor to Cafarrelli~\cite{Ca1} (also see~\cite{Cher17}) but weaker, for showing that the transport map $\nabla \psi^{*}:\mathrm{Int}(\mathcal{Y}) \to \mathrm{Int}(\mathcal{S})$ is continuous on $\mathrm{Int}(\mathcal{Y})$. Recently, \cite[Theorem~1.1]{Figalli18} used a condition like \eqref{eq:sandwitch} to show that the center-outward quantile function (see~\cite{dCHM} for its definition) is a homeomorphism. However,~\cite{Figalli18} assumed that $\mathcal{Y} = \mathbb{R}^d$. In contrast,~\eqref{eq:sandwitch} is more flexible and covers the case when $\mathcal{Y}$ is a compact convex subset of $\mathbb{R}^d$ as well as when $\mathcal{Y}=\mathbb{R}^d$, and $\nu$ is a probability measure with positive bounded density on $\mathcal{Y}$. For example, any unimodal multivariate density supported on a convex domain $\mathcal{Y}\subset \mathbb{R}^d$ satisfies \eqref{eq:sandwitch};  in particular, this includes the family of multivariate normal distributions.
\end{remark}
Next we illustrate that the rank map (as defined in~\eqref{eq:Rank}) possesses many properties similar to the univariate distribution function. Our first result, Lemma~\ref{lem:Monotonicity} (proved in Section~\ref{sec:Monotonicity}), states that the one-dimensional projection of the rank map, along any direction, is nondecreasing.

\begin{lemma}[Monotonicity of the rank map]\label{lem:Monotonicity}
Let $R$ be the rank map of $\nu$ w.r.t. $\mu$.  For $x,y\in \mathbb{R}^d$, define $R_{x,y}:\mathbb{R}\to \mathbb{R}$ as
\begin{align*}
R_{x,y}(t):=(x-y)^{\top}R(tx+(1-t)y), \qquad t \in \mathbb{R}.
\end{align*}
Then, $R_{x,y}(\cdot)$ is a nondecreasing function.
\end{lemma}

Note that a univariate distribution function is not only nondecreasing but takes the value 0 or 1 as one approaches $-\infty$ or $+\infty$, irrespective of the probability measure $\nu$. Under mild regularity assumptions on $\mathcal{S}$ and the rank map $R(\cdot)$, we show in the Lemma~\ref{cor:RankProp} (proved in Section~\ref{sec:RankProp}) that $R(\cdot)$ is continuous on the whole of $\mathbb{R}^d$ and it approaches a limit along every ray that depends only on the geometry of $\mathcal{S}$ (and not on the measure $\nu$).
\begin{lemma}\label{cor:RankProp}
Let $\mathcal{S}$ be a compact convex set in $\mathbb{R}^d$ such that all the supporting hyperplanes of $\mathcal{S}$ touch the boundary of $\mathcal{S}$ at most once. Let $\mu$ and $\nu$ be two probability measures on $\mathcal{S}$ and $\mathcal{Y} \subset \mathbb{R}^d$, respectively, where $\mathcal{Y}$ has nonempty interior. Let $R$ be the rank map of $\nu$ w.r.t. $\mu$. Suppose that $R$ is a homeomorphism from $\mathrm{Int}(\mathcal{Y})$ to $\mathrm{Int}(\mathcal{S})$. Then,
\begin{enumerate}
\item[(a)] $R$ is everywhere continuous in $\mathbb{R}^d$,
\item[(b)] for any $x\in \mathbb{R}^d$, $\lim_{\lambda \to  +\infty} R(\lambda x) = \argmax_{v\in \mathcal{S}} \langle x, v\rangle$.
\end{enumerate}
\end{lemma}
Note that the above required condition on $\mathcal{S}$ is certainly satisfied, for example, when $\mathcal{S}$ is the unit ball in $\mathbb{R}^d$, i.e., $\mathcal{S} = B_1(0)$; unfortunately when $\mathcal{S} = [0,1]^d$, the condition is not satisfied.

\subsection{The sample quantile and rank maps}\label{sec:Emp-Q-R}
\begin{figure}
\centering
\includegraphics{4-Points}
\caption{The left plot shows a data set with four two-dimensional points $X_1,X_2,X_3$ and $X_4$.  The right plot shows the four cells (each with area 1/4) marked 1, 2, 3, 4, and the four data points in blue (appropriately scaled to lie in $[0,1]^2$) along with dashed lines connecting each data point to the centroid (in red) of the corresponding cell. The two points $A$ and $B$ in the right plot correspond to the intersection of three cells --- $1, 2, 3$ and $1, 3, 4$.}
\label{fig:Q-map}
\end{figure}
As before, we fix an absolutely continuous distribution $\mu$ with compact convex support $\mathcal{S} \subset \mathbb{R}^d$. Given a random sample $X_1,\ldots, X_n$ from a distribution $\nu$ (on $\mathbb{R}^d$), we now consider estimating the population quantile and rank maps $Q(\cdot)$ and $R(\cdot)$, respectively (w.r.t.~$\mu$). We simply define the sample versions of the quantile and rank maps as those obtained by replacing the unknown distribution $\nu$ with its empirical counterpart $\hat \nu_n$ --- the empirical distribution of the data, i.e.,
$$
\hat \nu_n(A) = \frac{1}{n} \sum_{i=1}^n \delta_{X_i}(A), \qquad \mbox{ for any Borel set $A \subset \mathbb{R}^d$}.
$$
\subsubsection{Empirical quantile function}\label{sec:Q_n}
By Theorem~\ref{thm:Brenier} there exists an $\mu$-a.e.~unique map $\hat Q_n$ which pushes $\mu$ to $\hat \nu_n$ and can be expressed as
\begin{equation}\label{eq:SampQ_n}
\hat Q_n = \nabla \hat \psi_n,
\end{equation}
where $\hat \psi_n:\mathbb{R}^d \to \mathbb{R} \cup \{+\infty\}$ is a convex function. Further, by Theorem~\ref{thm:Brenier}, $\hat Q_n$ can be computed via:
\begin{equation}\label{eq:Emp_Q}
\hat Q_n = \argmin_T \int  \|u - T(u)\|^2 d\mu(u)  \qquad \quad \mbox{subject to }\quad T\#\mu  = \hat \nu_n.
\end{equation}
Note that $\hat Q_n= \nabla \hat \psi_n$ is $\mu$-a.e.~unique; when $\hat \psi_n$ is not differentiable at $u$ we can define $\hat Q_n(u)$ to be any point in $\partial \hat \psi_n(u)$.  As $\hat Q_n = \nabla \hat \psi_n$ pushes $\mu$ to $\hat \nu_n$, $\hat \psi_n$ is a convex function whose gradient takes $\mu$-a.e.~finitely many values (in the set $\{X_1,\ldots, X_n\}$). Thus $\hat \psi_n$ is piecewise linear (affine), and hence, there exists $\hat h = (\hat h_1,\ldots, \hat h_n) \in \mathbb{R}^n$ (unique up to adding a scalar multiple of $(1,\ldots, 1) \in \mathbb{R}^n$) such that $\hat{\psi}_n:\mathbb{R}^d \to \mathbb{R} \cup \{+\infty\}$ can be represented as
\begin{equation}\label{eq:Emp_G}
\hat{\psi}_n(u) := \begin{cases} \max_{i=1,\ldots, n} \{u^\top X_i + \hat h_i\} & \mbox{for } u \in \mathcal{S} \\ +\infty & \mbox{for } u \notin \mathcal{S}. \end{cases}
\end{equation}
The vector $\hat h$ can be computed by solving a convex optimization problem;  see Section~\ref{sec:Comp}. Note that from the form of $\hat{\psi}_n$ above it is clear that $\hat Q_n(u)$, for any $u \in \mathrm{Int}(\mathcal{S})$, belongs to the convex hull of the data.
\begin{remark}[Form of the subdifferential set $\partial \hat{\psi}_n(u)$]\label{rem:Q-d} As $\hat{\psi}_n$ is  piecewise linear (affine) and convex (and thus a finite pointwise maximum of affine functions), we can explicitly write its subdifferential, i.e., for any $u \in \mathcal{S}$, $$\partial \hat{\psi}_n(u) =  \mathrm{Conv}(\{X_i: \langle u,X_i \rangle + \hat h_i = \hat{\psi}_n(u)\}).$$
\end{remark}
The function $\partial \hat{\psi}_n(\cdot)$ induces a cell decomposition of $\mathcal{S}$: Each cell is a convex set and is defined as
\begin{equation}\label{eq:W_i}
W_i(\hat h) := \{u \in \mathcal{S}: \nabla \hat{\psi}_n(u) = X_i\};
\end{equation}
 see~\cite{Gu12} for the details. In defining $W_i(\hat h)$, as in~\eqref{eq:W_i}, we only consider points $u \in \mathcal{S}$ where $\hat{\psi}_n$ is differentiable. Note that, for a.e.~sequence $X_1,\ldots, X_n$, each cell $W_i(\hat h)$ has $\mu$ measure $1/n$ and $\cup_{i=1}^n W_i(\hat h) \subset \mathcal{S}$. Figure~\ref{fig:Q-map} illustrates this with four points $X_1,X_2,X_3$ and $X_4$ and $\mu = $ Uniform$([0,1]^2)$. Each point in the four cells (labelled 1, 2, 3  and 4) is mapped to the corresponding data point ($X_1,X_2,X_3$ and $X_4$) by the sample quantile function $\hat Q_n \equiv \nabla \hat \psi_n$. The convex function $\hat \psi_n$ is not differentiable at the boundary of the 4 cells (marked by the black lines in the right panel of Figure~\ref{fig:Q-map}). Remark~\ref{rem:Q-d=1} in the Appendix illustrates the above ideas when $d=1$ and $\mu = $ Uniform$([0,1])$.

\subsubsection{Empirical rank map}\label{sec:R_n}
Let us define $\hat{\psi}_n^*:\mathbb{R}^d \to \mathbb{R} \cup \{+ \infty\}$ to be the {\it Legendre-Fenchel} dual of $\hat{\psi}_n$, i.e.,
 \begin{equation}\label{eq:Sup}
 \hat{\psi}^{*}_n(x) :=\sup_{y\in \mathbb{R}^d}\big\{\langle x,y\rangle - \hat{\psi}_n(y)\big\} = \sup_{u\in \mathcal{S}}\big\{\langle x,u\rangle - \hat{\psi}_n(u)\big\}, \quad \mbox{for } x \in \mathbb{R}^d.
\end{equation}
We define the {\it multivariate sample rank function} $\hat{R}_n:\mathbb{R}^d \to \mathcal{S}$ as
\begin{equation}\label{eq:SampR_n}
\hat{R}_n  := \nabla  \hat{\psi}^{*}_n.
\end{equation}
The following result (proved in Section~\ref{sec:RAltDef}) expresses $\hat{R}_n$ in another form, which is especially convenient for computation; cf.~\cite[Definition 3.1]{Cher17}.

\begin{lemma}\label{lem:RAltDef}
Consider the multivariate sample rank function $\hat{R}_n$ defined in \eqref{eq:SampR_n}. Then, for all $y\in \mathbb{R}^d$,
\begin{align}\label{eq:RAltDef}
\hat{R}_n(y) \in \argmax_{u\in \mathcal{S}}\{\langle u, y\rangle - \hat{\psi}_n(u)\}.
\end{align}
\end{lemma}
The following result, proved in Section~\ref{Pf:lem:ExtremePt}, expresses the value of $ \hat{\psi}^{*}_n$ at the data points in terms of $\hat {h}_i$ (see~\eqref{eq:Emp_G}).
\begin{lemma}\label{lem:ExtremePt}
Fix $i \in \{1,\ldots, n\}$. Consider $\hat{\psi}^{*}_n$ as defined in~\eqref{eq:Emp_G}. Then, $\hat{\psi}^{*}_n(X_i) = -\hat {h}_i$.
\end{lemma}
\begin{figure}
\includegraphics{2-Dist}
\caption{The two plots show the cell decomposition of $\mathcal{S} = [0,1]^2$ (each with area $1/n$ where $n=100$) induced by the estimated quantile function (w.r.t.~$\mu = $ Uniform$([0,1]^2)$) and the data cloud (appropriately scaled to lie in $[0,1]^2$) along with dashed lines indicating which cell corresponds to which data point. The data sets are drawn from the following distributions: (i) $X \sim N_2((0,0),I_2)$; (ii) $X \sim N_2((0,0),\Sigma)$ where $\Sigma_{1,1} = \Sigma_{2,2} = 1$ and $\Sigma_{1,2} = \Sigma_{2,1} = 0.99$.
\label{fig:4Plots}
\end{figure}

It is a simple fact that the Legendre-Fenchel dual of a piecewise affine convex function is also convex piecewise affine. In fact, for $x \in \mathrm{Conv}(X_1, \ldots, X_n)$,
\begin{equation}\label{eq:Dual-2}
\hat{\psi}^{*}_n(x) = \min \left\{\sum_{i=1}^n t_i \hat{\psi}^{*}_n(X_i): t_i \ge 0, \sum_{i=1}^n t_i =1, \sum_{i=1}^n t_i X_i = x\right\};
\end{equation}
see e.g.,~\cite[Theorem 2.2.7]{H94}. Thus, $\hat R_n(\cdot)$ a.e.~takes finitely many distinct values (as it is a gradient of a piecewise  affine convex function).

Remark~\ref{rem:R-d=1} in the Appendix shows that when $d=1$, the rank function $\hat{R}_n$ is not defined uniquely at the data points $X_i$'s. Note that the non-uniqueness of the rank function when $d=1$ was finessed by enforcing right-continuity, which is hard to do as we go beyond $d=1$. Indeed, for any $d \ge 1$, $\hat R_n(X_{i})$ could be defined as any element in the (closure of the) cell $W_i(\hat h)$; this follows from Lemma~\ref{lem:SubD}. Figure~\ref{fig:Q-map} illustrates this when $\mu = $ Uniform$([0,1]^2)$. Using the next result, Lemma~\ref{lem:Char3} (proved in Section~\ref{sec:Char3}), we see in Figure~\ref{fig:Q-map} that any point in the interior of the triangle formed by $X_1, X_2$ and $X_3$ (or $X_1, X_3$ and $X_4$) is mapped to the point $A$ (or $B$) by the sample rank map $\hat R_n$.
\begin{lemma}\label{lem:Char3}
Fix $x\in \mathbb{R}^d$. Suppose that for $i_1,\ldots, i_{d+1} \subset \{1,\ldots, n\}$: (i) $x\in \mathrm{Int}\big(\mathrm{Conv}\big(X_{i_1}, \ldots , X_{i_{d+1}}\big)\big)$, and (ii) there exists a unique $u\in \mathcal{S}$ such that $u = \mathrm{Cl}(W_{i_1}(\hat h)) \cap \ldots \cap \mathrm{Cl}(W_{i_{d+1}}(\hat h))$ (see~\eqref{eq:W_i}). Then, $u$ is the unique point in $\mathcal{S}$ such that $x\in \partial \hat{\psi}_n (u)$. Furthermore, $\partial\hat{\psi}^{*}_n(x) = u = \hat{R}_n(x)$.
\end{lemma}

\subsubsection{Ranks}\label{sec:Ranks}

By the ``ranks" of the data points we mean the rank function evaluated at the data points $X_i$'s. When $d=1$ and the underlying distribution is continuous, the usual ranks, i.e., $\{\mathbb{F}_n(X_i)\}_{i=1}^n$ (here $\mathbb{F}_n$ is the empirical distribution function), are identically distributed on the discrete set $\{1/n,2/n,\ldots, n/n\}$ with probability $1/n$ each. As a consequence, the usual ranks are {\it distribution-free} (in $d=1$), i.e., the distribution of $\mathbb{F}_n(X_i)$ does not depend on the distribution of $X_i$ (as long as $X_i$ comes from a continuous distribution). We may ask: ``Does a similar property hold for the multivariate ranks $\hat R_n(X_i)$?".

From the discussion in Section~\ref{sec:R_n} it is clear that the multivariate ranks $\hat R_n(X_{i})$ are non-unique. In fact, we can choose $\hat R_n(X_i)$ to be any point in the set $W_i(\hat h)$ (see~\eqref{eq:W_i}). In the sequel we will use a special choice of $\hat R_n(X_i)$ which will lead to a distribution-free notion. We define $\hat R_n(X_i)$ as a random point drawn from the uniform distribution on the cell $W_i(\hat h) \subset \mathcal{S}$, i.e.,
\begin{equation}\label{eq:Rank-X_i}
\hat R_n(X_i)|X_1,\ldots, X_n \sim \mathrm{Uniform}(W_i(\hat h)).
\end{equation}
Thus, our choice of the empirical ranks $\{\hat R_n(X_i)\}_{i=1}^n$ is random. However, this external randomization leads to the following interesting consequence --- the multivariate ranks are  distribution-free (see Section~\ref{pf:Uniform} for the proof).
\begin{lemma}\label{lem:Uniform}
Suppose that $X_1,\ldots, X_n$ are i.i.d.~$\nu$, an absolutely continuous distribution on $\mathbb{R}^d$. Let $\mu = $ Uniform$(\mathcal{S})$, where $\mathcal{S}$ is a compact convex set in $\mathbb{R}^d$. Then, for any $i =1,\ldots, n$, $\hat R_n(X_i) \sim \mu = \mathrm{Uniform}(\mathcal{S}).$
\end{lemma}

Compare Lemma~\ref{lem:Uniform} with the result that $R(X) \sim \mu$ where $R(\cdot)$ is the population rank map of $X \sim \nu$, a consequence of the fact that $R(\cdot)$ pushes forward $\nu$ to $\mu$ (by Lemma~\ref{lem:QRrelation} ). Note that the above result may not hold if $\mu$ is not the uniform distribution on $\mathcal{S}$. If we do not want a randomized choice of ranks, then we can define
$\hat R_n(X_i) := \max_{u \in \mathrm{Cl}(W_i(\hat h))}\|u\|;$ the above choice is convenient for computational purposes.

\subsection{Computation of the sample quantile and rank functions}\label{sec:Comp}
The computation of the empirical quantile function (via~\eqref{eq:Emp_Q}) is often referred to as the semi-discrete optimal transport problem. The computation of~\eqref{eq:W_i}, which is obtained from solving~\eqref{eq:Emp_Q}, leads to a ``partition'' of $\mathcal{S}$ into $n$ convex sets (each with volume $1/n$) and is usually called the power diagram~\cite{Auren87} --- a type of weighted Voronoi diagram. Several authors have worked on the computation of the power diagram; see e.g.,~\cite{Auren87, Auren98, Merigot11, Levy18}. In particular, it is known that the computation of~\eqref{eq:Emp_Q} can be formulated as a convex program with $n$ variables. Moreover, recently, several approximate algorithms that are computationally efficient (especially when $d \ge 4$) have also been investigated, see e.g.,~\cite{Genevay16} and the references therein. Once the empirical potential function $\hat{\psi}_n$ is computed, the computation of the empirical rank map at a data point, via~\eqref{eq:RAltDef}, involves solving  a convex program.

The two plots in Figure~\ref{fig:4Plots} show different convex polyhedral partitions of $[0,1]^2$ obtained from the potential function corresponding to two different simulated data sets --- notice the different shapes and structure of the cells $W_i(\hat h)$ for the two types of data distributions. As the (empirical) rank and quantile functions take values in $\mathbb{R}^d$, they are a bit difficult to visualize. In Figure~\ref{fig:Banana} we plot the estimated  depth function --- defined as $\hat D_n:\mathbb{R}^d \to \mathbb{R}$ such that $\hat D_n(x) := 1/2 - \|\hat R_n(x) - \mathbf{1}/2\|_\infty$ where $\hat R_n(\cdot)$ is the estimated rank function and  $\mathbf{1} = (1,1,\ldots, 1) \in \mathbb{R}^d$ --- for the banana-shaped distribution; cf.~\cite{Cher17} where the authors motivate the use of multivariate ranks/quantiles based on optimal transportation using this data (see~\cite[Figure 2]{Cher17}). The banana-like geometry of the data cloud is correctly picked up by the non-convex contours in Figure~\ref{fig:Banana}; cf.~\cite[Figure 2]{Cher17}.
\begin{figure}

	       \includegraphics{Banana-Dist}
	    \caption{Left: A random sample of size $n=1000$ drawn from the banana-shaped distribution. Right: The estimated depth function for the banana-shaped data obtained from a sample of 10000 observations.}
	    \label{fig:Banana}
\end{figure}

\subsection{Properties of the quantile and rank maps}\label{sec:Q-R-Prop}
In this section we describe some important properties of the defined quantile and rank functions. Our first result, proved in Section~\ref{Pf:lem:LinTrans}, shows that the quantile/rank function of $Y := c X + b$, where $X \sim \nu$ is a random vector in $\mathbb{R}^d$ ($b \in \mathbb{R}^d$ and $c >0$), can be easily obtained from the quantile/rank function of $X$.
\begin{lemma}\label{lem:LinTrans}
Suppose that $X \sim \nu$ where $\nu$ is a distribution on $\mathbb{R}^d$. Let $\mu$ be an absolutely continuous distribution on $\mathbb{R}^d$ with support $\mathcal{S}$. Suppose that $c >0$ is a scalar and $b \in \mathbb{R}^d$. Let $Y := c X + b$. Let $Q_X:\mathcal{S} \to \mathbb{R}^d$ and $R_X: \mathbb{R}^d \to\mathbb{R}^d$ be the quantile and rank maps of $X$ (w.r.t.~$\mu$). Let $Q_Y:\mathcal{S} \to \mathbb{R}^d$ and $R_Y: \mathbb{R}^d \to \mathbb{R}^d$ be the quantile and rank maps of $Y$ (w.r.t.~$\mu$). Then, for  $\mu$-a.e.~$u$ and for a.e.~$y \in \mathbb{R}^d$, $$Q_Y(u) = c\,Q_X(u) + b, \qquad  \mbox{and} \qquad R_Y(y) = R_X((y -b)/c).$$
\end{lemma}

The above lemma holds for any probability measure $\nu$ (discrete or continuous); it justifies the fact that we can rescale the data (by adding a constant vector and multiplying by a positive scalar) in Figures~\ref{fig:Q-map} and~\ref{fig:4Plots} and the cell decomposition (of $\mathcal{S}$) does not change (see~\eqref{eq:W_i}) as the transformed (piecewise linear and convex) potential function is obtained by adding a constant to a positive multiple of the previous (piecewise linear) potential function.

It is natural to ask if it is possible to relate the quantile and rank functions of $Y := AX$, where $A_{d \times d}$ is a matrix, to those of $X$. The following result (proved in Section~\ref{Pf:lem:LinTrans-2}) shows that the quantile map is equivariant under any orthogonal transformation if $\mu$ is spherically symmetric.
 \begin{lemma}\label{lem:LinTrans-2}
 Suppose that $A$ is an orthogonal matrix, i.e., $A A^\top  = A^\top A = I_d$. Let $\mu$ be a spherically symmetric absolutely continuous distribution on $\mathbb{R}^d$ (e.g., the uniform distribution on the unit ball around $0 \in \mathbb{R}^d$). Let us denote by $\psi_X$ the potential function linked to the random variable $X\sim \nu$, i.e., $\nabla \psi_X \# \mu = \nu$ and $\psi_X$ is convex. Then a potential function of $Y:=AX$ is given by $\psi_Y(u) = \psi_X(A^\top u)$, for $u \in \mathbb{R}^d$. As a consequence, for  $\mu$-a.e.~$u$ and for a.e.~$y \in \mathbb{R}^d$, $$Q_Y(u) = A Q_X(A^\top u), \qquad \mbox{and} \qquad R_Y(y) = A R_X(A^\top y).$$
\end{lemma}

For the next result (proved in Section~\ref{pf:prop:Indep}) we take $\mu =$ Uniform$([0,1]^d)$; note that the choice of $\mu =$ Uniform$([0,1]^d)$ has been studied before (see e.g.,~\cite{D14, Galichon16}). This has implications in testing for mutual independence between random vectors; see Section~\ref{sec:IndepTest} for more details.

\begin{proposition}\label{prop:Indep}
Suppose that $\nu$ is a distribution on $\mathbb{R}^d$ and let $\mu= $ Uniform$([0,1]^d)$. Suppose that $X =(X_1,X_2, \ldots, X_k) \sim \nu$ where $k \ge 2$, $X_i \sim \nu_i$, for $i=1,\ldots, k$, are random vectors in $\mathbb{R}^{d_i}$ (here $d_1 + \ldots + d_k = d$). Let $Q$ and $Q_i$ be the quantile maps of $X$ and $X_i$, for $i = 1,\ldots, k$, respectively (w.r.t.~$\mu$ and $\mu_i = $ Uniform$([0,1]^{d_i})$). Let $R$ and $R_i$, for $i = 1,\ldots,k$, be the corresponding rank maps. If $X_1, \ldots, X_k$ are mutually independent then
\begin{equation}\label{eq:Indep-Q}
Q(u_1,\ldots, u_k) = (Q_1(u_1), \ldots, Q_k(u_k)), \quad \mbox{for $\mu$-a.e. } (u_1,\ldots,u_k) \in \mathbb{R}^{d},
\end{equation}
and
\begin{equation}\label{eq:Indep}
R(x_1,\ldots, x_k) = (R_1(x_1), \ldots, R_k(x_k)), \qquad \mbox{for a.e.~}(x_1,\ldots,x_k) \in \mathbb{R}^{d}.
\end{equation}
 Conversely, suppose that~\eqref{eq:Indep-Q} or~\eqref{eq:Indep} holds. Then $X_1,\ldots,X_k$ are mutually independent.
\end{proposition}

\section{Asymptotic Properties of Empirical Quantile and Rank maps}\label{sec:Asymptotics}

 \subsection{Uniform convergence}\label{sec:UnifConv}
The rank and quantile functions in one dimension enjoy many interesting asymptotic properties. For example, if $X_1, \ldots , X_n\sim \nu$, where $\nu$ is a probability measure over $\mathbb{R}$, then by the Glivenko-Cantelli theorem, the empirical rank function (which is same as the empirical distribution function when $d=1$) converges uniformly to the population rank function a.s. Similarly, for $d=1$, the empirical quantile function converges uniformly (on compacts $[a,b] \subset (0,1)$) to the population quantile function, when the underlying distribution function is continuous and strictly increasing. One may wonder if such results also hold for the multidimensional empirical quantile and rank functions studied in this paper. In Theorem~\ref{thm:GCProp} below we show that this is indeed the case.

Suppose that $\nu$ is absolutely continuous with support $\mathcal{Y} \subset \mathbb{R}^d$; here $\nu$ is the target distribution. Let $\mu$ be an absolutely continuous distribution supported on a compact convex set $\mathcal{S} \subset \mathbb{R}^d$. Let $Q$ and $R$ be the quantile and rank maps of $\nu$ (w.r.t.~$\mu$); see~\eqref{eq:Quantile} and~\eqref{eq:Rank} respectively.
Let $X_1, X_2, \ldots$ be a sequence of i.i.d.~random variables with distribution $\nu$. Let $\{\hat{\nu}_n\}_{n\ge1}$ be a sequence of random probability distributions (computed from $X_1,\ldots, X_n$) such that $\hat{\nu}_n$ converges weakly to $\nu$ a.s., i.e.,
\begin{equation}\label{eq:Conv-Emp-Meas}
\hat{\nu}_n \stackrel{d}{\to} \nu \quad \mbox{a.s.}
\end{equation}
For example, we can take $\hat{\nu}_n$ to be the empirical distribution obtained from the first $n$ data points, i.e., $\hat{\nu}_n = \frac{1}{n} \sum_{i=1}^n \delta_{X_i}$; in this case we know that~\eqref{eq:Conv-Emp-Meas} holds (see e.g.,~\cite[Theorem~11.4.1]{Dudley}). Denote the multivariate quantile and rank functions for $\hat{\nu}_n$ (w.r.t.~$\mu$) by $\hat{Q}_n$ and $\hat{R}_n$. In particular, when the underlying potential functions (see Definition~\ref{def:Quantile}) are not differentiable, we define $\hat{Q}_n$ and $\hat{R}_n$ to be any point in the corresponding subdifferential set. The following is a main result of this paper (see Section~\ref{proof:thm-GC} for its proof).

\begin{theorem}\label{thm:GCProp}
Consider the notation introduced above and suppose that~\eqref{eq:Conv-Emp-Meas} holds. Suppose that $Q:\mathrm{Int}(\mathcal{S}) \to \mathrm{Int}(\mathcal{Y})$ is a homeomorphism. Let $K_1\subset \mathrm{Int}(\mathcal{S})$ and $K_2\subset \mathrm{Int}(\mathcal{Y})$ be any two compact sets.
\begin{enumerate}
\item[(a)]  Then, we have
\begin{equation}\label{eq:GC}
\sup_{u\in K_1} \|\hat{Q}_n(u) - Q(u)\| \stackrel{a.s.}{\rightarrow} 0.
\end{equation}

\item[(b)] Further,
\begin{align}\label{eq:GC-Rank}
\sup_{x\in K_2} \|\hat{R}_n(x) - R(x)\| \stackrel{a.s.}{\rightarrow} 0.
\end{align}

\item[(c)]  Suppose that all the supporting hyperplanes of $\mathcal{S}$ touch the boundary of $\mathcal{S}$ at most once. Let $\{\lambda_n\}_{n\in \mathbb{N}}\subset \mathbb{R}$ be a sequence such that $\lambda_n\to \infty$ as $n\to \infty$. Then,
\begin{align}\label{eq:GC-RankFiner}
\sup_{x\in \mathbb{R}^d} \|\hat{R}_n(x) - R(x)\| \stackrel{a.s.}{\rightarrow} 0,
\end{align}
and
\begin{align}\label{eq:Asymptot}
\qquad \lim_{\lambda_{n}\to \infty}\hat{R}_n(\lambda_n x) \stackrel{a.s.}{=} \argmax_{v \in \mathcal{S}} \langle x, v\rangle, \quad \mbox{for all}\;\; x\in \mathbb{R}^d.
\end{align}

\end{enumerate}
\end{theorem}

 Theorem~\ref{thm:GCProp}-$(a)$ extends the uniform convergence of the empirical quantile function (on compacts in the interior of $[0,1]$, for $d=1$) beyond $d=1$. Theorem~\ref{thm:GCProp}-$(b)$ shows the uniform convergence of the estimated rank map on any compact set inside $\mathrm{Int}(\mathcal{Y})$. One may notice that Theorem~\ref{thm:GCProp}-$(a)$ and~$(b)$ improve upon the result of \cite[Theorem 3.1]{Cher17} where the authors prove a similar convergence result for the estimated quantile/rank maps under the additional assumption of compactness of $\mathcal{Y}$. Also,  compared to~\cite[Theorem~3.1]{Cher17} where only convergence in probability of the empirical quantile/rank maps are established, in Theorem~\ref{thm:GCProp} we show a.s.~convergence.

Theorem~\ref{thm:GCProp}-$(c)$ (see \eqref{eq:GC-RankFiner}) can be thought of as the proper generalization of  the Glivenko-Cantelli theorem beyond $d=1$ where we show the a.s.~convergence of the estimated rank map uniformly over the whole of $\mathbb{R}^d$.

 \begin{remark}[On the sufficient condition for~\eqref{eq:GC-RankFiner}] In~\eqref{eq:GC-RankFiner} we show that the empirical rank map converges to the population rank function uniformly on $\mathbb{R}^d$, under a certain assumption on $\mathcal{S}$. This sufficient condition is certainly satisfied, for example, when $\mathcal{S}$ is the unit ball in $\mathbb{R}^d$, i.e., $\mathcal{S} = B_1(0)$. Unfortunately when $\mathcal{S} = [0,1]^d$, this condition is not satisfied.
\end{remark}

\begin{remark}[Necessity of $Q$ to be a homeomorphism]
One of the main assumptions in Theorem~\ref{thm:GCProp} is that the population quantile $Q$ is a homeomorphism; for $d=1$ this corresponds to assuming that the distribution function is continuous and strictly increasing.
It is actually a necessary condition for showing the uniform convergence of $\hat{Q}_n$ (the sample quantile function) to $Q$; in fact, more generally, for a sequence of (sub)-gradients of convex functions. To see this, consider the example of a sequence of convex functions $\phi_n:\mathbb{R} \to \mathbb{R}$ defined as $\phi_n(x) := (x^2+n^{-1})^{1/2}$. Note that $\phi^{\prime}_n(x)=x(x^2+n^{-1})^{-1/2}$ and $\phi^{\prime \prime}_n(x)= (x^2+n^{-1})^{-3/2}$, for all $x\in \mathbb{R}$. This shows that $\phi_n$ is convex for all $n\geq 1$. As $n\to \infty$, $\phi_n(x)$ converges pointwise to $\phi(x) := |x|$. However, the subdifferential set of the function $\phi(x)$ at $x=0$ is equal to $[-1,1]$ whereas $\phi^{\prime}_n(0)=0$ for all $n\geq 1$. Hence, $\phi^{\prime}_n(\cdot)$ does not converge uniformly on any compact set containing $0$.
\end{remark}

\begin{remark}[When is $Q$ a homeomorphism?] From Proposition~\ref{thm:Q_prop} it follows that when the support of $\nu$ is convex and $\nu$ is absolutely continuous with density satisfying \eqref{eq:sandwitch} then the quantile map $Q$ will be a homeomorphism; also see Remarks~\ref{rem:Cvx-S-Y} and~\ref{rem:Cond-11}. Recently, in~\cite[Proposition~4.5 and Corollary~4.6]{KM17} some results are provided that show that the transport map (quantile map) can be a homeomorphism even when the support of $\nu$ is a union of convex domains.
\end{remark}

\begin{remark}[Connection to~\citet{VS18}]
During the final stages of the preparation of this paper, we came across the recent paper~\cite{VS18} which would imply ``graphical convergence" of the estimated quantile maps (see~\cite[Theorem 4.2 and Corollary 4.4]{VS18}). Their result does not need absolute continuity of $\nu$ and no restrictions are placed on the supports of the measures $\mu$ and $\nu$. However, note that graphical convergence, which implies a form of local uniform convergence, is weaker than uniform convergence on compacta stated in Theorem~\ref{thm:GCProp}. Moreover, since the empirical rank maps $\hat{R}_n$ are not strictly transport maps, it is not clear if~\cite{VS18} implies any notion of convergence for $\hat{R}_n$.

\end{remark}

One of the key ingredients in the proof of Theorem~\ref{thm:GCProp} is the following lemma which investigates some limiting properties of (sub)-gradients of a sequence of convex functions. Before proceeding to the main statement, let us provide some motivation for such a result. Suppose that $\phi_n:\mathbb{R}^d \to \mathbb{R} \cup \{+\infty\}$, for ${n\ge 1}$, is a sequence of convex functions such that the sets $\{\phi^{*}_n<\infty\}$ are uniformly bounded; here $\phi^{*}_n$ denotes the Legendre-Fenchel dual of $\phi_n$. We may think of $\phi_n$ as $\hat{\psi}^*_n$ (see~\eqref{eq:Sup}) in which case $\phi_n^* = \hat{\psi}_n$. Then, owing to Lemma~\ref{lem:SubD}, $\{\partial \phi_n(\mathbb{R}^d): n \ge 1\}$,  are uniformly bounded sets. Further, on any bounded set $\mathfrak{K} \subset \mathbb{R}^d$, $\{\phi_n\}_{n\ge 1}$ will be a sequence of uniformly bounded equicontinous\footnote{We say a sequence of functions $\{f_n:\mathbb{R}^d\to \mathbb{R}\}_{n\ge 1}$ is uniformly equicontinuous if for any $\epsilon>0$ there exists $\delta>0$ such that $|f_n(x)-f_n(y)|\leq \epsilon$ whenever $\|x-y\|\leq \delta$.} functions on $\mathfrak{K}$; see~Lemma~\ref{lem:Bd}. Therefore, by the Arzela-Ascoli theorem, there exists a convex function $\phi$ such that $\phi_n$ converges to $\phi$ uniformly on $\mathfrak{K}$. However, this does not guarantee the uniform convergence of the corresponding subdifferential sets. The following lemma, proved in Section~\ref{pf:KeyLemma}, addresses the mode of convergence of the subdifferential sets when the underlying convex functions converge uniformly.  The result may also be of independent interest.

\begin{lemma}\label{KeyLemma}
For $n \ge 1$, let $\phi_n:\mathbb{R}^d \to \mathbb{R}$ be a sequence of convex functions with $\phi_n(0)=0$ and $\partial \phi_n(\mathbb{R}^d)  \subset S$ for some compact set $S\subset \mathbb{R}^d$. Let $K\subset \mathbb{R}^d$ be a compact set. Assume that there exists a convex function $\phi:\mathbb{R}^d \to \mathbb{R} \cup \{+\infty\}$ such that $$\sup_{u\in K^{\prime}} |\phi_n(u) - \phi(u) |\to 0 \quad \mbox{ as } \quad n \to \infty,$$ where $K^{\prime}\subset \mathbb{R}^d$ is a compact set such that $\mathrm{Int}(K') \supset K$. Then, the following hold:
\begin{enumerate}

\item[(a)] Fix $\delta>0$. For a set $A\subset \mathbb{R}^d$, define $B(\delta, A) := \cup_{x\in A} B_{\delta}(x)$. There exists $n_0=n_0(\delta) \in \mathbb{N}$ such that for all $n\geq n_0$, we have $\partial \phi_n(K)\subset B(\delta, \partial \phi(K))$.

\item[(b)] $\partial\phi(K) \subset S$.

\item[(c)] Furthermore, if $\phi$ is differentiable everywhere on $K$, then,
\begin{equation}
\sup_{u\in K} \sup_{\xi\in \partial \phi_n(u)} \|\xi- \nabla \phi(u)\|   \to 0, \quad \text{as }n\to \infty. \vspace{-0.12in} \nonumber
\end{equation}

\item[(d)] If $\phi$ is strictly convex on $K^{\prime}$, then, for any open set $U\subset K$, there exists $n_0=n_0(U)\in \mathbb{N}$ such that $\partial \phi(U)\subset \partial \phi_n(K^{\prime})$ for all $n\geq n_0$.

\item[(e)] Let $K^{\prime\prime} \subset S$ be a compact convex set. Suppose that $\phi^{*}_n$, the Legendre-Fenchel dual of $\phi_n$, converges uniformly to another  differentiable convex function $\psi$ on $K^{\prime\prime}$, i.e., $\sup_{u\in K^{\prime\prime}} |\phi_n^*(u) - \psi(u) |\to 0$ as $n \to \infty$. Also suppose that $\nabla \psi(K^{\prime\prime}) \subset K$. For any $x\in K^{\prime\prime}$, if $\nabla\psi(x) =y\in K$, then $x\in \partial \phi(y)$.
\end{enumerate}

\end{lemma}

Lemma~\ref{KeyLemma}-(e) shows that if a sequence of convex functions and their Legendre-Fenchel duals converge uniformly to the convex functions $\phi$ and $\psi$ respectively, and if one of these two functions is everywhere differentiable, then,~\eqref{eq:Charac-Sub} of Lemma~\ref{lem:SubD} holds partially between $\phi$ and $\psi$. This raises the following question (which is also relevant to the proof of Theorem~\ref{thm:GCProp}): If \eqref{eq:Charac-Sub} holds partially between any two convex functions $\phi$ and $\psi$, then, is it true that $\phi$ is the Legendre-Fenchel dual of $\psi$? As one can guess, this is not true in general and the main reason is the invariance of \eqref{eq:Charac-Sub} under the addition of constants to $\phi$ or $\psi$. However, one may still hope that the subgradients of $\phi$ will be the same as the subgradients of the Legendre-Fenchel dual of $\psi$.
Our next result, proved in Section~\ref{pf:KeyLemma2}, provides a sufficient condition under which we are able to validate this claim.

 \begin{lemma}\label{KeyLemma2}
Let $\mathcal{S}$ and $\mathcal{Y}$ be two sets in $\mathbb{R}^d$. Suppose that $\mathcal{S}$ is bounded and there is a differentiable convex function $\psi: \mathcal{S}\to \mathbb{R}$ such that $\nabla \psi:\mathrm{Int}(\mathcal{S}) \to \mathrm{Int}(\mathcal{Y})$ is a homeomorphism. Then $\psi^{*}$, the convex conjugate of $\psi$, is differentiable everywhere on $\mathrm{Int}(\mathcal{Y})$. Now, let $\phi:\mathbb{R}^d\to \mathbb{R}$ be another convex function such that: (i) $\partial \phi(\mathbb{R}^d)\subset \mathcal{S}$, and (ii) $y= \nabla \psi(x)$ for some $x\in \mathcal{S}\; \Rightarrow \; x\in\partial \phi(y)$. Then, $\phi$ is differentiable everywhere on $\mathrm{Int}(\mathcal{Y})$, and $\nabla\phi(y) = \nabla \psi^{*}(y)$ for all $y\in \mathrm{Int}(\mathcal{Y})$.
\end{lemma}

Suppose that a sequence of convex functions $\{\phi_n\}_{n\geq 1}$ converges to another convex function $\phi$ uniformly on every compact subset of $\mathbb{R}^d$. Our last result of this section Lemma~\ref{lem:UnifConv} (proved in Section~\ref{pf:UnifConv}) provides a sufficient condition under which one can show the uniform convergence of the subgradients of $\phi_n$ to those of $\phi$, over the whole of $\mathbb{R}^d$.

\begin{lemma}\label{lem:UnifConv}
Let $\mathcal{S}$ be a compact convex set in $\mathbb{R}^d$ such that all the supporting hyperplanes of $\mathcal{S}$ touch the boundary of $\mathcal{S}$ at most once. Let $\mathcal{Y} \subset \mathbb{R}^d$ have nonempty interior. Let $\phi_n:\mathbb{R}^d \to \mathbb{R}$ be a sequence of convex functions such that $\partial \phi_n(\mathbb{R}^d)\subset \mathcal{S}$ for all $n\geq 1$. Suppose that $\{\phi_n\}_{n\geq 1}$ converges uniformly to a convex function $\phi:\mathbb{R}^d \to \mathbb{R}$ on every compact set of $\mathbb{R}^d$ and $\nabla\phi$ is a homeomorphism from $\mathrm{Int}(\mathcal{Y})$ to $\mathrm{Int}(\mathcal{S})$. Then,
\begin{enumerate}
\item[(a)] $\phi$ is everywhere differentiable in $\mathbb{R}^d$,
\item[(b)] $\sup_{x\in \mathbb{R}^d} \sup_{y\in \partial\phi_n(x)}\|y - \nabla \phi(x)\|\to 0, \quad \text{ as }n\to \infty,$
\item[(c)] for any $x\in \mathbb{R}^d$, $\lim_{\lambda \to  +\infty} \nabla \phi(\lambda x) = \argmax_{v\in \mathcal{S}} \langle x, v\rangle$.
\end{enumerate}
\end{lemma}
We observe that \cite[Section~3.2.3]{dCHM} has a similar result like Lemma~\ref{lem:UnifConv} when $\mathcal{S}$ is the closed unit ball in $\mathbb{R}^d$. Lemma~\ref{lem:UnifConv} generalizes \cite{dCHM} by giving a sufficient condition on $\mathcal{S}$ under which a similar conclusion holds.

\subsection{Comparison with~\citet{Cher17} and~\citet{dCHM}}\label{sec:Comparison}
In the papers~\cite{Cher17} and~\cite{dCHM} the authors use ideas from the theory of optimal transportation to define multivariate quantiles and ranks. Although our approach is similar in spirit to that of~\cite{Cher17} there are subtle and important differences. As opposed to~\cite{Cher17}, we completely avoid the dual formulation of Kantorovich and Brenier (see~\cite[Theorem 2.2]{Cher17}) and define the multivariate quantiles and ranks through Monge's primal problem; we hope that this makes the exposition more accessible to the uninitiated reader. ~\citet{Cher17} studied multivariate quantiles and ranks to obtain notions of statistical depth whereas we study quantiles and ranks to aid us to construct nonparametric goodness-of-fit and mutual independence tests.

The approach to defining multivariate ranks and quantiles proposed and studied in~\cite{dCHM} (also see~\cite{BSS18}) is quite different from ours.~\citet{dCHM} choose a set of $n$ representative grid points within the set $\mathcal{S}$ (that approximates the measure $\mu$) and then solve the discrete optimal transport problem (between the sample data points and the $n$ chosen grid points) to define the empirical rank map. Thus the ``ranks'' of the data points are forced to be the points in the chosen grid. This approach immediately leads to many attractive features for the empirical ranks, e.g., the distribution-freeness of the ranks. However this approach also has many obvious drawbacks: (i) the choice of the $n$ grid-points is ad-hoc (see~\cite{dCHM}); (ii) it does not automatically give rise to a quantile function (or quantile contours) and special smoothing interpolation is required (which again involves the choice of tuning parameters). In comparison, our approach (and that of~\cite{Cher17}) is completely automated and tuning parameter-free. However, this necessarily entails dealing with non-unique ranks at the data points. In a sense, our approach yields an elegant and useful notion of quantiles while the approach of~\cite{dCHM} yields a notion of ranks with  attractive properties.

Theorem~\ref{thm:GCProp} aims towards a unification of the asymptotic results of the Monge-Kantorovich ranks and quantiles of \cite[Theorem 3.1]{Cher17} and the center-outward ranks and quantiles of \cite[Propositions~1.5.1 and 1.5.2]{dCHM}. In~\cite{Cher17}, the authors show the convergence (in probability) of the Monge-Kantorovich ranks and quantiles by relating them to the solutions of the dual problem of the Kantorovich relaxation (to Monge's problem). This correspondence works under the assumption that both the reference and target measures have finite second moments.~\citet{dCHM} avoided this dependence on the finite second moment assumption by defining the center-outward ranks and quantiles on the basis of McCann's construction \cite{McCann95} of transport maps as limits of cyclically monotone maps.
For proving our uniform consistency result, we marry the weak convergence theory of the Monge-Amp\'{e}re measures (see~\cite{G16}) and the recently introduced theory of graphical convergence of transport maps (see~\cite{del2019}); the connections between these two notions of convergence are made precise in Lemmas~\ref{KeyLemma},~\ref{KeyLemma2} and~\ref{lem:UnifConv}.
By doing so we neither have to impose any finite moment assumptions on the target measure nor have to interpret the quantiles or ranks as limits of cyclically monotone maps.

\subsection{Local rate of convergence}\label{sec:RateSec}

When $d=1$, the pointwise limiting distribution (under appropriate scaling and centering) of the empirical rank and quantile functions are easy to derive. In fact, the central limit theorem plays a key role in obtaining these limiting distributions; this is tied to the fact that the one-dimensional rank and quantile functions can be approximated by sums of i.i.d.~random variables. However, it is not yet clear if the multidimensional ranks and quantiles, studied in this paper, enjoy such properties. This makes it difficult to even find the pointwise rate of convergence of the empirical rank and quantile maps.

As a first step to finding the local uniform rate of convergence of the empirical quantile and rank functions, we give the following result (proved in Section~\ref{sec:RateProp1}) that provides a deterministic upper bound on the local uniform rate of convergence of the subdifferentials (of a sequence of convex functions and their Legendre-Fenchel duals) by a local $L_2$-loss of the subdifferentials.

\begin{theorem}\label{ppn:RateProp1}
Let $\mu$ be an absolutely continuous probability measure supported on a compact convex set $\mathcal{S} \subset \mathbb{R}^d$. Let $\nu$ be a probability measure supported on $\mathcal{Y}\subset \mathbb{R}^d$ and let $\psi$ be a convex function such that $\nabla \psi \# \mu = \nu$. Suppose that $\{\hat{\nu}_n\}_{n \ge 1}$ is a sequence of probability distributions on $\mathbb{R}^d$. Let $\{\hat{\psi}_n\}_{n \ge 1}$ be a sequence of convex functions such that $\nabla \hat{\psi}_n\# \mu = \hat{\nu}_n$, for all $n \ge 1$. Fix $u_0\in \mathrm{Int}(\mathcal{S})$ and $\delta_0\equiv\delta_0(u_0)>0$ such that $B_{\delta_0}(u_0) \subset \mathcal{S}$. Suppose that $\mu$ has a bounded (from below and above) nonvanishing density on $B_{\delta_0}(u_0)$. Suppose that $\psi$ is differentiable everywhere in $\mathrm{Int}(\mathcal{S})$ and let $\nabla\psi$ be locally uniformly Lipschitz  in $B_{\delta_0}(u_0)$ with Lipschitz constant $K$. Define
 \begin{align}\label{eq:DeltaDef}
\delta_n:= \Big(\int_{B_{\delta_0}(u_0)} \|\nabla \hat{\psi}_n(u)- \nabla\psi(u)\|^2 d\mu(u)\Big)^{\frac{1}{d+2}}.
\end{align}
  Then, there exists $C=C(\mu, d, K) >1/2$ such that
{\small \begin{align}\label{eq:SupBd}
\quad \;\; \sup_{u\in B_{\delta_0/3}(u_0)} \sup_{y \in \partial \hat{\psi}_n(u)}\|y- \nabla\psi(u) \|  \leq \begin{cases}
C\delta_n & \text{if }\delta_n \leq \delta_0/3, \\
C \delta_n^{d+2}\delta^{-(d+1)}_{0}  + \frac{1}{2}\delta_0& \text{if } \delta_n> \delta_0/3.
\end{cases}
\end{align}}
Now, assume that $\mu$ has bounded nonvanishing density everywhere on $\mathcal{S}$ and that $\nabla \psi$ is uniformly Lipschitz on $\mathcal{S}$ with Lipschitz constant $K$. Suppose that there exists $\tilde{\delta}_0>0$ such that $\nabla\psi^{*}(\mathrm{Cl}(B_{\tilde{\delta}_0}(\nabla \psi(u_0))))\subset B_{\delta_{0}/6}(u_0)$. Define
\begin{align*}
\delta^{\prime}_n:= \Big(\int_{\mathcal{S}}\|\nabla \hat{\psi}_n(u) - \nabla \psi(u)\|^2 d\mu(u)\Big)^{\frac{1}{d+2}},
\end{align*}
and
{\small $$ \tilde{\delta}_n: = \sup_{v \in \mathrm{Cl}(B_{\tilde{\delta}_0}(\nabla \psi(u_0))), \; w\in \nabla\psi(\mathrm{Cl}(B_{\delta_0/3}(u_0)))}\Big\{\|\nabla\psi^{*}(v)-\nabla\psi^{*}(w)\|: \|v-w\|\leq C\delta^{\prime}_n\Big\} $$}
where $C$ is the same constant as in \eqref{eq:SupBd}.
If $\max\{C \delta^{\prime}_n, \tilde{\delta}_n\}<\delta_0/6$, then,
\begin{align}\label{eq:SupBd1}
\sup_{x\in B_{\tilde{\delta}_0}(\nabla \psi(u_0))} \sup_{w \in \partial \hat{\psi}^{*}_n(x)}\|w -\nabla\psi^{*}(x)\| \leq
\tilde{\delta}_n.
\end{align}
\end{theorem}
Note that the existence of $\tilde \delta_0$ is guaranteed if $\nabla \psi$ is a homeomorphism from $\mathrm{Int}(\mathcal{S})$ to $\mathrm{Int}(\mathcal{Y})$.
In~\eqref{eq:SupBd} of Theorem~\ref{ppn:RateProp1} we provide a deterministic upper bound on the pointwise difference between $\partial \hat{\psi}_n(\cdot)$ and $\nabla\psi(\cdot)$, uniformly on the local ball $B_{\delta_0/3}(u_0)$, in terms of the $L_2$-loss~\eqref{eq:DeltaDef}. Similarly,~\eqref{eq:SupBd1} bounds the pointwise difference between $\partial \hat{\psi}_n^*(\cdot)$ and $\nabla\psi^*(\cdot)$, uniformly over a local ball around $\nabla\psi(u_0)$, in terms of $\tilde{\delta}_n$.

As $\tilde{\delta}_n$ is defined  implicitly in terms of $\delta_0,\tilde{\delta}_0$ and $\delta^{\prime}_n$ it is natural to ask how $\tilde{\delta}_n$ varies with $\delta^{\prime}_n$. If $\nabla \psi^{*}$ is uniformly $\beta$-H\"older continuous, for $\beta \in (0,1]$,  in the neighborhood $\mathrm{Cl}(B_{\tilde{\delta}_0}(\nabla \psi(u_0)))\cup \nabla\psi(\mathrm{Cl}(B_{\delta_0/3}(u_0)))$, then, for all   $v,w\in \mathrm{Cl}(B_{\tilde{\delta}_0}(\nabla \psi(u_0)))\cup \nabla\psi(\mathrm{Cl}(B_{\delta_0/3}(u_0)))$
\begin{align}
\|\nabla \psi^{*}(v)- \nabla \psi^{*}(w)\| \leq \kappa (\delta^{\prime}_n)^{\beta}, \quad \text{such that } \|v-w\|\leq C\delta^{\prime}_n, \nonumber
\end{align}
where $\kappa = \kappa(C,\beta, \mu, \delta_0)>0$ is a constant. As a consequence, $\tilde{\delta}_n$ is also less than $\kappa (\delta^{\prime}_n)^{\beta}$. This shows that the local rate of convergence of the rank map adapts to the local smoothness of the transport maps $\nabla \psi$ and $\nabla \psi^{*}$.

Suppose that $\hat{\nu}_n$ is the empirical measure of $X_1,\ldots ,X_n$. Suppose that $\psi$ and $\hat{\psi}_n$ are two convex functions such that $\nabla \psi\# \mu =\nu$ and $\nabla \hat{\psi}_n\#\mu =\hat{\nu}_n$. By an application of the deterministic result Theorem~\ref{ppn:RateProp1}, we can bound the local uniform rate of convergence of $\partial \hat{\psi}_n$ and $\partial \hat{\psi}_n^*$ by the local $L_2$-rate of convergence of $\partial \hat{\psi}_n$.

It is natural to ask if useful bounds on the local $L_2$-rate of convergence of the transport map $\partial \hat{\psi}_n$ is known.
Obviously, $\delta^{(d+2)/2}_n$, as defined in \eqref{eq:DeltaDef}, is bounded from above by the global $L_2$-loss of $\hat{\psi}_n$, i.e., $\int_{\mathcal{S}} [\|\nabla \hat{\psi}_n(u)- \nabla \psi(u)\|^2 d\mu(u)]^{{1}/{2}}$. Recently,~\cite{HR} studied the rate of convergence of the $L_2$-loss function of transport maps. Under additional smoothness assumptions on $\psi$ (and $\nabla \psi$), \cite{HR} found the minimax rate of convergence of transport maps in the $L_2$-loss (when $n$ independent samples are available from $\mu$). We believe that a similar approach will provide a rate of convergence for $\delta_n$. However, a complete analysis of the rate of convergence of $\delta_n$ will need new techniques and is beyond the scope of the present paper and will be pursued in a follow-up work.

In the special case when $\mu=\nu$, the analysis is much simpler, and we can use known results to obtain upper bounds on the rate of convergence of the global $L_2$-loss for the transport map $\nabla \hat{\psi}_n$, thereby yielding a rate for the local uniform loss via Theorem~\ref{ppn:RateProp1}. Indeed, this special case in important in its own right and has received much attention in the literature; see Section~\ref{sec:LR} in the Appendix for motivation and a detailed review. Our final result of this section, Corollary~\ref{thm:RateTheo} (proved in Section~\ref{sec:RateTheo}), demonstrates a local-global correspondence to yield a rate of convergence of the empirical quantile/rank maps when $\mu \equiv \nu$ and is a consequence of Theorem~\ref{ppn:RateProp1} and the main result of~\citet{FG15}.

\begin{corollary}\label{thm:RateTheo}
Let $\mu\equiv \nu$ be an absolutely continuous probability measure supported on $\mathcal{S} \subset \mathbb{R}^d$ ($d > 1$) such that $\int \|x\|^{q}d\nu(x)<\infty$, for some $q>2$. Suppose that $X_1, \ldots , X_n$ are i.i.d.~$ \nu$. Let $\hat{\psi}_n$ be a convex function such that $\nabla \hat{\psi}_n\# \mu = \hat \nu_n \equiv \frac{1}{n}\sum_{i=1}^{n}\delta_{X_i}$.
Define
\begin{align}
\Psi(n,d,q):=  \begin{cases}
n^{-\frac{1}{2(d+2)}} + n^{-\frac{q-2}{q(d+2)}} & \text{if } d<4, q\neq 4,\\
n^{-\frac{1}{2(d+2)}} (\log(1+n))^{\frac{1}{d+2}} + n^{-\frac{q-2}{q(d+2)}} & \text{if }d=4, q\neq 4, \\
n^{-\frac{2}{d(d+2)}} + n^{-\frac{q-2}{q(d+2)}} & \text{if }d>4, q\neq  \frac{d}{d-2}.
\end{cases}
\end{align}
Fix $u_0\in \mathrm{Int}(\mathcal{S})$ and $\delta_0\equiv\delta_0(u_0)>0$ such that $B_{\delta_0}(u_0) \subset \mathcal{S}$. Then, there exists   $C=C(\mu,d,q)>0$ such that, for all $n\geq 1$,
\begin{align}\label{eq:RateAc}
\qquad \mathbb{E}\Big[\sup_{u\in B_{\delta_0/3}(u_0)}\sup_{z \in \partial \hat{\psi}_n(u)}\|z-u\|\Big]\leq C \Psi(n,d,q).
\end{align}
Now, suppose that the support of $\mu$ is bounded. Then,
\begin{align}\label{eq:RateAc2}
\qquad \mathbb{E}\Big[\sup_{x\in B_{\delta_0/6}(u_0)}\sup_{w \in \partial \hat{\psi}^{*}_n(x)}\|w-x\|\Big]\leq C \Psi(n,d,q).
\end{align}
\end{corollary}

 To the best of our knowledge, the above result is the first attempt to study the local uniform behavior of transport (quantile/rank) maps. However, it is not clear to us whether the above bounds are tight  when $d\ge 2$. We believe that it may be possible to improve our rate of convergence result under further assumptions on $\mu$.
 We hope to address this in future work.

\section{Applications to nonparametric testing}\label{sec:Goodness-Fit-Test}
\subsection{Two-sample goodness-of-fit testing in $\mathbb{R}^d$}\label{sec:2S-Goodness-Fit-Test}
Suppose that we observe $X_1,\ldots, X_m$ i.i.d.~$\nu_X$ and $Y_1,\ldots, Y_n$ i.i.d.~$\nu_Y$, where $m, n \ge 1$, and $\nu_X$ and $\nu_Y$ are unknown absolutely continuous distributions on $\mathbb{R}^d$. We also assume that both the samples are drawn mutually independently. In this section we consider the two-sample equality of distribution hypothesis testing problem:
\begin{equation}\label{eq:2-Sample-Test}
H_0: \nu_X = \nu_Y\quad \mbox{ versus }\quad H_1: \nu_X \ne \nu_Y.
\end{equation}
The two-sample problem for multivariate data has been extensively studied, beginning with the works of~\cite{Weiss60, Bickel68}. Several graph based methods have been proposed in the literature for this problem; see e.g.,~\cite{FR79, Sc86, Rosenbaum05, B15} and the references therein. Also see~\cite{BF04, SR13, EquivRKHS13} for distance and kernel based methods for the two-sample problem when $d \ge 1$. In this section we introduce another multivariate two-sample test that uses ideas from optimal transportation and, in particular, the quantile and rank functions defined in Section~\ref{sec:Q-R}.

Let $\mu$ be an absolutely continuous distribution supported on a compact convex set $\mathcal{S} \subset \mathbb{R}^d$ having a density (w.r.t.~Lebesgue measure), e.g., $\mu = $ Uniform$([0,1]^d)$ or $\mu = $ Uniform$(B_1(0))$.  Let $\hat Q_X$ and $\hat Q_Y$ be the sample quantile functions (as defined in~\eqref{eq:SampQ_n}) of the $X_i$'s and $Y_j$'s, respectively (w.r.t.~$\mu$). Let $\hat R_{X,Y}$ be the empirical rank map of the combined sample  $X_1,\ldots, X_m, Y_1,\ldots, Y_n$ (w.r.t.~$\mu$). Note that, as in Section~\ref{sec:Ranks}, we define the rank at any data point as a randomized value (as defined in~\eqref{eq:Rank-X_i}).
We use the following test statistic for testing~\eqref{eq:2-Sample-Test}:
\begin{align}\label{eq:2-S-TS}
T_{X,Y} & := \int_\mathcal{S} \|\hat R_{X,Y}(\hat Q_X(u)) - \hat R_{X,Y}(\hat Q_Y(u))\|^2 d \mu(u) \\
& = \mathbb{E}_{U}\Big[\big\|\hat R_{X,Y}(\hat Q_{X}(U))- \hat R_{X,Y}(\hat Q_{Y}(U))\big\|^2\Big] \nonumber
\end{align}
where $U\sim \mu$ is independent of $X_1, \ldots , X_m, Y_1, \ldots ,Y_n$ and the above expectation is taken w.r.t.~$U$. Although exactly computing $T_{X,Y}$ is possible (as the above integral reduces to a finite sum; see Section~\ref{sec:Simul-2S}  for the details) it is computationally involved. One can easily approximate $T_{X,Y}$ using Monte Carlo.

We reject $H_0$ when $T_{X,Y}$ is large. To motivate the form of the above test statistic consider the one-sample Cram\'{e}r-von Mises statistic when $d=1$. Let $\mathbb{F}_n$ be the empirical distribution of the data (when $d=1$) and $F$ be the true distribution function (assumed to be absolutely continuous). Then the Cram\'{e}r-von Mises statistic can be written as $$ \int_{\mathbb{R}} \{\mathbb{F}_n(x) - F(x)\}^2 dF(x) = \int_0^1 \{\mathbb{F}_n(F^{-1}(u)) - u\}^2 du.$$ Indeed,~\eqref{eq:2-S-TS} is similar to the right side of the above display; however as we are now in the two-sample case, $F^{-1}$ is unknown and is replaced by the sample quantile function.

The connection to the Cram\'{e}r-von Mises statistic above immediately raises the following question: Is $T_{X,Y}$ distribution-free under $H_0$ (as the Cram\'{e}r-von Mises statistic when $d=1$)? Unfortunately, we do not know the exact answer to this question; see Section~\ref{sec:Simul-2S} for a detailed discussion with simulation studies. Our simulations suggest that this might very well be the case, at least for $d=2$. We plan to study this in the future.

In the following lemma (proved in Section~\ref{pf:Distfree}) we show that $\hat R_{X,Y}(\hat Q_{X}(U))$ and $\hat R_{X,Y}(\hat Q_{Y}(U))$ (as in~\eqref{eq:2-S-TS}) are both marginally distributed as $\mu$ under $H_0$ (when $\mu$ is the uniform distribution on $\mathcal{S}$), and are thus distribution-free.

\begin{lemma}\label{lem:Distfree}
Let $\mathcal{S}$ be a compact convex set in $\mathbb{R}^d$. Let $\mu = $ Uniform$(\mathcal{S})$, i.e., $\mu$ is the uniform distribution on $\mathcal{S}$. Suppose that $H_0$ is true, i.e., $\nu_X = \nu_Y$. Then $\hat R_{X,Y}(\hat Q_{X}(U)) \sim \mu$ and $\hat R_{X,Y}(\hat Q_{Y}(U)) \sim \mu$, and hence their distributions do not depend on $\nu_X \equiv \nu_Y$.
\end{lemma}

The following result (proved in Section~\ref{pf:Power1}) shows that our proposed test has asymptotic power 1 for any two distributions $\nu_X \ne \nu_Y$, as $m,n \to \infty$.

\begin{proposition}[Consistency]\label{lem:Power1}
Suppose that $H_0: \nu_X = \nu_Y = \nu$ holds. Assume that $\nu$ is supported on a domain $\mathcal{Y} \subset \mathbb{R}^d$ such that the quantile map $Q:\mathrm{Int}(\mathcal{S})\to \mathrm{Int}(\mathcal{Y})$ is a homeomorphism. Also, assume that $m,n\to \infty$ such that $\frac{m}{m+n}\to \theta\in (0,1)$. Then, under $H_0$, as $m,n\to \infty$,
\begin{align}\label{eq:Consis1}
T_{X,Y} \stackrel{a.s.}{\longrightarrow} 0.
\end{align}
Now, suppose $X_1, \ldots , X_m\stackrel{i.i.d}{\sim} \nu_X$ and $Y_1, \ldots , Y_n\stackrel{i.i.d}{\sim} \nu_Y$ where $\nu_X \ne \nu_Y$ are two distinct measures supported on domains $\mathcal{Y}_X$ and $\mathcal{Y}_Y$ respectively. Denote the quantile maps of the measures $\nu_X$, $\nu_Y$ and $\theta \nu_X+(1-\theta)\nu_Y$ by $Q_X$, $Q_Y$ and $Q_{X,Y}$ respectively. Assume that $Q_X,Q_Y, Q_{X,Y}:\mathrm{Int}(\mathcal{S})\to \mathrm{Int}(\mathcal{Y}_X \cup \mathcal{Y}_Y)$ are homeomorphisms. Then, there exists $c>0$ such that
\begin{align}\label{eq:Consis2}
T_{X,Y} \stackrel{a.s.}{\longrightarrow} c, \qquad \mbox{ as  } m,n\to \infty.
\end{align}
\end{proposition}

\begin{remark}[Finding the critical value of $T_{X,Y}$] Although we have shown (in Lemma~\ref{lem:Distfree}) that $\hat R_{X,Y}(\hat Q_{X}(U)) \sim \mu$ and $R_{X,Y}(\hat Q_{Y}(U)) \sim \mu$ (and thus both quantities are distribution-free) it is not immediately clear if the test statistic $T_{X,Y}$ is distribution-free. In Section~\ref{sec:Simul-2S} we provide simulation evidence that illustrates that a properly normalized version of $T_{X,Y}$ may be asymptotically distribution-free, at least when $d=2$. In any case, the critical value of the test under $H_0$ can always be computed using the following permutation principle: Under the null hypothesis $X_1,\ldots, X_m, Y_1, \ldots, Y_n$ are i.i.d.~and thus we can consider any partition of the $m+n$ data points into two sets of sizes $m$ and $n$ and recompute our test statistic to simulate its null distribution.
\end{remark}

Our test statistic $T_{X,Y}$ (see~\eqref{eq:2-S-TS}) is inspired by the form of the Cram\'{e}r-von Mises (one-sample) goodness-of-fit statistic. One can, of course, use other test statistics. A key observation for constructing other tests is to realize that, under $H_0$, $\hat R_{X,Y}(X_1), \ldots, \hat R_{X,Y}(X_m), \hat R_{X,Y}(Y_1), \ldots, \hat R_{X,Y}(Y_n)$ are {\it exchangeable} and are all marginally distributed as $\mu$.

\subsection{Mutual independence testing}\label{sec:IndepTest}
Let $X = (X^{(1)}, \ldots, X^{(k)}) \sim \nu$ be a random vector in $\mathbb{R}^d$ where $k \ge 2$ and $X^{(j)}\sim \nu_j$ is a random vector in $\mathbb{R}^{d_j}$, for $j = 1, \ldots, k$, with $\sum_{j=1}^k d_j = d$. In this section we consider the problem of testing the mutual independence of $X^{(1)},\ldots, X^{(k)}$. Specifically, we consider testing whether $\nu$ is equal to the product measure $\nu_1 \otimes \ldots \otimes \nu_k$, for some $\nu_1,\ldots, \nu_k$, i.e.,
\begin{equation}\label{eq:Ind-Test}
H_0: \nu = \nu_1 \otimes \ldots \otimes \nu_k, \qquad \mbox{ versus } \qquad H_1: \nu \ne \nu_1 \otimes \ldots \otimes \nu_k,
\end{equation}
when we observe i.i.d.~data from $\nu$. This is again a fundamental problem in statistics and there has been many approaches investigated in the literature; see e.g.,~\cite{Blomqvist50, BlumEtAl61},~\cite[Chapter 8]{HW99} and the references therein. Recently, the use of kernel (see e.g.,~\cite{GrettonKernelMeasInd05, EquivRKHS13, Lyons13}) and distance covariance (see e.g.,~\cite{SzekelyBDCov09, SzekelyCorrDist07, 4-Axioms-MS19, SR13}) based methods have become very popular. In this section, we use ideas from optimal transportation to construct a test for~\eqref{eq:Ind-Test}.

For simplicity of notation, let us first assume that $k=2$. Let $\{Z_i \equiv (X_i,Y_i): 1 \le i \le n\}$ be $n$ i.i.d.~{$\nu$},  assumed to be absolutely continuous on $\mathbb{R}^{d_X} \times \mathbb{R}^{d_Y}$; here $d_X, d_Y \ge 1$ and $d_X + d_Y =d$. Further, we assume that $X \sim \nu_X$ and $Y \sim \nu_Y$. In this section we want to test the hypothesis of mutual independence between $X$ and $Y$, i.e., we want to test:
\begin{equation}\label{eq:Ind-Test-2}
\qquad {H_0: \nu = \nu_X \otimes \nu_Y}\quad \mbox{ versus }\quad {H_1: \nu \ne \nu_X \otimes \nu_Y}.
\end{equation}
Let ${\mu_X }= $ Uniform($[0,1]^{d_X}$),  $ {\mu_Y} = $  Uniform($[0,1]^{d_Y}$) and let {$\mu := \mu_X \otimes \mu_Y$} =  Uniform($[0,1]^d$). We define $\hat R: \mathbb{R}^d \to [0,1]^d$ and $\hat Q:[0,1]^d \to \mathbb{R}^d$ to be the empirical rank and quantile maps of the joint sample $(X_1,Y_1),\ldots, (X_n, Y_n)$. Let ${\hat R_X}: \mathbb{R}^{d_X} \to \mathbb{R}^{d_X}$ be the empirical rank map of $X_1,\ldots, X_n$; similarly let {$\hat R_Y: \mathbb{R}^{d_Y} \to \mathbb{R}^{d_Y}$} be the sample {rank map} obtained from $Y_1,\ldots, Y_n$. Define ${\tilde R := (\hat R_X, \hat R_Y)}:\mathbb{R}^d \to [0,1]^d$. We consider the following test statistic:
\begin{equation}\label{eq:Ind-TS}
T_{n} := {\int_{[0,1]^d} \|\hat R(\hat Q(u)) - \tilde R(\hat Q(u))\|^2 d u } = \frac{1}{n} \sum_{i=1}^n \|\hat R(Z_i) - \tilde R(Z_i)\|^2.
\end{equation}
Note that the above integral reduces to a finite average as $\hat Q(\cdot)$ can only take $n$ distinct values a.s. We reject the null hypothesis in~\eqref{eq:Ind-Test} when $T_{n}$ is large. As in Section~\ref{sec:2S-Goodness-Fit-Test}, the critical value of the above test can be computed using the permutation principle. Although it is beyond the scope of the present paper, we illustrate through simulations in Section~\ref{sec:Simul-Ind} that a properly normalized version of $T_{n}$ may be (asymptotically) distribution-free (at least when $d=2$). The following result, proved in Section~\ref{sec:Pf:lem:Power2}, describes the asymptotic behavior of the proposed test statistic under the null and alternative hypotheses; in particular, it shows that the power of the test converges to 1, under mild regularity conditions.
\begin{proposition}[Consistency]\label{lem:Power2}
We have $\hat R(\hat Q(U)) \sim \mu$, where $U \sim \mu = $ Uniform$([0,1]^d)$. Suppose $H_0$ holds, i.e., $\nu = \nu_X \otimes \nu_Y$. Then, $\tilde  R(\hat Q(U)) \sim \mu$.

Assume further that $\nu_{X}$ and $\nu_{Y}$ are two probability measures supported on the domains $\mathcal{Y}_X\subset \mathbb{R}^{d_{X}}$ and $\mathcal{Y}_{Y}\subset \mathbb{R}^{d_{Y}}$ respectively. Denote the quantile maps of the measures $\nu_{X}$, $\nu_{Y}$ and $\nu$ w.r.t. the measures $\mathrm{Uniform}([0,1]^{d_X})$, $\mathrm{Uniform}([0,1]^{d_Y})$ and $\mathrm{Uniform}([0,1]^{d})$ by $Q_X$, $Q_Y$ and $Q$  respectively, where $d=d_X+d_Y$. Assume that $Q_X:(0,1)^{d_X}\to\mathrm{Int}(\mathcal{Y}_X)$,  $Q_X:(0,1)^{d_Y}\to\mathrm{Int}(\mathcal{Y}_Y)$ and  $Q:(0,1)^{d}\to\mathrm{Int}(\mathcal{Y}_X \times \mathcal{Y}_Y)$ are homeomorphisms. Then, under $H_0$, as $n\to\infty$,
\begin{align}\label{eq:Consis21}
T_{n} \stackrel{a.s.}{\longrightarrow} 0.
\end{align}
Furthermore, if $\nu \ne \nu_X \otimes \nu_Y$, then, there exists $c>0$  such that
\begin{align}\label{eq:Consis22}
T_{n} \stackrel{a.s.}{\longrightarrow} c, \qquad \mbox{ as  } n \to \infty.
\end{align}
\end{proposition}

\section{Discussion}\label{sec:Disc}
In this paper we have studied a notion of multivariate ranks and quantiles based on the theory of optimal transportation. We have also proposed multivariate goodness-of-fit tests based on these empirical ranks and quantiles. One of the main motivations for proposing such test statistics (see e.g.,~\eqref{eq:2-S-TS} and~\eqref{eq:Ind-TS}) is that the resulting tests can be asymptotically distribution-free, borrowing the analogy from one-dimension and the established distribution-freeness of the multivariate ranks (see Lemma~\ref{lem:Distfree}, Proposition~\ref{lem:Power2} and the simulation studies in Section~\ref{sec:Simul}); see Sections~\ref{sec:2S-Goodness-Fit-Test} and~\ref{sec:IndepTest} for the details. However, we do not have a proof of the distribution-freeness of the proposed tests, and believe that it would be an interesting future problem.

In Theorem~\ref{thm:GCProp} we establish the uniform a.s.~consistency of the empirical rank and quantile maps under the assumption that their population analogues are homeomorphisms. In Proposition~\ref{thm:Q_prop} we also provide a sufficient condition for this to hold. It is worth exploring if other sufficient conditions, that can arise naturally in statistics, also imply the same conclusions. Note that when $d=1$, the empirical rank function converges to its population counterpart under no assumptions on the target measure. It is not clear to us if such a result holds beyond $d=1$ without further assumptions.

Corollary~\ref{thm:RateTheo} shows a local uniform rate of convergence of the empirical quantile and rank functions when the reference measure is the same as the target measure.
However our proof strategy fails to generalize when the reference measure is different from the target measure.
We consider this as an important open problem; also see~\cite{AST19}.

\section*{Acknowledgements}
We are extremely grateful to Peng Xu for creating the R-package \url{https://github.com/Francis-Hsu/testOTM} (see~\cite{OTM}) for the computation of all the estimators studied in this paper. In particular, all the plots in the paper are obtained from his R-package. The second author would like to thank Marc Hallin for sharing an early version of his manuscript and Johan Segers for helpful discussions.

Statistics Theory (math.ST); Probability (math.PR)