Permalink
Browse files

Update docs for code style

  • Loading branch information...
1 parent 34a6e14 commit b8fcc3ac6e1ee9ffae439318cd21d024b6d53413 @tmcw tmcw committed Feb 7, 2013
Showing with 7 additions and 6 deletions.
  1. +7 −6 docs/simple_statistics.html
@@ -215,14 +215,15 @@
<span class="p">}</span></pre></div> </td> </tr> <tr id="section-65"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-65">&#182;</a> </div> <p>the covariance is weighted by the length of the datasets.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">return</span> <span class="nx">sum</span> <span class="o">/</span> <span class="p">(</span><span class="nx">x</span><span class="p">.</span><span class="nx">length</span> <span class="o">-</span> <span class="mi">1</span><span class="p">);</span>
<span class="p">};</span></pre></div> </td> </tr> <tr id="section-66"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-66">&#182;</a> </div> <h1><a href="http://en.wikipedia.org/wiki/Correlation_and_dependence">correlation</a></h1>
-<p>Gets a measure of how correlated two datasets are, between -1 and 1</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">ss</span><span class="p">.</span><span class="nx">sample_correlation</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span><span class="nx">x</span><span class="p">,</span> <span class="nx">y</span><span class="p">){</span>
- <span class="kd">var</span> <span class="nx">cov</span> <span class="o">=</span> <span class="nx">ss</span><span class="p">.</span><span class="nx">sample_covariance</span><span class="p">(</span><span class="nx">x</span><span class="p">,</span> <span class="nx">y</span><span class="p">);</span>
- <span class="kd">var</span> <span class="nx">xstd</span> <span class="o">=</span> <span class="nx">ss</span><span class="p">.</span><span class="nx">sample_standard_deviation</span><span class="p">(</span><span class="nx">x</span><span class="p">);</span>
- <span class="kd">var</span> <span class="nx">ystd</span> <span class="o">=</span> <span class="nx">ss</span><span class="p">.</span><span class="nx">sample_standard_deviation</span><span class="p">(</span><span class="nx">y</span><span class="p">);</span>
+<p>Gets a measure of how correlated two datasets are, between -1 and 1</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">ss</span><span class="p">.</span><span class="nx">sample_correlation</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span><span class="nx">x</span><span class="p">,</span> <span class="nx">y</span><span class="p">)</span> <span class="p">{</span>
+ <span class="kd">var</span> <span class="nx">cov</span> <span class="o">=</span> <span class="nx">ss</span><span class="p">.</span><span class="nx">sample_covariance</span><span class="p">(</span><span class="nx">x</span><span class="p">,</span> <span class="nx">y</span><span class="p">),</span>
+ <span class="nx">xstd</span> <span class="o">=</span> <span class="nx">ss</span><span class="p">.</span><span class="nx">sample_standard_deviation</span><span class="p">(</span><span class="nx">x</span><span class="p">),</span>
+ <span class="nx">ystd</span> <span class="o">=</span> <span class="nx">ss</span><span class="p">.</span><span class="nx">sample_standard_deviation</span><span class="p">(</span><span class="nx">y</span><span class="p">);</span>
- <span class="k">if</span> <span class="p">(</span><span class="nx">cov</span> <span class="o">===</span> <span class="kc">null</span> <span class="o">||</span> <span class="nx">xstd</span> <span class="o">===</span> <span class="kc">null</span> <span class="o">||</span> <span class="nx">ystd</span> <span class="o">===</span> <span class="kc">null</span><span class="p">){</span>
- <span class="k">return</span> <span class="kc">null</span><span class="p">;</span>
+ <span class="k">if</span> <span class="p">(</span><span class="nx">cov</span> <span class="o">===</span> <span class="kc">null</span> <span class="o">||</span> <span class="nx">xstd</span> <span class="o">===</span> <span class="kc">null</span> <span class="o">||</span> <span class="nx">ystd</span> <span class="o">===</span> <span class="kc">null</span><span class="p">)</span> <span class="p">{</span>
+ <span class="k">return</span> <span class="kc">null</span><span class="p">;</span>
<span class="p">}</span>
+
<span class="k">return</span> <span class="nx">cov</span> <span class="o">/</span> <span class="nx">xstd</span> <span class="o">/</span> <span class="nx">ystd</span><span class="p">;</span>
<span class="p">};</span></pre></div> </td> </tr> <tr id="section-67"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-67">&#182;</a> </div> <h1><a href="http://en.wikipedia.org/wiki/Median">median</a></h1> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">ss</span><span class="p">.</span><span class="nx">median</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span><span class="nx">x</span><span class="p">)</span> <span class="p">{</span></pre></div> </td> </tr> <tr id="section-68"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-68">&#182;</a> </div> <p>The median of an empty list is null</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">if</span> <span class="p">(</span><span class="nx">x</span><span class="p">.</span><span class="nx">length</span> <span class="o">===</span> <span class="mi">0</span><span class="p">)</span> <span class="k">return</span> <span class="kc">null</span><span class="p">;</span></pre></div> </td> </tr> <tr id="section-69"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-69">&#182;</a> </div> <p>Sorting the array makes it easy to find the center, but
use <code>.slice()</code> to ensure the original array <code>x</code> is not modified</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">var</span> <span class="nx">sorted</span> <span class="o">=</span> <span class="nx">x</span><span class="p">.</span><span class="nx">slice</span><span class="p">().</span><span class="nx">sort</span><span class="p">(</span><span class="kd">function</span> <span class="p">(</span><span class="nx">a</span><span class="p">,</span> <span class="nx">b</span><span class="p">)</span> <span class="p">{</span> <span class="k">return</span> <span class="nx">a</span> <span class="o">-</span> <span class="nx">b</span><span class="p">;</span> <span class="p">});</span></pre></div> </td> </tr> <tr id="section-70"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-70">&#182;</a> </div> <p>If the length of the list is odd, it's the central number</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">if</span> <span class="p">(</span><span class="nx">sorted</span><span class="p">.</span><span class="nx">length</span> <span class="o">%</span> <span class="mi">2</span> <span class="o">===</span> <span class="mi">1</span><span class="p">)</span> <span class="p">{</span>

0 comments on commit b8fcc3a

Please sign in to comment.