<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0">
    <channel>
        <title>Statistics - Tag - In a past life…</title>
        <link>https://archive.jtimothyking.com/tags/statistics/</link>
        <description>Statistics - Tag - In a past life…</description>
        <generator>Hugo -- gohugo.io</generator><language>en-us</language><lastBuildDate>Tue, 08 Oct 2013 11:00:34 &#43;0000</lastBuildDate><atom:link href="https://archive.jtimothyking.com/tags/statistics/" rel="self" type="application/rss+xml" /><item>
    <title>More Simple Stats with Perl 6</title>
    <link>https://archive.jtimothyking.com/2013/10/08/more-simple-stats-with-perl-6/</link>
    <pubDate>Tue, 08 Oct 2013 11:00:34 &#43;0000</pubDate>
    <author>J. Timothy King</author>
    <guid>https://archive.jtimothyking.com/2013/10/08/more-simple-stats-with-perl-6/</guid>
    <description><![CDATA[<figure class="alignright size-thumbnail"><a class="lightgallery" href="/2013/10/08/more-simple-stats-with-perl-6/SEO-icon.png" title="This is what happens when I try to pick out images while I&amp;#039;m too tired to think straight." data-thumbnail="/2013/10/08/more-simple-stats-with-perl-6/SEO-icon.png">
        
    </a></figure>
<p><a href="http://sd.jtimothyking.com/2013/09/24/some-simple-stats-with-perl-6/" title="Some Simple Stats with Perl 6">Last time,</a> a time long, long ago, in a universe far, far away, I left you with the following Perl 6 code (or something like it). This code reads in a series of book heights and displays the number of books of each height (in order from shortest to tallest).</p>
<pre><span style="color: DarkRed;">my</span> <span style="color: DarkOrange; font-weight: bold;">%num_of_height</span>;
<span style="color: DarkRed;">for lines() {</span>
    <span style="color: DarkRed;">if</span> <span style="color: DarkMagenta;">m/^ \s* (\d+[\.\d+]?) [\s* x \s* (\d+)]? \s* $/</span><span style="color: DarkRed;"> {</span>
        <span style="color: DarkRed;">my</span> <span style="color: DarkBlue; font-weight: bold;">$height</span> <span style="color: DimGray;">=</span> <span style="color: DarkRed;">+</span><span style="color: DarkBlue; font-weight: bold;">$</span><span style="color: DarkGreen;">0</span><span style="color: DarkRed;">;</span>
        <span style="color: DarkRed;">my</span> <span style="color: DarkBlue; font-weight: bold;">$num</span> <span style="color: DimGray;">=</span> <span style="color: DarkRed;">+(</span><span style="color: DarkBlue; font-weight: bold;">$</span><span style="color: DarkGreen;">1</span> <span style="color: DimGray;">||</span> <span style="color: DarkOrange;">1</span><span style="color: DarkRed;">);</span>
        <span style="color: DarkOrange; font-weight: bold;">%num_of_height</span><span style="color: DarkRed;">{</span><span style="color: DarkBlue; font-weight: bold;">$height</span><span style="color: DarkRed;">}</span> <span style="color: DimGray;">+</span><span style="color: DarkRed;">=</span> <span style="color: DarkBlue; font-weight: bold;">$num</span><span style="color: DarkRed;">;</span>
    <span style="color: DarkRed;">} elsif !</span> <span style="color: DarkMagenta;">m/^\s*$/</span><span style="color: DarkRed;"> {</span>
        <span style="color: DarkRed;">note</span> <span style="color: DarkMagenta;">&quot;Invalid line ignored:</span> <span style="color: DarkBlue; font-weight: bold;">$_</span><span style="color: DarkMagenta;">&quot;</span><span style="color: DarkRed;">;</span>
    <span style="color: DarkRed;">}</span>
<span style="color: DarkRed;">}</span>

<span style="color: DarkGreen; font-weight: bold;">#| unique book heights seen, in order from shortest to tallest</span><span style="color: DarkRed;"></span>
<span style="color: DarkRed;">my</span> <span style="color: Brown; font-weight: bold;">@heights</span> <span style="color: DimGray;">=</span> sort { <span style="color: DarkBlue; font-weight: bold;">$</span><span style="color: DarkGreen;">^</span><span style="color: DarkBlue; font-weight: bold;">a</span> <span style="color: DimGray;">&lt;=&gt;</span> <span style="color: DarkBlue; font-weight: bold;">$</span><span style="color: DarkGreen;">^</span><span style="color: DarkBlue; font-weight: bold;">b</span> }<span style="color: DimGray;">,</span> keys <span style="color: DarkOrange; font-weight: bold;">%num_of_height</span>;

say <span style="color: DarkMagenta;">&quot;Histogram data:&quot;</span>;
<span style="color: DarkRed;">for</span> <span style="color: Brown; font-weight: bold;">@heights</span><span style="color: DarkRed;"> -&gt;</span> <span style="color: DarkBlue; font-weight: bold;">$height</span><span style="color: DarkRed;"> {</span>
    <span style="color: DarkRed;">my</span> <span style="color: DarkBlue; font-weight: bold;">$num</span> <span style="color: DimGray;">=</span> <span style="color: DarkOrange; font-weight: bold;">%num_of_height</span><span style="color: DarkRed;">{</span><span style="color: DarkBlue; font-weight: bold;">$height</span><span style="color: DarkRed;">};</span>
    <span style="color: DarkRed;">say</span> <span style="color: DarkMagenta;">&quot;</span><span style="color: DarkBlue; font-weight: bold;">$height</span><span style="color: DarkMagenta;"> x</span> <span style="color: DarkBlue; font-weight: bold;">$num</span><span style="color: DarkMagenta;">&quot;</span><span style="color: DarkRed;">;</span>
<span style="color: DarkRed;">}</span></pre>
<p>As you may recall, this little bit of somewhat less-than-useful P6 script was inspired by a homework assignment in my daughter&rsquo;s high-school statistics course. While she manually counted up the heights of the books we measured, in order to draw a histogram of the data, I wrote a Perl script to do the same counting.</p>
<p>Since then, for kicks, I&rsquo;ve also hacked together about 50 lines of code to display an actual histogram of these data, with horizontal bars of <code>*****</code>. I&rsquo;m not going to go into that code here, because I did not write it at the time, but if you want, you can <a href="https://github.com/JTimothyKing/sample-code/blob/master/book-heights/book-heights.pl6">check it out on Github</a>.</p>
<p>However, I did discover how succinctly Perl 6 could answer the other questions from the assignment.</p>]]></description>
</item>
<item>
    <title>Some Simple Stats with Perl 6</title>
    <link>https://archive.jtimothyking.com/2013/09/24/some-simple-stats-with-perl-6/</link>
    <pubDate>Tue, 24 Sep 2013 17:12:36 &#43;0000</pubDate>
    <author>J. Timothy King</author>
    <guid>https://archive.jtimothyking.com/2013/09/24/some-simple-stats-with-perl-6/</guid>
    <description><![CDATA[<figure class="alignright size-medium"><a class="lightgallery" href="/2013/09/24/some-simple-stats-with-perl-6/Bingo-numbers-Leo-Reynolds.jpg" title="Bingo numbers; ©2010 Leo Reynolds CC BY-NC-SA 2.0" data-thumbnail="/2013/09/24/some-simple-stats-with-perl-6/Bingo-numbers-Leo-Reynolds.jpg">
        
    </a></figure>
<p>When my daughter told me she was taking statistics, I wondered how she could do that without knowing any calculus. Then on second thought, I guess there is a certain amount you can do with statistics, even without knowing any calculus.</p>
<p>Ah, yes. And last night&rsquo;s homework assignment drilled that home. She asked me to help her. First, she needed to find a quantitative data set she could use to construct a histogram. Looking around the living room, I suggested, &ldquo;What about the heights of the books on my book shelves? You could measure the spines and write them down in a data table.&rdquo;</p>
<p>Now, I currently have nine full shelves of books in my living room, everything from Dave Barry and Dilbert to <em>Peopleware</em> to marketing and memoirs, theology and psychology, short stories and the theory of writing, to Holly Lisle, Douglas Adams, Robert Heinlein, and <em>The Sisterhood of the Traveling Pants</em>. (And I am not making this up.) And those are just the books that are actually on shelves, not the books that are still in boxes.</p>
<p>I think she was a little overwhelmed by the idea.</p>
<p>&ldquo;You don&rsquo;t have to include all the books, just one or two shelves worth. Maybe that one over there, half full of mass-market paperbacks all the same size.&rdquo; <em>Easy to measure, easy to count.</em></p>
<p>So we chose that shelf and the shelf just under it, a nice cross-section of fiction in mass-market, trade paperback, and hardcover. And then while she was manually collating the data, inspiration struck me. <em>Why don&rsquo;t I write a quick Perl 6 script to check her results. It&rsquo;ll give me something to write about; plus I&rsquo;ll see whether Perl 6 is really useful for anything, especially minor scripts.</em></p>
<p>And as it turns out, it might be.</p>]]></description>
</item>
</channel>
</rss>
