<!-- Generated by pkgdown: do not edit by hand -->
<!DOCTYPE html>
<html lang="en">
  <head>
  <meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>spectral separability — spectral.separability • spatialEco</title>


<!-- jquery -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script>
<!-- Bootstrap -->

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.4.1/css/bootstrap.min.css" integrity="sha256-bZLfwXAP04zRMK2BjiO8iu9pf4FbLqX6zitd+tIvLhE=" crossorigin="anonymous" />

<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.4.1/js/bootstrap.min.js" integrity="sha256-nuL8/2cJ5NDSSwnKD8VqreErSWHtnEP9E7AySL+1ev4=" crossorigin="anonymous"></script>

<!-- bootstrap-toc -->
<link rel="stylesheet" href="../bootstrap-toc.css">
<script src="../bootstrap-toc.js"></script>

<!-- 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" />

<!-- 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>

<!-- 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>

<!-- pkgdown -->
<link href="../pkgdown.css" rel="stylesheet">
<script src="../pkgdown.js"></script>




<meta property="og:title" content="spectral separability — spectral.separability" />
<meta property="og:description" content="Calculates spectral separability by class
Available statistics:
Bhattacharyya distance (Bhattacharyya 1943; Harold 2003) measures the similarity
of two discrete or continuous probability distributions.
Jeffries-Matusita (default) distance (Bruzzone et al., 2005; Swain et al., 1971)
is a scaled (0-2) version of Bhattacharyya. The J-M distance is asymptotic to 2,
where 2 suggest complete separability.

" />




<!-- 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 data-spy="scroll" data-target="#toc">
    <div class="container template-reference-topic">
      <header>
      <div class="navbar navbar-default navbar-fixed-top" role="navigation">
  <div class="container">
    <div class="navbar-header">
      <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false">
        <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
      <span class="navbar-brand">
        <a class="navbar-link" href="../index.html">spatialEco</a>
        <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">1.3-7</span>
      </span>
    </div>

    <div id="navbar" class="navbar-collapse collapse">
      <ul class="nav navbar-nav">
        <li>
  <a href="../index.html">
    <span class="fas fa-home fa-lg"></span>
     
  </a>
</li>
<li>
  <a href="../reference/index.html">Reference</a>
</li>
      </ul>
      <ul class="nav navbar-nav navbar-right">
        <li>
  <a href="https://github.com/jeffreyevans/spatialEco/">
    <span class="fab fa-github fa-lg"></span>
     
  </a>
</li>
      </ul>
      
    </div><!--/.nav-collapse -->
  </div><!--/.container -->
</div><!--/.navbar -->

      

      </header>

<div class="row">
  <div class="col-md-9 contents">
    <div class="page-header">
    <h1>spectral separability</h1>
    <small class="dont-index">Source: <a href='https://github.com/jeffreyevans/spatialEco/blob/master/R/spectral.separability.R'><code>R/spectral.separability.R</code></a></small>
    <div class="hidden name"><code>spectral.separability.Rd</code></div>
    </div>

    <div class="ref-description">
    <p>Calculates spectral separability by class</p>
<p>Available statistics:</p><ul>
<li><p>Bhattacharyya distance (Bhattacharyya 1943; Harold 2003) measures the similarity
of two discrete or continuous probability distributions.</p></li>
<li><p>Jeffries-Matusita (default) distance (Bruzzone et al., 2005; Swain et al., 1971)
is a scaled (0-2) version of Bhattacharyya. The J-M distance is asymptotic to 2,
where 2 suggest complete separability.</p></li>
</ul>

    </div>

    <pre class="usage"><span class='fu'>spectral.separability</span><span class='op'>(</span><span class='va'>x</span>, <span class='va'>y</span>, jeffries.matusita <span class='op'>=</span> <span class='cn'>TRUE</span><span class='op'>)</span></pre>

    <h2 class="hasAnchor" id="arguments"><a class="anchor" href="#arguments"></a>Arguments</h2>
    <table class="ref-arguments">
    <colgroup><col class="name" /><col class="desc" /></colgroup>
    <tr>
      <th>x</th>
      <td><p>data.frame, matrix or vector of spectral values must,
match classes defined in y</p></td>
    </tr>
    <tr>
      <th>y</th>
      <td><p>A vector or factor with grouping classes, must match
row wise values in x</p></td>
    </tr>
    <tr>
      <th>jeffries.matusita</th>
      <td><p>(TRUE/FALSE) Return J-M distance (default) else Bhattacharyya</p></td>
    </tr>
    </table>

    <h2 class="hasAnchor" id="value"><a class="anchor" href="#value"></a>Value</h2>

    <p>A matrix of class-wise Jeffries-Matusita or Bhattacharyya distance
separability values</p>
    <h2 class="hasAnchor" id="references"><a class="anchor" href="#references"></a>References</h2>

    <p>Bhattacharyya, A. (1943) On a measure of divergence between two statistical
populations defined by their probability distributions'. Bulletin of the
Calcutta Mathematical Society 35:99-109</p>
<p>Bruzzone, L., F. Roli, S.B. Serpico (1995) An extension to multiclass cases of
the Jefferys-Matusita distance. IEEE Transactions on Pattern Analysis and
Machine Intelligence 33:1318-1321</p>
<p>Kailath, T., (1967) The Divergence and Bhattacharyya measures in signal
selection. IEEE Transactions on Communication Theory 15:52-60</p>
    <h2 class="hasAnchor" id="author"><a class="anchor" href="#author"></a>Author</h2>

    <p>Jeffrey S. Evans  <a href='mailto:jeffrey_evans@tnc.org'>jeffrey_evans@tnc.org</a></p>

    <h2 class="hasAnchor" id="examples"><a class="anchor" href="#examples"></a>Examples</h2>
    <pre class="examples"><div class='input'><span class='co'>#' # Create example data </span>
<span class='kw'><a href='https://rdrr.io/r/base/library.html'>require</a></span><span class='op'>(</span><span class='va'><a href='http://www.stats.ox.ac.uk/pub/MASS4/'>MASS</a></span><span class='op'>)</span>                
</div><div class='output co'>#&gt; <span class='message'>Loading required package: MASS</span></div><div class='output co'>#&gt; <span class='message'></span>
#&gt; <span class='message'>Attaching package: 'MASS'</span></div><div class='output co'>#&gt; <span class='message'>The following object is masked from 'package:spatstat.geom':</span>
#&gt; <span class='message'></span>
#&gt; <span class='message'>    area</span></div><div class='output co'>#&gt; <span class='message'>The following objects are masked from 'package:raster':</span>
#&gt; <span class='message'></span>
#&gt; <span class='message'>    area, select</span></div><div class='input'><span class='va'>d</span> <span class='op'>&lt;-</span> <span class='fl'>6</span>                 <span class='co'># Number of bands</span>
<span class='va'>n.class</span> <span class='op'>&lt;-</span> <span class='fl'>5</span>           <span class='co'># Number of classes</span>
<span class='va'>n</span> <span class='op'>&lt;-</span> <span class='fu'><a href='https://rdrr.io/r/base/rep.html'>rep</a></span><span class='op'>(</span><span class='fl'>1000</span>, <span class='fl'>5</span><span class='op'>)</span>                
<span class='va'>mu</span> <span class='op'>&lt;-</span> <span class='fu'><a href='https://rdrr.io/r/base/Round.html'>round</a></span><span class='op'>(</span><span class='fu'><a href='https://rdrr.io/r/base/matrix.html'>matrix</a></span><span class='op'>(</span><span class='fu'><a href='https://rdrr.io/r/stats/Normal.html'>rnorm</a></span><span class='op'>(</span><span class='va'>d</span><span class='op'>*</span><span class='va'>n.class</span>, <span class='fl'>128</span>, <span class='fl'>1</span><span class='op'>)</span>, 
            ncol<span class='op'>=</span><span class='va'>n.class</span>, byrow<span class='op'>=</span><span class='cn'>TRUE</span><span class='op'>)</span>, <span class='fl'>0</span><span class='op'>)</span>

<span class='va'>x</span> <span class='op'>&lt;-</span> <span class='fu'><a href='https://rdrr.io/r/base/matrix.html'>matrix</a></span><span class='op'>(</span><span class='fu'><a href='https://rdrr.io/r/base/double.html'>double</a></span><span class='op'>(</span><span class='op'>)</span>, ncol<span class='op'>=</span><span class='va'>d</span>, nrow<span class='op'>=</span><span class='fl'>0</span><span class='op'>)</span>
  <span class='va'>classes</span> <span class='op'>&lt;-</span> <span class='fu'><a href='https://rdrr.io/r/base/integer.html'>integer</a></span><span class='op'>(</span><span class='op'>)</span>
    <span class='kw'>for</span> <span class='op'>(</span><span class='va'>i</span> <span class='kw'>in</span> <span class='fl'>1</span><span class='op'>:</span><span class='va'>n.class</span><span class='op'>)</span> <span class='op'>{</span>
      <span class='va'>f</span> <span class='op'>&lt;-</span> <span class='fu'><a href='https://rdrr.io/r/base/svd.html'>svd</a></span><span class='op'>(</span><span class='fu'><a href='https://rdrr.io/r/base/matrix.html'>matrix</a></span><span class='op'>(</span><span class='fu'><a href='https://rdrr.io/r/stats/Normal.html'>rnorm</a></span><span class='op'>(</span><span class='va'>d</span><span class='op'>^</span><span class='fl'>2</span><span class='op'>)</span>, ncol<span class='op'>=</span><span class='va'>d</span><span class='op'>)</span><span class='op'>)</span>
      <span class='va'>sigma</span> <span class='op'>&lt;-</span> <span class='fu'><a href='https://rdrr.io/pkg/raster/man/transpose.html'>t</a></span><span class='op'>(</span><span class='va'>f</span><span class='op'>$</span><span class='va'>v</span><span class='op'>)</span> <span class='op'>%*%</span> <span class='fu'><a href='https://rdrr.io/r/base/diag.html'>diag</a></span><span class='op'>(</span><span class='fu'><a href='https://rdrr.io/r/base/rep.html'>rep</a></span><span class='op'>(</span><span class='fl'>10</span>, <span class='va'>d</span><span class='op'>)</span><span class='op'>)</span> <span class='op'>%*%</span> <span class='va'>f</span><span class='op'>$</span><span class='va'>v</span>
      <span class='va'>x</span> <span class='op'>&lt;-</span> <span class='fu'><a href='https://rdrr.io/r/base/cbind.html'>rbind</a></span><span class='op'>(</span><span class='va'>x</span>, <span class='fu'><a href='https://rdrr.io/pkg/MASS/man/mvrnorm.html'>mvrnorm</a></span><span class='op'>(</span><span class='va'>n</span><span class='op'>[</span><span class='va'>i</span><span class='op'>]</span>, <span class='va'>mu</span><span class='op'>[</span>, <span class='va'>i</span><span class='op'>]</span>, <span class='va'>sigma</span><span class='op'>)</span><span class='op'>)</span>
      <span class='va'>classes</span> <span class='op'>&lt;-</span> <span class='fu'><a href='https://rdrr.io/r/base/c.html'>c</a></span><span class='op'>(</span><span class='va'>classes</span>, <span class='fu'><a href='https://rdrr.io/r/base/rep.html'>rep</a></span><span class='op'>(</span><span class='va'>i</span>, <span class='va'>n</span><span class='op'>[</span><span class='va'>i</span><span class='op'>]</span><span class='op'>)</span><span class='op'>)</span>
    <span class='op'>}</span>
<span class='fu'><a href='https://rdrr.io/r/base/colnames.html'>colnames</a></span><span class='op'>(</span><span class='va'>x</span><span class='op'>)</span> <span class='op'>&lt;-</span> <span class='fu'><a href='https://rdrr.io/r/base/paste.html'>paste0</a></span><span class='op'>(</span><span class='st'>"band"</span>, <span class='fl'>1</span><span class='op'>:</span><span class='fl'>6</span><span class='op'>)</span>
<span class='va'>classes</span> <span class='op'>&lt;-</span> <span class='fu'><a href='https://rdrr.io/r/base/factor.html'>factor</a></span><span class='op'>(</span><span class='va'>classes</span>, labels<span class='op'>=</span><span class='fu'><a href='https://rdrr.io/r/base/c.html'>c</a></span><span class='op'>(</span><span class='st'>"water"</span>, <span class='st'>"forest"</span>,
                  <span class='st'>"shrub"</span>, <span class='st'>"urban"</span>, <span class='st'>"ag"</span><span class='op'>)</span><span class='op'>)</span>

<span class='co'># Separability for multi-band (multivariate) spectra </span>
<span class='fu'>spectral.separability</span><span class='op'>(</span><span class='va'>x</span>, <span class='va'>classes</span><span class='op'>)</span>
</div><div class='output co'>#&gt; <span class='message'>Calculating distances for 5 classes and 6 spectra</span></div><div class='output co'>#&gt;            water    forest     shrub     urban        ag
#&gt; water  0.0000000 0.5222125 0.6930201 0.5661507 0.5772556
#&gt; forest 0.5222125 0.0000000 0.5784187 0.4408988 0.3518784
#&gt; shrub  0.6930201 0.5784187 0.0000000 0.4689764 0.4626040
#&gt; urban  0.5661507 0.4408988 0.4689764 0.0000000 0.5425867
#&gt; ag     0.5772556 0.3518784 0.4626040 0.5425867 0.0000000</div><div class='input'>
<span class='co'># Separability for single-band (univariate) spectra </span>
<span class='fu'>spectral.separability</span><span class='op'>(</span><span class='va'>x</span><span class='op'>[</span>,<span class='fl'>1</span><span class='op'>]</span>, <span class='va'>classes</span><span class='op'>)</span>
</div><div class='output co'>#&gt; <span class='message'>Calculating distances for 5 classes and 1 spectra</span></div><div class='output co'>#&gt;            water      forest     shrub      urban          ag
#&gt; water  0.0000000 0.323189891 0.4735819 0.31380337 0.331823652
#&gt; forest 0.3231899 0.000000000 0.1588724 0.01759146 0.009642274
#&gt; shrub  0.4735819 0.158872383 0.0000000 0.16449753 0.152035332
#&gt; urban  0.3138034 0.017591463 0.1644975 0.00000000 0.026335384
#&gt; ag     0.3318237 0.009642274 0.1520353 0.02633538 0.000000000</div><div class='input'>
</div></pre>
  </div>
  <div class="col-md-3 hidden-xs hidden-sm" id="pkgdown-sidebar">
    <nav id="toc" data-toggle="toc" class="sticky-top">
      <h2 data-toc-skip>Contents</h2>
    </nav>
  </div>
</div>


      <footer>
      <div class="copyright">
  <p>Developed by Jeffrey S. Evans.</p>
</div>

<div class="pkgdown">
  <p>Site built with <a href="https://pkgdown.r-lib.org/">pkgdown</a> 1.6.1.</p>
</div>

      </footer>
   </div>

  


  </body>
</html>


