<!DOCTYPE html>
<!-- Generated by pkgdown: do not edit by hand --><html lang="en"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"><meta name="description" content="Calculate the pairwise colocation quotient (CLQ) for two categorical variables using conditional permutation."><title>Pairwise Colocation Quotient — pairwise_colocation • sfdep</title><script src="../deps/jquery-3.6.0/jquery-3.6.0.min.js"></script><meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"><link href="../deps/bootstrap-5.3.1/bootstrap.min.css" rel="stylesheet"><script src="../deps/bootstrap-5.3.1/bootstrap.bundle.min.js"></script><link href="../deps/Noto_Sans_Display-0.4.8/font.css" rel="stylesheet"><link href="../deps/Noto_Sans_Mono-0.4.8/font.css" rel="stylesheet"><link href="../deps/Merriweather-0.4.8/font.css" rel="stylesheet"><!-- Font Awesome icons --><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.12.1/css/all.min.css" integrity="sha256-mmgLkCYLUQbXn0B1SRqzHar6dCnv9oZFPEC1g1cwlkk=" crossorigin="anonymous"><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.12.1/css/v4-shims.min.css" integrity="sha256-wZjR52fzng1pJHwx4aV2AO3yyTOXrcDW7jBpJtTwVxw=" crossorigin="anonymous"><!-- bootstrap-toc --><script src="https://cdn.jsdelivr.net/gh/afeld/bootstrap-toc@v1.0.1/dist/bootstrap-toc.min.js" integrity="sha256-4veVQbu7//Lk5TSmc7YV48MxtMy98e26cf5MrgZYnwo=" crossorigin="anonymous"></script><!-- headroom.js --><script src="https://cdnjs.cloudflare.com/ajax/libs/headroom/0.11.0/headroom.min.js" integrity="sha256-AsUX4SJE1+yuDu5+mAVzJbuYNPHj/WroHuZ8Ir/CkE0=" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/headroom/0.11.0/jQuery.headroom.min.js" integrity="sha256-ZX/yNShbjqsohH1k95liqY9Gd8uOiE1S4vZc+9KQ1K4=" crossorigin="anonymous"></script><!-- clipboard.js --><script src="https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.6/clipboard.min.js" integrity="sha256-inc5kl9MA1hkeYUt+EC3BhlIgyp/2jDIyBLS6k3UxPI=" crossorigin="anonymous"></script><!-- search --><script src="https://cdnjs.cloudflare.com/ajax/libs/fuse.js/6.4.6/fuse.js" integrity="sha512-zv6Ywkjyktsohkbp9bb45V6tEMoWhzFzXis+LrMehmJZZSys19Yxf1dopHx7WzIKxr5tK2dVcYmaCk2uqdjF4A==" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/autocomplete.js/0.38.0/autocomplete.jquery.min.js" integrity="sha512-GU9ayf+66Xx2TmpxqJpliWbT5PiGYxpaG8rfnBEk1LL8l1KGkRShhngwdXK1UgqhAzWpZHSiYPc09/NwDQIGyg==" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/mark.js/8.11.1/mark.min.js" integrity="sha512-5CYOlHXGh6QpOFA/TeTylKLWfB3ftPsde7AnmhuitiTX4K5SqCLBeKro6sPS8ilsz1Q4NRx3v8Ko2IBiszzdww==" crossorigin="anonymous"></script><!-- pkgdown --><script src="../pkgdown.js"></script><meta property="og:title" content="Pairwise Colocation Quotient — pairwise_colocation"><meta property="og:description" content="Calculate the pairwise colocation quotient (CLQ) for two categorical variables using conditional permutation."><!-- mathjax --><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js" integrity="sha256-nvJJv9wWKEm88qvoQl9ekL2J+k/RWIsaSScxxlsrv8k=" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/config/TeX-AMS-MML_HTMLorMML.js" integrity="sha256-84DKXVJXs0/F8OTMzX4UR909+jtl4G7SPypPavF+GfA=" crossorigin="anonymous"></script><!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]--></head><body>
    <a href="#main" class="visually-hidden-focusable">Skip to contents</a>
    

    <nav class="navbar fixed-top navbar-light navbar-expand-lg bg-light"><div class="container">
    
    <a class="navbar-brand me-2" href="../index.html">sfdep</a>

    <small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">0.2.4</small>

    
    <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbar" aria-controls="navbar" aria-expanded="false" aria-label="Toggle navigation">
      <span class="navbar-toggler-icon"></span>
    </button>

    <div id="navbar" class="collapse navbar-collapse ms-3">
      <ul class="navbar-nav me-auto"><li class="active nav-item">
  <a class="nav-link" href="../reference/index.html">Reference</a>
</li>
<li class="nav-item dropdown">
  <a href="#" class="nav-link dropdown-toggle" data-bs-toggle="dropdown" role="button" aria-expanded="false" aria-haspopup="true" id="dropdown-vignettes">Vignettes</a>
  <div class="dropdown-menu" aria-labelledby="dropdown-vignettes">
    <a class="dropdown-item" href="../articles/basics-of-sfdep.html">Basics of sfdep</a>
    <a class="dropdown-item" href="../articles/spacetime-s3.html">spacetime and spacetime cubes</a>
    <a class="dropdown-item" href="../articles/colocation-analysis.html">Colocation Quotients</a>
    <a class="dropdown-item" href="../articles/conditional-permutation.html">Conditional permutation</a>
    <a class="dropdown-item" href="../articles/understanding-emerging-hotspots.html">Emerging Hot Spot Analysis</a>
  </div>
</li>
<li class="nav-item">
  <a class="nav-link" href="../news/index.html">Changelog</a>
</li>
<li class="nav-item dropdown">
  <a href="#" class="nav-link dropdown-toggle" data-bs-toggle="dropdown" role="button" aria-expanded="false" aria-haspopup="true" id="dropdown-releases">Releases</a>
  <div class="dropdown-menu" aria-labelledby="dropdown-releases">
    <a class="dropdown-item" href="../articles/Version-0-2-0.html">Version 0.2.0</a>
  </div>
</li>
      </ul><form class="form-inline my-2 my-lg-0" role="search">
        <input type="search" class="form-control me-sm-2" aria-label="Toggle navigation" name="search-input" data-search-index="../search.json" id="search-input" placeholder="Search for" autocomplete="off"></form>

      <ul class="navbar-nav"><li class="nav-item">
  <a class="external-link nav-link" href="https://github.com/josiahparry/sfdep/" aria-label="github">
    <span class="fab fa fab fa-github fa-lg"></span>
     
  </a>
</li>
      </ul></div>

    
  </div>
</nav><div class="container template-reference-topic">
<div class="row">
  <main id="main" class="col-md-9"><div class="page-header">
      <img src="" class="logo" alt=""><h1>Pairwise Colocation Quotient</h1>
      <small class="dont-index">Source: <a href="https://github.com/josiahparry/sfdep/blob/HEAD/R/pariwise-colocation-impl.R" class="external-link"><code>R/pariwise-colocation-impl.R</code></a></small>
      <div class="d-none name"><code>pairwise_colocation.Rd</code></div>
    </div>

    <div class="ref-description section level2">
    <p>Calculate the pairwise colocation quotient (CLQ) for two categorical variables using conditional permutation.</p>
    </div>

    <div class="section level2">
    <h2 id="ref-usage">Usage<a class="anchor" aria-label="anchor" href="#ref-usage"></a></h2>
    <div class="sourceCode"><pre class="sourceCode r"><code><span><span class="fu">pairwise_colocation</span><span class="op">(</span><span class="va">A</span>, <span class="va">B</span>, <span class="va">nb</span>, nsim <span class="op">=</span> <span class="fl">99</span><span class="op">)</span></span></code></pre></div>
    </div>

    <div class="section level2">
    <h2 id="arguments">Arguments<a class="anchor" aria-label="anchor" href="#arguments"></a></h2>
    <dl><dt>A</dt>
<dd><p>a character or factor vector.</p></dd>


<dt>B</dt>
<dd><p>a character or factor vector.</p></dd>


<dt>nb</dt>
<dd><p>a neighbors list e.g. created by <code><a href="st_knn.html">st_knn()</a></code> or <code><a href="st_contiguity.html">st_contiguity()</a></code></p></dd>


<dt>nsim</dt>
<dd><p>default <code>99</code>. An integer representing how many simulations to run for calculating the simulated p-values.</p></dd>

</dl></div>
    <div class="section level2">
    <h2 id="value">Value<a class="anchor" aria-label="anchor" href="#value"></a></h2>
    

<p>A matrix where the rownames are the unique values of A and the column names are the unique values of B and their simulated p-values in the form of <code>p_sim_{B}</code>.</p>
    </div>
    <div class="section level2">
    <h2 id="details">Details<a class="anchor" aria-label="anchor" href="#details"></a></h2>
    
<div class="section">
<h3 id="intuition">Intuition<a class="anchor" aria-label="anchor" href="#intuition"></a></h3>


<p>The pairwise CLQ is used to test if there is a spatial directional association between subcategories of two vectors <code>A</code> and <code>B</code>. Compared to the cross-K metric and the join count statistic, the pairwise CLQ can elucidate the presence of an asymmetric relationship between subcategories of A and B. A and B can either be separate categorical vectors or the same categorical vector.</p>
<p>"The null hypothesis for a CLQ-based analysis is 'given the clustering of the joint population, there is no spatial association between pairs of categorical subsets.'"</p>
</div>

<div class="section">
<h3 id="definition">Definition<a class="anchor" aria-label="anchor" href="#definition"></a></h3>


<p>The pairwise colocation quotient is defined as "the ratio of observed to expected proportions of B among A's nearest neighbors. Formally this is given by
\(CLQ_{A \to B} = \frac{{C_{A \to B} / N_A}}{N^{'}_{B} / (N - 1)}\)" where \(C_{A \to B} = \sum_{i = 1}^{N_A}\sum_{j = 1}^{v}\frac{B_{ij}(1,0)}{v}\).</p>
</div>

<div class="section">
<h3 id="inference">Inference<a class="anchor" aria-label="anchor" href="#inference"></a></h3>


<p>Inference is done using conditional permutation as suggested by Anselin 1995 where a number of replicates are created. The observed values are compared to the replicates and a the simulated p-value is the proportion of cases where the observed is more extreme as compared to replicate. The simulated p-value returns the lower p-value of either tail.</p>
</div>

<div class="section">
<h3 id="interpretation">Interpretation<a class="anchor" aria-label="anchor" href="#interpretation"></a></h3>


<p>Given that the CLQ is a ratio of the observed to expected, we interpret values larger than one to mean that there is more colocation than to be expected under the null hypothesis of no spatial association. When the value is smaller than 0, we interpret it to mean that there is less colocation than expected under the null.</p>
</div>

    </div>

    <div class="section level2">
    <h2 id="ref-examples">Examples<a class="anchor" aria-label="anchor" href="#ref-examples"></a></h2>
    <div class="sourceCode"><pre class="sourceCode r"><code><span class="r-in"><span><span class="va">A</span> <span class="op">&lt;-</span> <span class="va">guerry</span><span class="op">$</span><span class="va">main_city</span></span></span>
<span class="r-in"><span><span class="va">B</span> <span class="op">&lt;-</span> <span class="va">guerry</span><span class="op">$</span><span class="va">region</span></span></span>
<span class="r-in"><span><span class="va">nb</span> <span class="op">&lt;-</span> <span class="fu"><a href="st_knn.html">st_knn</a></span><span class="op">(</span><span class="fu">sf</span><span class="fu">::</span><span class="fu"><a href="https://r-spatial.github.io/sf/reference/st_geometry.html" class="external-link">st_geometry</a></span><span class="op">(</span><span class="va">guerry</span><span class="op">)</span>, <span class="fl">5</span><span class="op">)</span></span></span>
<span class="r-msg co"><span class="r-pr">#&gt;</span> <span style="color: #BBBB00;">!</span> Polygon provided. Using point on surface.</span>
<span class="r-in"><span><span class="fu">pairwise_colocation</span><span class="op">(</span><span class="va">B</span>, <span class="va">A</span>, <span class="va">nb</span><span class="op">)</span></span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span>        1:Sm     2:Med      3:Lg p_sim_1:Sm p_sim_2:Med p_sim_3:Lg</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> C 0.8894118 1.1250679 0.1976471       0.43        0.00       0.00</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> E 1.8776471 0.8514027 0.9882353       0.00        0.01       0.46</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> N 0.1976471 1.0794570 1.1858824       0.00        0.04       0.21</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> S 1.5811765 0.9122172 0.8894118       0.01        0.05       0.41</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> W 0.6917647 1.0338462 0.9882353       0.20        0.24       0.49</span>
<span class="r-in"><span><span class="fu">pairwise_colocation</span><span class="op">(</span><span class="va">B</span>, <span class="va">B</span>, <span class="va">nb</span>, <span class="fl">199</span><span class="op">)</span></span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span>           C         E         N         S         W p_sim_C p_sim_E p_sim_N</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> C 3.5205882 0.3705882 0.4941176 0.3088235 0.5558824   0.000   0.000    0.00</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> E 0.4323529 3.8294118 0.4941176 0.4941176 0.0000000   0.005   0.000    0.01</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> N 0.4323529 0.5558824 3.9529412 0.0000000 0.3088235   0.000   0.025    0.00</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> S 0.3705882 0.5558824 0.0000000 3.9529412 0.3705882   0.000   0.005    0.00</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> W 0.5558824 0.0000000 0.3088235 0.4941176 3.8911765   0.005   0.000    0.00</span>
<span class="r-out co"><span class="r-pr">#&gt;</span>   p_sim_S p_sim_W</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> C    0.00   0.015</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> E    0.01   0.000</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> N    0.00   0.000</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> S    0.00   0.000</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> W    0.00   0.000</span>
</code></pre></div>
    </div>
  </main><aside class="col-md-3"><nav id="toc"><h2>On this page</h2>
    </nav></aside></div>


    <footer><div class="pkgdown-footer-left">
  <p></p><p>Developed by Josiah Parry, Dexter H Locke.</p>
</div>

<div class="pkgdown-footer-right">
  <p></p><p>Site built with <a href="https://pkgdown.r-lib.org/" class="external-link">pkgdown</a> 2.0.7.</p>
</div>

    </footer></div>

  

  

  </body></html>

