<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Distance Metrics |</title><link>https://kristianeschenburg.netlify.app/tag/distance-metrics/</link><atom:link href="https://kristianeschenburg.netlify.app/tag/distance-metrics/index.xml" rel="self" type="application/rss+xml"/><description>Distance Metrics</description><generator>Source Themes Academic (https://sourcethemes.com/academic/)</generator><language>en-us</language><lastBuildDate>Wed, 24 Jun 2020 15:27:11 -0700</lastBuildDate><image><url>https://kristianeschenburg.netlify.app/img/Bayes.jpg</url><title>Distance Metrics</title><link>https://kristianeschenburg.netlify.app/tag/distance-metrics/</link></image><item><title>Distances Between Subspaces</title><link>https://kristianeschenburg.netlify.app/post/comparing-subspaces/</link><pubDate>Wed, 24 Jun 2020 15:27:11 -0700</pubDate><guid>https://kristianeschenburg.netlify.app/post/comparing-subspaces/</guid><description>&lt;p>I&amp;rsquo;m working with some multi-dimensional float-valued data &amp;ndash; I&amp;rsquo;ll call a single instance of this data $X \in \mathbb{R}^{n \times k}$. I have multiple samples $X_{1}, X_{2}&amp;hellip;X_{t}$, and want to compare these subspaces &amp;ndash; namely, I want to compute the distance between pairs of subspaces.&lt;/p>
&lt;p>Let&amp;rsquo;s assume that our subspaces are not rank-deficient &amp;ndash; i.e. for a given subspace sample, all of our dimensions are linearly independent. Thus, the $k$ vectors form a basis set that spans some $k$-d subspace in $\mathbb{R}^{n}$. We can think of each $k$-d subspace as a hyperplane in $(k+1)$-d space, just as we can think of a 2-d plane in 3-d space. One way to compare these subspaces is by using the &amp;ldquo;principal angles between subspaces&amp;rdquo; (or
&lt;a href="https://en.wikipedia.org/wiki/Angles_between_flats" target="_blank" rel="noopener">angles between flats&lt;/a>). We can compare the &amp;ldquo;angles&amp;rdquo; between these hyperplanes, which will tell us how &amp;ldquo;far apart&amp;rdquo; the two subspaces are.&lt;/p>
&lt;figure id="figure-intersecting-2d-linear-subspaceshttpswwwresearchgatenetpublication327930102_optimal_exploitation_of_subspace_prior_information_in_matrix_sensing">
&lt;a data-fancybox="" href="https://kristianeschenburg.netlify.app/post/comparing-subspaces/subspaces_hu_664436aa30d376e4.png" data-caption="Intersecting 2D linear
subspaces.">
&lt;img data-src="https://kristianeschenburg.netlify.app/post/comparing-subspaces/subspaces_hu_664436aa30d376e4.png" class="lazyload" alt="" width="640" height="483">
&lt;/a>
&lt;figcaption>
Intersecting 2D linear
&lt;a href="https://www.researchgate.net/publication/327930102_Optimal_Exploitation_of_Subspace_Prior_Information_in_Matrix_Sensing" target="_blank" rel="noopener">subspaces&lt;/a>.
&lt;/figcaption>
&lt;/figure>
&lt;p>This comparison is effectively based on the
&lt;a href="https://en.wikipedia.org/wiki/QR_decomposition" target="_blank" rel="noopener">QR decomposition&lt;/a> and the
&lt;a href="https://en.wikipedia.org/wiki/Singular_value_decomposition" target="_blank" rel="noopener">Singular Value Decomposition&lt;/a>. For two subspaces $[U, W]$, we compute the QR decomposition of both:&lt;/p>
&lt;p>$$\begin{align}
U &amp;amp;= Q_{u}R_{u}\\
W &amp;amp;= Q_{w}R_{w}\\
\end{align}$$&lt;/p>
&lt;p>where $Q_{u}$ and $Q_{w} \in \mathbb{R}^{n \times k}$ are orthonormal bases such that $Q_{u}^{T}Q_{u} = Q_{w}^{T}Q_{w} = I_{k}$ that span the same subspace as the original columns of $U$ and $W$, and $R_{u}$ and $R_{w} \in \mathbb{R}^{k \times k}$ are upper triangular matrices. Next, we compute the matrix $D = \langle Q_{u}, Q_{w} \rangle = Q_{u}^{T} Q_{w} \in \mathbb{R}^{k \times k}$, and then apply the singular value decomposition:&lt;/p>
&lt;p>$$\begin{align}
D = USV^{T}
\end{align}$$&lt;/p>
&lt;p>We can sort of think of $D$ as the cross-covariance matrix. As such, the singular vectors represent the main orthogonal axes of cross-covariation between our two subspaces, while the singular values represent angles. In order to compute the principal angles of our subspaces, we simply take&lt;/p>
&lt;p>$$\begin{align}
\theta &amp;amp;= cos^{-1}(S) \\
&amp;amp;=cos^{-1}[\sigma_{1}, \sigma_{2}&amp;hellip;\sigma_{k}]
\end{align}$$&lt;/p>
&lt;p>which gives us the principal angles (in radians). Because the SVD is invariant to sign (+/-), the principal angles range between $\Big[0, \frac{\pi}{2}\Big]$. This means that subspaces that span the same space have a principal angle of 0, and subspaces that are orthogonal (maximally far apart) to one another have a principal angle of $\frac{\pi}{2}$.&lt;/p>
&lt;p>In order to compute the &amp;ldquo;distance&amp;rdquo; between our subspaces, we can apply
&lt;a href="https://galton.uchicago.edu/~lekheng/work/schubert.pdf" target="_blank" rel="noopener">various metrics&lt;/a> to our vector of principal angles. The simplest approach is to apply the $L2$ norm to our vector of principal angles, $\theta$, as&lt;/p>
&lt;p>$$\begin{align}
d(X_{i}, X_{j}) = \sqrt{\sum_{n=1}^{k} cos^{-1}(\sigma_{n})^{2}}
\end{align}$$&lt;/p>
&lt;p>This metric is called the
&lt;a href="http://www.eeci-institute.eu/GSC2011/Photos-EECI/EECI-GSC-2011-M5/book_AMS.pdf" target="_blank" rel="noopener">Grassmann Distance&lt;/a> and is formally related to the geodesic distance between subspaces distributed on the Grassmannian manifold.&lt;/p>
&lt;figure id="figure-grassmann-manifold-and-its-tangent-spacehttpsdeepaiorgpublicationautomatic-recognition-of-space-time-constellations-by-learning-on-the-grassmann-manifold-extended-version">
&lt;a data-fancybox="" href="https://kristianeschenburg.netlify.app/post/comparing-subspaces/grassmann_hu_27eb0bb5a47e713.png" data-caption="Grassmann manifold and its
tangent space.">
&lt;img data-src="https://kristianeschenburg.netlify.app/post/comparing-subspaces/grassmann_hu_27eb0bb5a47e713.png" class="lazyload" alt="" width="398" height="249">
&lt;/a>
&lt;figcaption>
Grassmann manifold and its
&lt;a href="https://deepai.org/publication/automatic-recognition-of-space-time-constellations-by-learning-on-the-grassmann-manifold-extended-version" target="_blank" rel="noopener">tangent space&lt;/a>.
&lt;/figcaption>
&lt;/figure>
&lt;p>This, however, is a topic for another future blog post. There are a variety of metrics we can use to compute the pairwise distance between subspaces, some of which are&lt;/p>
&lt;ul>
&lt;li>Asimov: $\; max(\theta)$&lt;/li>
&lt;li>Fubini-Study: $\; cos^{-1}(\prod sin(\theta))$&lt;/li>
&lt;li>Spectral: $\; 2 sin(\frac{max(\theta)}{2})$&lt;/li>
&lt;/ul>
&lt;p>but all are fundamentally based on some function of our vector of principal angles, $\theta$.&lt;/p></description></item><item><title>Mahalanobis Distances of Brain Connectivity</title><link>https://kristianeschenburg.netlify.app/post/mahalanobis-distances-of-brain-connectivity/</link><pubDate>Fri, 07 Dec 2018 05:12:32 -0700</pubDate><guid>https://kristianeschenburg.netlify.app/post/mahalanobis-distances-of-brain-connectivity/</guid><description>&lt;p>For one of the projects I&amp;rsquo;m working on, I have an array of multivariate data relating to brain connectivity patterns. Briefly, each brain is represented as a surface mesh, which we represent as a graph $G = (V,E)$, where $V$ is a set of $n$ vertices, and $E$ is the set of edges between vertices.&lt;/p>
&lt;p>Additionally, for each vertex $v \in V$, we also have an associated scalar &lt;em>label&lt;/em>, which we&amp;rsquo;ll denote $l(v)$, that identifies what region of the cortex each vertex belongs to, the set of regions which we define as $L = {1, 2, &amp;hellip; k}$. And finally, for each vertex $v \in V$, we also have a multivariate feature vector $r(v) \in \mathbb{R}^{1 \times k}$, that describes the strength of connectivity between it, and every region $l \in L$.&lt;/p>
&lt;figure id="figure-example-of-cortical-map-and-array-of-connectivity-features">
&lt;a data-fancybox="" href="https://kristianeschenburg.netlify.app/post/mahalanobis-distances-of-brain-connectivity/parcellation_hu_ff318333e3f2fe17.png" data-caption="Example of cortical map, and array of connectivity features.">
&lt;img data-src="https://kristianeschenburg.netlify.app/post/mahalanobis-distances-of-brain-connectivity/parcellation_hu_ff318333e3f2fe17.png" class="lazyload" alt="" width="1296" height="432">
&lt;/a>
&lt;figcaption>
Example of cortical map, and array of connectivity features.
&lt;/figcaption>
&lt;/figure>
&lt;p>I&amp;rsquo;m interested in examining how &amp;ldquo;close&amp;rdquo; the connectivity samples of one region, $l_{j}$, are to another region, $l_{k}$. In the univariate case, one way to compare a scalar sample to a distribution is to use the $t$-statistic, which measures how many standard deviations away from the mean a given sample is:&lt;/p>
&lt;p>$$\begin{align}
t_{s} = \frac{\bar{x} - \mu}{\frac{s}{\sqrt{n}}}
\end{align}$$&lt;/p>
&lt;p>where $\mu$ is the population mean, and $s$ is the sample standard deviation. If we square this, we get:&lt;/p>
&lt;p>$$\begin{align}
t^{2} = \frac{(\bar{x} - \mu)^{2}}{\frac{s^{2}}{n}} = \frac{n (\bar{x} - \mu)^{2}}{S^{2}} \sim F(1,n)
\end{align}$$&lt;/p>
&lt;p>We know the last part is true, because the numerator and denominator are independent $\chi^{2}$ distributed random variables. However, I&amp;rsquo;m not working with univariate data &amp;ndash; I have multivariate data. The multivariate generalization of the $t$-statistic is the
&lt;a href="https://en.wikipedia.org/wiki/Mahalanobis_distance" target="_blank" rel="noopener">Mahalanobis Distance&lt;/a>:&lt;/p>
&lt;p>$$\begin{align}
d &amp;amp;= \sqrt{(\bar{x} - \mu)\Sigma^{-1}(\bar{x}-\mu)^{T}}
\end{align}$$&lt;/p>
&lt;p>where the squared Mahalanobis Distance is:&lt;/p>
&lt;p>$$\begin{align}
d^{2} &amp;amp;= (\bar{x} - \mu)\Sigma^{-1}(\bar{x}-\mu)^{T}
\end{align}$$&lt;/p>
&lt;p>where $\Sigma^{-1}$ is the inverse covariance matrix. If our $X$&amp;rsquo;s were initially distributed with a multivariate normal distribution, $N_{p}(\mu,\Sigma)$ (assuming $\Sigma$ is non-degenerate i.e. positive definite), the squared Mahalanobis distance, $d^{2}$ has a $\chi^{2}_{p}$ distribution. We show this below.&lt;/p>
&lt;p>We know that $(X-\mu)$ is distributed $N_{p}(0,\Sigma)$. We also know that, since $\Sigma$ is symmetric and real, that we can compute the eigendecomposition of $\Sigma$ as:&lt;/p>
&lt;p>$$\begin{align}
\Sigma = U \Lambda U^{T}
\end{align}$$&lt;/p>
&lt;p>and consequently, because $U$ is an orthogonal matrix, and because $\Lambda$ is diagonal, we know that $\Sigma^{-1}$ is:&lt;/p>
&lt;p>$$\begin{align}
\Sigma^{-1} &amp;amp;= (U \Lambda U^{T})^{-1} \\
&amp;amp;= U \Lambda^{-1} U^{T} \\
&amp;amp;= (U \Lambda^{\frac{-1}{2}}) (U \Lambda^{\frac{-1}{2}})^{T} \\
&amp;amp;= R R^{T}
\end{align}$$&lt;/p>
&lt;p>Therefore, we know that $R^{T}(X-\mu) \sim N_{p}(0,I_{p})$:&lt;/p>
&lt;p>$$\begin{align}
X &amp;amp;\sim N_{p}(\mu,\Sigma) \\
(X-\mu) = Y &amp;amp;\sim N_{p}(0,\Sigma)\\
R^{T}Y = Z &amp;amp;\sim N_{p}(0, R^{T} \Sigma R) \\
&amp;amp;\sim N_{p}(0, \Lambda^{\frac{-1}{2}} U^{T} (U \Lambda U^{T}) U \Lambda^{\frac{-1}{2}}) \\
&amp;amp;\sim N_{p}(0, \Lambda^{\frac{-1}{2}} I_{p} \Lambda I_{p} \Lambda^{\frac{-1}{2}}) \\
&amp;amp;\sim N_{p}(0,I_{p})
\end{align}$$&lt;/p>
&lt;p>so that we have&lt;/p>
&lt;p>$$\begin{align}
&amp;amp;= (X-\mu)\Sigma^{-1}(X-\mu)^{T} \\
&amp;amp;= (X-\mu)RR^{T}(X-\mu)^{T} \\
&amp;amp;= Z^{T}Z
\end{align}$$&lt;/p>
&lt;p>the sum of $p$ squared standard Normal random variables, which is the definition of a $\chi_{p}^{2}$ distribution with $p$ degrees of freedom. So, given that we start with a $MVN$ random variable, the squared Mahalanobis distance is $\chi^{2}_{p}$ distributed. Because the sample mean and sample covariance are consistent estimators of the population mean and population covariance parameters, we can use these estimates in our computation of the Mahalanobis distance.&lt;/p>
&lt;p>Also, of particular importance is the fact that the Mahalanobis distance is &lt;strong>not symmetric&lt;/strong>. That is to say, if we define the Mahalanobis distance as:&lt;/p>
&lt;p>$$\begin{align}
M(A, B) = \sqrt{(A - \mu(B))\Sigma(B)^{-1}(A-\mu(B))^{T}}
\end{align}$$&lt;/p>
&lt;p>then $M(A,B) \neq M(B,A)$, clearly. Because the parameter estimates are not guaranteed to be the same, it&amp;rsquo;s straightforward to see why this is the case.&lt;/p>
&lt;p>Now, back to the task at hand. For a specified target region, $l_{T}$, with a set of vertices, $V_{T} = {v \; : \; l(v) \; = \; l_{T}, \; \forall \; v \in V}$, each with their own distinct connectivity fingerprints, I want to explore which areas of the cortex have connectivity fingerprints that are different from or similar to $l_{T}$&amp;rsquo;s features, in distribution. I can do this by using the Mahalanobis Distance. And based on the analysis I showed above, we know that the data-generating process of these distances is related to the $\chi_{p}^{2}$ distribution.&lt;/p>
&lt;p>First, I&amp;rsquo;ll estimate the covariance matrix, $\Sigma_{T}$, of our target region, $l_{T}$, using the
&lt;a href="http://perso.ens-lyon.fr/patrick.flandrin/LedoitWolf_JMA2004.pdf" target="_blank" rel="noopener">Ledoit-Wolf estimator&lt;/a> (the shrunken covariance estimate has been shown to be a more reliable estimate of the population covariance), and mean connectivity fingerprint, $\mu_{T}$. Then, I&amp;rsquo;ll compute $d^{2} = M^{2}(A,A)$ for every $\{v: v \in V_{T}\}$. The empirical distribution of these distances should follow a $\chi_{p}^{2}$ distribution. If we wanted to do hypothesis testing, we would use this distribution as our null distribution.&lt;/p>
&lt;p>Next, in order to assess whether this intra-regional similarity is actually informative, I&amp;rsquo;ll also compute the similarity of $l_{T}$ to every other region, $\{ l_{k} \; : \; \forall \; k \in L \setminus \{T\} \}$ &amp;ndash; that is, I&amp;rsquo;ll compute $M^{2}(A, B) \; \forall \; B \in L \setminus T$. If the connectivity samples of our region of interest are as similar to one another as they are to other regions, then $d^{2}$ doesn&amp;rsquo;t really offer us any discriminating information &amp;ndash; I don&amp;rsquo;t expect this to be the case, but we need to verify this.&lt;/p>
&lt;p>Then, as a confirmation step to ensure that our empirical data actually follows the theoretical $\chi_{p}^{2}$ distribution, I&amp;rsquo;ll compute the location and scale
&lt;a href="https://en.wikipedia.org/wiki/Maximum_likelihood_estimation" target="_blank" rel="noopener">Maximum Likelihood&lt;/a>(MLE) parameter estimates of our $d^{2}$ distribution, keeping the &lt;em>d.o.f.&lt;/em> (i.e. $p$) fixed.&lt;/p>
&lt;p>See below for Python code and figures&amp;hellip;&lt;/p>
&lt;h3 id="step-1-compute-parameter-estimates">Step 1: Compute Parameter Estimates&lt;/h3>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-python" data-lang="python">&lt;span class="line">&lt;span class="cl">&lt;span class="o">%&lt;/span>&lt;span class="n">matplotlib&lt;/span> &lt;span class="n">inline&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="kn">import&lt;/span> &lt;span class="nn">matplotlib.pyplot&lt;/span> &lt;span class="k">as&lt;/span> &lt;span class="nn">plt&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="kn">from&lt;/span> &lt;span class="nn">matplotlib&lt;/span> &lt;span class="kn">import&lt;/span> &lt;span class="n">rc&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="n">rc&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s1">&amp;#39;text&amp;#39;&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">usetex&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="kc">True&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="kn">import&lt;/span> &lt;span class="nn">numpy&lt;/span> &lt;span class="k">as&lt;/span> &lt;span class="nn">np&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="kn">from&lt;/span> &lt;span class="nn">scipy.spatial.distance&lt;/span> &lt;span class="kn">import&lt;/span> &lt;span class="n">cdist&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="kn">from&lt;/span> &lt;span class="nn">scipy.stats&lt;/span> &lt;span class="kn">import&lt;/span> &lt;span class="n">chi2&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">probplot&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="kn">from&lt;/span> &lt;span class="nn">sklearn&lt;/span> &lt;span class="kn">import&lt;/span> &lt;span class="n">covariance&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-python" data-lang="python">&lt;span class="line">&lt;span class="cl">&lt;span class="c1"># lab_map is a dictionary, mapping label values to sample indices&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1"># our region of interest has a label of 8&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="n">LT&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="mi">8&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1"># get indices for region LT, and rest of brain&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="n">lt_indices&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="n">lab_map&lt;/span>&lt;span class="p">[&lt;/span>&lt;span class="n">LT&lt;/span>&lt;span class="p">]&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="n">rb_indices&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="n">np&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">concatenate&lt;/span>&lt;span class="p">([&lt;/span>&lt;span class="n">lab_map&lt;/span>&lt;span class="p">[&lt;/span>&lt;span class="n">k&lt;/span>&lt;span class="p">]&lt;/span> &lt;span class="k">for&lt;/span> &lt;span class="n">k&lt;/span> &lt;span class="ow">in&lt;/span> &lt;span class="n">lab_map&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">keys&lt;/span>&lt;span class="p">()&lt;/span> &lt;span class="k">if&lt;/span> &lt;span class="n">k&lt;/span> &lt;span class="o">!=&lt;/span> &lt;span class="n">LT&lt;/span>&lt;span class="p">])&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="n">data_lt&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="n">conn&lt;/span>&lt;span class="p">[&lt;/span>&lt;span class="n">lt_indices&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="p">:]&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="n">data_rb&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="n">conn&lt;/span>&lt;span class="p">[&lt;/span>&lt;span class="n">rb_indices&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="p">:]&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1"># fit covariance and precision matrices&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1"># Shrinkage factor = 0.2&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="n">cov_lt&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="n">covariance&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">ShrunkCovariance&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">assume_centered&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="kc">False&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">shrinkage&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="mf">0.2&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="n">cov_lt&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">fit&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">data_lt&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="n">P&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="n">cov_lt&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">precision_&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>Next, compute the Mahalanobis Distances:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-python" data-lang="python">&lt;span class="line">&lt;span class="cl">&lt;span class="c1"># LT to LT Mahalanobis Distance&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="n">dist_lt&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="n">cdist&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">data_lt&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">data_lt&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">mean&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="mi">0&lt;/span>&lt;span class="p">)[&lt;/span>&lt;span class="kc">None&lt;/span>&lt;span class="p">,:],&lt;/span> &lt;span class="n">metric&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="s1">&amp;#39;mahalanobis&amp;#39;&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">VI&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="n">P&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="n">dist_lt2&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="n">dist_lt&lt;/span>&lt;span class="o">**&lt;/span>&lt;span class="mi">2&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1"># fit covariance estimate for every region in cortical map&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="n">EVs&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="p">{&lt;/span>&lt;span class="n">l&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="n">covariance&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">ShrunkCovariance&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">assume_centered&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="kc">False&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">shrinkage&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="mf">0.2&lt;/span>&lt;span class="p">)&lt;/span> &lt;span class="k">for&lt;/span> &lt;span class="n">l&lt;/span> &lt;span class="ow">in&lt;/span> &lt;span class="n">labels&lt;/span>&lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="k">for&lt;/span> &lt;span class="n">l&lt;/span> &lt;span class="ow">in&lt;/span> &lt;span class="n">lab_map&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">keys&lt;/span>&lt;span class="p">():&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">EVs&lt;/span>&lt;span class="p">[&lt;/span>&lt;span class="n">l&lt;/span>&lt;span class="p">]&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">fit&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">conn&lt;/span>&lt;span class="p">[&lt;/span>&lt;span class="n">lab_map&lt;/span>&lt;span class="p">[&lt;/span>&lt;span class="n">l&lt;/span>&lt;span class="p">],:])&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1"># compute d^2 from LT to every cortical region&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1"># save distances in dictionary&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="n">lt_to_brain&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="p">{}&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">fromkeys&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">labels&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="k">for&lt;/span> &lt;span class="n">l&lt;/span> &lt;span class="ow">in&lt;/span> &lt;span class="n">lab_map&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">keys&lt;/span>&lt;span class="p">():&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">temp_data&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="n">conn&lt;/span>&lt;span class="p">[&lt;/span>&lt;span class="n">label_map&lt;/span>&lt;span class="p">[&lt;/span>&lt;span class="n">l&lt;/span>&lt;span class="p">],&lt;/span> &lt;span class="p">:]&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">temp_mu&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="n">temp_data&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">mean&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="mi">0&lt;/span>&lt;span class="p">)[&lt;/span>&lt;span class="kc">None&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="p">:]&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">temp_mh&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="n">cdist&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">data_lt&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">temp_mu&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">metric&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="s1">&amp;#39;mahalanobis&amp;#39;&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">VI&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="n">EVs&lt;/span>&lt;span class="p">[&lt;/span>&lt;span class="n">l&lt;/span>&lt;span class="p">]&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">precision_&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">temp_mh2&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="n">temp_mh&lt;/span>&lt;span class="o">**&lt;/span>&lt;span class="mi">2&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">lt_to_brain&lt;/span>&lt;span class="p">[&lt;/span>&lt;span class="n">l&lt;/span>&lt;span class="p">]&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="n">temp_mh2&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1"># plot distributions seperate (scales differ)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="n">fig&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="n">plt&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">subplots&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="mi">2&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="mi">1&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">figsize&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="mi">12&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="mi">12&lt;/span>&lt;span class="p">))&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="n">plt&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">subplot&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="mi">2&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="mi">1&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="mi">1&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="n">plt&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">hist&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">lt_to_brain&lt;/span>&lt;span class="p">[&lt;/span>&lt;span class="n">LT&lt;/span>&lt;span class="p">],&lt;/span> &lt;span class="mi">50&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">density&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="kc">True&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">color&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="s1">&amp;#39;blue&amp;#39;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">label&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="s1">&amp;#39;Region-to-Self&amp;#39;&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">alpha&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="mf">0.7&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="n">plt&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">subplot&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="mi">2&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="mi">1&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="mi">2&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="k">for&lt;/span> &lt;span class="n">l&lt;/span> &lt;span class="ow">in&lt;/span> &lt;span class="n">labels&lt;/span>&lt;span class="p">:&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">if&lt;/span> &lt;span class="n">l&lt;/span> &lt;span class="o">!=&lt;/span> &lt;span class="n">LT&lt;/span>&lt;span class="p">:&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">plt&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">hist&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">lt_to_brain&lt;/span>&lt;span class="p">[&lt;/span>&lt;span class="n">l&lt;/span>&lt;span class="p">],&lt;/span> &lt;span class="mi">50&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">density&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="kc">True&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">linewidth&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="mi">2&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">alpha&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="mf">0.4&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">histtype&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="s1">&amp;#39;step&amp;#39;&lt;/span>&lt;span class="p">)&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>
&lt;figure id="figure-empirical-distributions-of-within-region-top-and-between-region-bottom-d2-values--each-line-is-the-distribution-of-the-distance-of-samples-in-our-roi-to-a-whole-region">
&lt;a data-fancybox="" href="https://kristianeschenburg.netlify.app/post/mahalanobis-distances-of-brain-connectivity/IntraInterMahal_hu_4a20b8ed998a232e.jpg" data-caption="Empirical distributions of within-region (top) and between-region (bottom) $d^{2}$ values. Each line is the distribution of the distance of samples in our ROI to a whole region.">
&lt;img data-src="https://kristianeschenburg.netlify.app/post/mahalanobis-distances-of-brain-connectivity/IntraInterMahal_hu_4a20b8ed998a232e.jpg" class="lazyload" alt="" width="864" height="864">
&lt;/a>
&lt;figcaption>
Empirical distributions of within-region (top) and between-region (bottom) $d^{2}$ values. Each line is the distribution of the distance of samples in our ROI to a whole region.
&lt;/figcaption>
&lt;/figure>
&lt;p>As expected, the distribution of $d^{2}$, the distance of samples in our region of interest, $l_{T}$, to distributions computed from other regions, is (considerably) larger and much more variable, while the profile of points within $l_{T}$ looks to have much smaller variance &amp;ndash; this is good! This means that we have high intra-regional similarity when compared to inter-regional similarities. This fits what&amp;rsquo;s known in neuroscience as the
&lt;a href="https://www.ncbi.nlm.nih.gov/pubmed/9651489" target="_blank" rel="noopener">&amp;ldquo;cortical field hypothesis&amp;rdquo;&lt;/a>.&lt;/p>
&lt;h3 id="step-2-distributional-qc-check">Step 2: Distributional QC-Check&lt;/h3>
&lt;p>Because we know that our data should follow a $\chi^{2}_{p}$ distribution, we can fit the MLE estimate of our location and scale parameters, while keeping the $df$ parameter fixed.&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-python" data-lang="python">&lt;span class="line">&lt;span class="cl">&lt;span class="n">p&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="n">data_lt&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">shape&lt;/span>&lt;span class="p">[&lt;/span>&lt;span class="mi">1&lt;/span>&lt;span class="p">]&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="n">mle_chi2_theory&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="n">chi2&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">fit&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">dist_lt2&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">fdf&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="n">p&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="n">xr&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="n">np&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">linspace&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">data_lt&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">min&lt;/span>&lt;span class="p">(),&lt;/span> &lt;span class="n">data_lt&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">max&lt;/span>&lt;span class="p">(),&lt;/span> &lt;span class="mi">1000&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="n">pdf_chi2_theory&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">xr&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="o">*&lt;/span>&lt;span class="n">mle_chi2_theory&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="n">fig&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="n">plt&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">subplot&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="mi">1&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="mi">2&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="mi">2&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="n">figsize&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="mi">18&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="mi">6&lt;/span>&lt;span class="p">))&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1"># plot theoretical vs empirical null distributon&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="n">plt&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">subplot&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="mi">1&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="mi">2&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="mi">1&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="n">plt&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">hist&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">data_lt&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">density&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="kc">True&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">color&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="s1">&amp;#39;blue&amp;#39;&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">alpha&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="mf">0.6&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">label&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="s1">&amp;#39;Empirical&amp;#39;&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="n">plt&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">plot&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">xr&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">pdf_chi2_theory&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">color&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="s1">&amp;#39;red&amp;#39;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">label&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="s1">&amp;#39;$\chi^&lt;/span>&lt;span class="si">{2}&lt;/span>&lt;span class="s1">_&lt;/span>&lt;span class="si">{p}&lt;/span>&lt;span class="s1">&amp;#39;&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1"># plot QQ plot of empirical distribution&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="n">plt&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">subplot&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="mi">1&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="mi">2&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="mi">2&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="n">probplot&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">D2&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">squeeze&lt;/span>&lt;span class="p">(),&lt;/span> &lt;span class="n">sparams&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="n">mle_chi2_theory&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">dist&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="n">chi2&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">plot&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="n">plt&lt;/span>&lt;span class="p">);&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>
&lt;figure id="figure-density-and-qq-plot-of-null-distribution">
&lt;a data-fancybox="" href="https://kristianeschenburg.netlify.app/post/mahalanobis-distances-of-brain-connectivity/Density.QQPlot_hu_ca5535fcd8e75fcd.png" data-caption="Density and QQ plot of null distribution.">
&lt;img data-src="https://kristianeschenburg.netlify.app/post/mahalanobis-distances-of-brain-connectivity/Density.QQPlot_hu_ca5535fcd8e75fcd.png" class="lazyload" alt="" width="864" height="864">
&lt;/a>
&lt;figcaption>
Density and QQ plot of null distribution.
&lt;/figcaption>
&lt;/figure>
&lt;p>From looking at the QQ plot, we see that the empirical density fits the theoretical density pretty well, but there is some evidence that the empirical density has heavier tails. The heavier tail of the upper quantile could probability be explained by acknowledging that our starting cortical map is not perfect (in fact there is no &amp;ldquo;gold-standard&amp;rdquo; cortical map). Cortical regions do not have discrete cutoffs, although there are reasonably steep
&lt;a href="https://www.ncbi.nlm.nih.gov/pubmed/25316338" target="_blank" rel="noopener">gradients in connectivity&lt;/a>. If we were to include samples that were considerably far away from the the rest of the samples, this would result in inflated densities of higher $d^{2}$ values.&lt;/p>
&lt;p>Likewise, we also made the distributional assumption that our connectivity vectors were multivariate normal &amp;ndash; this might not be true &amp;ndash; in which case our assumption that $d^{2}$ follows a $\chi^{2}_{p}$ would also not hold.&lt;/p>
&lt;p>Finally, let&amp;rsquo;s have a look at some brains! Below, is the region we used as our target &amp;ndash; the connectivity profiles from vertices in this region were used to compute our mean vector and covariance matrix &amp;ndash; we compared the rest of the brain to this region.&lt;/p>
&lt;figure id="figure-region-of-interest">
&lt;a data-fancybox="" href="https://kristianeschenburg.netlify.app/post/mahalanobis-distances-of-brain-connectivity/Region_LT_hu_ac1dbc85f77489a3.png" data-caption="Region of interest.">
&lt;img data-src="https://kristianeschenburg.netlify.app/post/mahalanobis-distances-of-brain-connectivity/Region_LT_hu_ac1dbc85f77489a3.png" class="lazyload" alt="" width="1440" height="821">
&lt;/a>
&lt;figcaption>
Region of interest.
&lt;/figcaption>
&lt;/figure>
&lt;figure id="figure-estimated-squared-mahalanobis-distances-overlaid-on-cortical-surface">
&lt;a data-fancybox="" href="https://kristianeschenburg.netlify.app/post/mahalanobis-distances-of-brain-connectivity/MahalanobisDistance_hu_d2a6bbc02ed1093d.png" data-caption="Estimated squared Mahalanobis distances, overlaid on cortical surface.">
&lt;img data-src="https://kristianeschenburg.netlify.app/post/mahalanobis-distances-of-brain-connectivity/MahalanobisDistance_hu_d2a6bbc02ed1093d.png" class="lazyload" alt="" width="1440" height="821">
&lt;/a>
&lt;figcaption>
Estimated squared Mahalanobis distances, overlaid on cortical surface.
&lt;/figcaption>
&lt;/figure>
&lt;p>Here, larger $d^{2}$ values are in red, and smaller $d^{2}$ are in black. Interestingly, we do see pretty large variance of $d^{2}$ spread across the cortex &amp;ndash; however the values are smoothly varying, but there do exists sharp boundaries. We kind of expected this &amp;ndash; some regions, though geodesically far away, should have similar connectivity profiles if they&amp;rsquo;re connected to the same regions of the cortex. However, the regions with connectivity profiles most different than our target region are not only contiguous (they&amp;rsquo;re not noisy), but follow known anatomical boundaries, as shown by the overlaid boundary map.&lt;/p>
&lt;p>This is interesting stuff &amp;ndash; I&amp;rsquo;d originally intended on just learning more about the Mahalanobis Distance as a measure, and exploring its distributional properties &amp;ndash; but now that I see these results, I think it&amp;rsquo;s definitely worth exploring further!&lt;/p></description></item></channel></rss>