<!-- 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>Winsorize transformation — winsorize • 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="Winsorize transformation — winsorize" />
<meta property="og:description" content="Removes extreme outliers using a winsorization transformation
Winsorization is the transformation of a distribution by limiting extreme values 
to reduce the effect of spurious outliers. This is done by shrinking outlying 
observations to the border of the main part of the distribution." />




<!-- 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>Winsorize transformation</h1>
    <small class="dont-index">Source: <a href='https://github.com/jeffreyevans/spatialEco/blob/master/R/winsorize.R'><code>R/winsorize.R</code></a></small>
    <div class="hidden name"><code>winsorize.Rd</code></div>
    </div>

    <div class="ref-description">
    <p>Removes extreme outliers using a winsorization transformation</p>
<p>Winsorization is the transformation of a distribution by limiting extreme values 
to reduce the effect of spurious outliers. This is done by shrinking outlying 
observations to the border of the main part of the distribution.</p>
    </div>

    <pre class="usage"><span class='fu'>winsorize</span><span class='op'>(</span>
  <span class='va'>x</span>,
  min.value <span class='op'>=</span> <span class='cn'>NULL</span>,
  max.value <span class='op'>=</span> <span class='cn'>NULL</span>,
  p <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='fl'>0.05</span>, <span class='fl'>0.95</span><span class='op'>)</span>,
  na.rm <span class='op'>=</span> <span class='cn'>FALSE</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>A numeric vector</p></td>
    </tr>
    <tr>
      <th>min.value</th>
      <td><p>A fixed lower bounds, all values lower than this will be 
replaced by this value. The default is set to the 5th-quantile 
of x.</p></td>
    </tr>
    <tr>
      <th>max.value</th>
      <td><p>A fixed upper bounds, all values higher than this will be replaced 
by this value. The default is set to the 95th-quantile of x.</p></td>
    </tr>
    <tr>
      <th>p</th>
      <td><p>A numeric vector of 2 representing the probabilities used in the 
quantile function.</p></td>
    </tr>
    <tr>
      <th>na.rm</th>
      <td><p>(FALSE/TRUE) should NAs be omitted?</p></td>
    </tr>
    </table>

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

    <p>A transformed vector the same length as x, unless na.rm is TRUE, then x is length 
minus number of NA's</p>
    <h2 class="hasAnchor" id="references"><a class="anchor" href="#references"></a>References</h2>

    <p>Dixon, W.J. (1960) Simplified Estimation from Censored Normal Samples. Annals of Mathematical 
  Statistics. 31(2):385-391</p>
    <h2 class="hasAnchor" id="author"><a class="anchor" href="#author"></a>Author</h2>

    <p>Jeffrey S. Evans  &lt;jeffrey_evans@tnc.org&gt;</p>

    <h2 class="hasAnchor" id="examples"><a class="anchor" href="#examples"></a>Examples</h2>
    <pre class="examples"><div class='input'><span class='fu'><a href='https://rdrr.io/r/base/Random.html'>set.seed</a></span><span class='op'>(</span><span class='fl'>1234</span><span class='op'>)</span>     
<span class='va'>x</span> <span class='op'>&lt;-</span> <span class='fu'><a href='https://rdrr.io/r/stats/Normal.html'>rnorm</a></span><span class='op'>(</span><span class='fl'>100</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='op'>&lt;-</span> <span class='va'>x</span><span class='op'>[</span><span class='fl'>1</span><span class='op'>]</span> <span class='op'>*</span> <span class='fl'>10</span>  
<span class='fu'>winsorize</span><span class='op'>(</span><span class='va'>x</span><span class='op'>)</span>       
</div><div class='output co'>#&gt;   [1] -1.457249338  0.277429242  1.084441177 -1.457249338  0.429124689
#&gt;   [6]  0.506055892 -0.574739960 -0.546631856 -0.564451999 -0.890037829
#&gt;  [11] -0.477192700 -0.998386445 -0.776253895  0.064458817  0.959494059
#&gt;  [16] -0.110285494 -0.511009506 -0.911195417 -0.837171680  1.709520029
#&gt;  [21]  0.134088220 -0.490685897 -0.440547872  0.459589441 -0.693720247
#&gt;  [26] -1.448204910  0.574755721 -1.023655723 -0.015138300 -0.935948601
#&gt;  [31]  1.102297546 -0.475593079 -0.709440038 -0.501258061 -1.457249338
#&gt;  [36] -1.167619262 -1.457249338 -1.340993192 -0.294293859 -0.465897540
#&gt;  [41]  1.449496265 -1.068642724 -0.855364634 -0.280623002 -0.994340076
#&gt;  [46] -0.968514318 -1.107318193 -1.251985886 -0.523828119 -0.496849957
#&gt;  [51] -1.457249338 -0.582075925 -1.108889624 -1.014962009 -0.162309524
#&gt;  [56]  0.563055819  1.647817473 -0.773353424  1.605909629 -1.157808548
#&gt;  [61]  0.656588464  1.709520029 -0.034760390 -0.669633580 -0.007604756
#&gt;  [66]  1.709520029 -1.138607737  1.367827179  1.329564791  0.336472797
#&gt;  [71]  0.006892838 -0.455468738 -0.366523933  0.648286568  1.709520029
#&gt;  [76] -0.153398412 -1.390700947 -0.723581777  0.258261762 -0.317059115
#&gt;  [81] -0.177789958 -0.169994077 -1.372301886 -0.173787170  0.850232257
#&gt;  [86]  0.697608712  0.549997351 -0.402731975 -0.191593770 -1.194527880
#&gt;  [91] -0.053158819  0.255196001  1.705964007  1.001513252 -0.495583443
#&gt;  [96]  0.355550297 -1.134608044  0.878203627  0.972916753  1.709520029</div><div class='input'>
<span class='fu'><a href='https://rdrr.io/pkg/raster/man/plot.html'>plot</a></span><span class='op'>(</span><span class='va'>x</span>, type<span class='op'>=</span><span class='st'>"l"</span>, main<span class='op'>=</span><span class='st'>"Winsorization transformation"</span><span class='op'>)</span>
</div><div class='input'>  <span class='fu'><a href='https://rdrr.io/r/graphics/lines.html'>lines</a></span><span class='op'>(</span><span class='fu'>winsorize</span><span class='op'>(</span><span class='va'>x</span><span class='op'>)</span>, col<span class='op'>=</span><span class='st'>"red"</span>, lwd<span class='op'>=</span><span class='fl'>2</span><span class='op'>)</span>
</div><div class='input'>    <span class='fu'><a href='https://rdrr.io/r/graphics/legend.html'>legend</a></span><span class='op'>(</span><span class='st'>"bottomright"</span>, legend<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'>"Original distribution"</span>,<span class='st'>"With outliers removed"</span><span class='op'>)</span>,
        lty<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='fl'>1</span>,<span class='fl'>1</span><span class='op'>)</span>, col<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'>"black"</span>,<span class='st'>"red"</span><span class='op'>)</span><span class='op'>)</span>
</div><div class='img'><img src='winsorize-1.png' alt='' width='700' height='433' /></div><div class='input'>
<span class='co'># Behavior with NA value(s)</span>
<span class='va'>x</span><span class='op'>[</span><span class='fl'>4</span><span class='op'>]</span> <span class='op'>&lt;-</span> <span class='cn'>NA</span>
<span class='fu'>winsorize</span><span class='op'>(</span><span class='va'>x</span><span class='op'>)</span>             <span class='co'># returns x with original NA's </span>
</div><div class='output co'>#&gt;  [1] -1.396451343  0.277429242  1.084441177           NA  0.506055892
#&gt;  [6] -0.574739960 -0.546631856 -0.564451999 -0.890037829 -0.477192700
#&gt; [11] -0.998386445 -0.776253895  0.064458817  0.959494059 -0.110285494
#&gt; [16] -0.511009506 -0.911195417 -0.837171680  1.713076051  0.134088220
#&gt; [21] -0.490685897 -0.440547872  0.459589441 -0.693720247 -1.396451343
#&gt; [26]  0.574755721 -1.023655723 -0.015138300 -0.935948601  1.102297546
#&gt; [31] -0.475593079 -0.709440038 -0.501258061 -1.396451343 -1.167619262
#&gt; [36] -1.396451343 -1.340993192 -0.294293859 -0.465897540  1.449496265
#&gt; [41] -1.068642724 -0.855364634 -0.280623002 -0.994340076 -0.968514318
#&gt; [46] -1.107318193 -1.251985886 -0.523828119 -0.496849957 -1.396451343
#&gt; [51] -0.582075925 -1.108889624 -1.014962009 -0.162309524  0.563055819
#&gt; [56]  1.647817473 -0.773353424  1.605909629 -1.157808548  0.656588464
#&gt; [61]  1.713076051 -0.034760390 -0.669633580 -0.007604756  1.713076051
#&gt; [66] -1.138607737  1.367827179  1.329564791  0.336472797  0.006892838
#&gt; [71] -0.455468738 -0.366523933  0.648286568  1.713076051 -0.153398412
#&gt; [76] -1.390700947 -0.723581777  0.258261762 -0.317059115 -0.177789958
#&gt; [81] -0.169994077 -1.372301886 -0.173787170  0.850232257  0.697608712
#&gt; [86]  0.549997351 -0.402731975 -0.191593770 -1.194527880 -0.053158819
#&gt; [91]  0.255196001  1.705964007  1.001513252 -0.495583443  0.355550297
#&gt; [96] -1.134608044  0.878203627  0.972916753  1.713076051</div><div class='input'><span class='fu'>winsorize</span><span class='op'>(</span><span class='va'>x</span>, na.rm<span class='op'>=</span><span class='cn'>TRUE</span><span class='op'>)</span> <span class='co'># removes NA's </span>
</div><div class='output co'>#&gt;  [1] -1.396451343  0.277429242  1.084441177  0.429124689  0.506055892
#&gt;  [6] -0.574739960 -0.546631856 -0.564451999 -0.890037829 -0.477192700
#&gt; [11] -0.998386445 -0.776253895  0.064458817  0.959494059 -0.110285494
#&gt; [16] -0.511009506 -0.911195417 -0.837171680  1.713076051  0.134088220
#&gt; [21] -0.490685897 -0.440547872  0.459589441 -0.693720247 -1.396451343
#&gt; [26]  0.574755721 -1.023655723 -0.015138300 -0.935948601  1.102297546
#&gt; [31] -0.475593079 -0.709440038 -0.501258061 -1.396451343 -1.167619262
#&gt; [36] -1.396451343 -1.340993192 -0.294293859 -0.465897540  1.449496265
#&gt; [41] -1.068642724 -0.855364634 -0.280623002 -0.994340076 -0.968514318
#&gt; [46] -1.107318193 -1.251985886 -0.523828119 -0.496849957 -1.396451343
#&gt; [51] -0.582075925 -1.108889624 -1.014962009 -0.162309524  0.563055819
#&gt; [56]  1.647817473 -0.773353424  1.605909629 -1.157808548  0.656588464
#&gt; [61]  1.713076051 -0.034760390 -0.669633580 -0.007604756  1.713076051
#&gt; [66] -1.138607737  1.367827179  1.329564791  0.336472797  0.006892838
#&gt; [71] -0.455468738 -0.366523933  0.648286568  1.713076051 -0.153398412
#&gt; [76] -1.390700947 -0.723581777  0.258261762 -0.317059115 -0.177789958
#&gt; [81] -0.169994077 -1.372301886 -0.173787170  0.850232257  0.697608712
#&gt; [86]  0.549997351 -0.402731975 -0.191593770 -1.194527880 -0.053158819
#&gt; [91]  0.255196001  1.705964007  1.001513252 -0.495583443  0.355550297
#&gt; [96] -1.134608044  0.878203627  0.972916753  1.713076051</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>


