<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"
    xmlns:dc="http://purl.org/dc/elements/1.1/">
    <channel>
        <title>the refsmmat report - All posts</title>
        <link>https://www.refsmmat.com</link>
        <description><![CDATA[a blog from Alex Reinhart]]></description>
        <atom:link href="https://www.refsmmat.com/rss.xml" rel="self"
                   type="application/rss+xml" />
        <lastBuildDate>Sat, 14 Oct 2023 00:00:00 UT</lastBuildDate>
        <item>
    <title>Further adventures with ICP accelerometers</title>
    <link>https://www.refsmmat.com/posts/2023-10-21-further-accelerometer-adventures.html</link>
    <description><![CDATA[<p>In <a href="/posts/2022-02-12-accelerometers-fun-profit.html">a previous edition</a>, we discussed industrial accelerometers: sensitive instruments for measuring vibration inside structures, but also fun ways to listen inside watches, cameras, and watermelons. Unfortunately accelerometers are designed to connect to laboratory data acquisition systems that cost more than a hobbyist is likely to pay, so to use them, we need some kind of adapter to connect to ordinary audio recorders.</p>
<p>My previous project was a simple battery-powered adapter. It provides the 4 mA current source needed by ICP or IEPE accelerometers, at up to 24 V, from a single 9 V battery. A BNC connection supplies the accelerometer with power and receives its signal, and a 1/4&quot; TS jack can be connected to an ordinary field recorder.</p>
<p>But as I tried using my accelerometers in the field, I found the setup too clumsy. A quick recording requires connecting the accelerometer to the adapter, connecting a short audio cable to the jack, connecting the other end to the recorder, and turning on the recorder. And besides the recorder’s battery, I have to worry about the 9 V battery, which is only accessible by unscrewing the adapter’s front panel entirely.</p>
<p>Most recorders can already provide power to microphones over XLR cables. Can we steal that power to supply a microphone, cutting out one battery and making a simpler, easier adapter?</p>
<section id="xlr-phantom-power-and-icp" class="level2">
<h2>XLR, phantom power, and ICP</h2>
<p>Microphones for recording voice and music almost universally use 3-pin XLR connectors. One pin grounds the microphone; the other two are for a balanced signal. Their impedances to ground are <em>balanced</em>, so any electrical noise (from nearby electronics, cell phones, etc.) generates a nearly identical voltage on both signal lines. But the microphone outputs its signal as the <em>difference</em> between the two pins’ voltages, so noise subtracts right out.<a href="#fn1" class="footnote-ref" id="fnref1"><sup>1</sup></a></p>
<p>It is a clever design, and it allows power to be supplied to microphones with active circuitry. In the P48 phantom power system, the recorder or mixer applies 48 V to both signal pins through 6.81 kΩ resistors. Again, the microphone signal is the difference between the pins, so applying this voltage is fine; the microphone can tap current off with similar matched resistors and power whatever preamplifier it needs. Under the specification, P48 devices should be able to supply up to 10 mA of current this way.</p>
<p>We need a way to use this current for ICP devices. ICP (Integrated Circuit Piezoelectric), IEPE (Integrated Electronics Piezoelectric), CCLD (Constant Current Line Drive), DeltaTron, and IsoTron are all brand names for a very simple power system that only requires two connectors, not three. The recorder is connected to the sensor with a simple coaxial cable: just one conductor and the shield. The recorder is a current source, not a voltage source, set to roughly 4 mA and capable of supplying at least 18 V (up to 30 V at most). The sensor consumes this current. With no signal, the cable typically carries 4 mA at about 12 V; when the sensor outputs a signal, the voltage fluctuates proportionally, with the current remaining constant.</p>
<p>For those of you who have DIYed microphones and are wondering how they can be powered off a current source, check out <a href="https://sound-au.com/project134.htm">ESP’s Project 134 figure 4</a> for an example—it is surprisingly simple. But for the rest of us, we just need to know: How do we turn P48 phantom power into ICP and return the signal back to the XLR connection?</p>
</section>
<section id="the-adapter-schematic" class="level2">
<h2>The adapter schematic</h2>
<p>Our adapter will rely on a current-regulating diode, a cheap device that supplies a constant current almost regardless of the input voltage. I’m using the Semitec E-352, which supplies 3.5 mA. I’ll use one pin of the P48 power to supply the current, while the other returns the signal. Here’s the plan:</p>
<figure>
<img src="/images/xlr-icp-adapter.svg" alt="On left, the XLR connection to the recorder; on right, the BNC connector leading to the accelerometer." style="width:75.0%" /><figcaption>On left, the XLR connection to the recorder; on right, the BNC connector leading to the accelerometer.</figcaption>
</figure>
<p>We draw 48V from pin 3. D1 is the E-352, supplying a constant 3.5 mA to the BNC connector. The varying voltage on the BNC center pin is AC coupled to pin 2 of the XLR connector through C1. Pin 3 is kept stable by C2 acting as a low-pass filter. (Thanks to kennjava and Richard Lee on <a href="https://groups.io/g/MicBuilders">MicBuilders</a> for pointing out the need for C2.) The capacitors must be rated to at least 50 V.</p>
<p>R1 and D2 are for safety. If the phantom power were turned on with no device connected via BNC, C1 could charge to 48 V; D2, a 30V Zener, ensures it can only charge to about 30 V, the maximum rating of most ICP devices. R1 discharges C1 and C2 after power is disconnected.</p>
<p>Those of you who have worked with XLR cables or DIY microphones will notice that this circuit is not balanced: pins 2 and 3 do not have identical impedance to ground. In principle, this makes the XLR output more susceptible to noise. But as we’ll see below, it will be plugged directly into the recorder with no cable. The XLR contacts will be shielded by the metal enclosure, and there’s very little opportunity for interference.</p>
</section>
<section id="building-a-real-device" class="level2">
<h2>Building a real device</h2>
<p>Next, I needed a convenient enclosure to fit the electronics. I discovered Neutrik’s <a href="https://www.neutrik.com/en/product/na-housing">NA-Housing</a>, a simple extruded aluminum enclosure that accepts their D Shape connectors, including the <a href="https://www.neutrik.com/en/product/nm3md-b">NM3MD-B</a> male XLR connector and the <a href="https://www.neutrik.com/en/product/nbb75dsgb">NBB75DSGB</a> BNC connector.<a href="#fn2" class="footnote-ref" id="fnref2"><sup>2</sup></a> The XLR connector can be plugged right into a recorder without a cable, making this a convenient recorder-mounted adapter.</p>
<p>For the wiring, I decided to go ahead and make a PCB. I’ve never made one before, and this is a simple enough starting point. The NA-Housing accepts 28mm wide PCBs in its slots, so I made a 28 by 35mm PCB in KiCad. No, my layout is certainly not optimal, but it almost certainly does not matter here.</p>
<figure>
<img src="/images/xlr-icp-adapter-pcb.svg" alt="The refsmmat XLR to ICP adapter PCB layout. The orange region is a ground plane on the back side of the PCB." style="width:50.0%" /><figcaption>The refsmmat XLR to ICP adapter PCB layout. The orange region is a ground plane on the back side of the PCB.</figcaption>
</figure>
<p>$7.60 to <a href="https://oshpark.com/">OSH Park</a> later and I had three beautiful PCBs. Then it was simply assembly. Height of the parts is critical to fit inside the NA-Housing; fortunately, Nichicon UFG1J220MPM electrolytic capacitors fit as long as they’re not near the edges of the board.</p>
<p>And here are the results:</p>
<figure>
<img src="/images/xlr-icp-guts.jpeg" alt="The guts of the adapter, ready to be sealed up inside its case." style="width:75.0%" /><figcaption>The guts of the adapter, ready to be sealed up inside its case.</figcaption>
</figure>
<figure>
<img src="/images/xlr-icp-glamour.jpeg" alt="The assembled adapter with spare PCBs, an Endevco 7251HT accelerometer, and a coaxial cable connected to a Bruel &amp; Kjaer 4188 microphone on a 2695 CCLD preamplifier." style="width:75.0%" /><figcaption>The assembled adapter with spare PCBs, an Endevco 7251HT accelerometer, and a coaxial cable connected to a Bruel &amp; Kjaer 4188 microphone on a 2695 CCLD preamplifier.</figcaption>
</figure>
</section>
<section id="but-how-does-it-sound" class="level2">
<h2>But how does it sound?</h2>
<p>Noisy—if there’s no accelerometer connected. I think this is the noise of the 30 V Zener, though thankfully this disappears immediately when a sensor is connected, since the Zener no longer conducts.</p>
<p>With the accelerometer connected, the noise disappears and we get a clear signal.</p>
</section>
<section class="footnotes">
<hr />
<ol>
<li id="fn1"><p>Many balanced systems achieve this by sending equal and opposite signals down each pin, so the difference between the two is two times the signal. This is common enough that many people treat it as the definition of a balanced signal; but for rejecting noise, all that matters is that the impedances to ground are equal.<a href="#fnref1" class="footnote-back">↩</a></p></li>
<li id="fn2"><p>In principle this BNC connector is incorrect: accelerometer manufacturers usually use cable with 50Ω characteristic impedance, but this connector is 75Ω impedance. Neutrik makes 75Ω connectors because they are widely used for digital video (<a href="https://en.wikipedia.org/wiki/Serial_digital_interface">SDI</a>) and audio (<a href="https://en.wikipedia.org/wiki/AES3">AES3</a>). But at typical audio frequencies, the impedance mismatch does not matter; the cable is not a transmission line and there will be negligible effect on the signal.<a href="#fnref2" class="footnote-back">↩</a></p></li>
</ol>
</section>]]></description>
    <pubDate>Sat, 14 Oct 2023 00:00:00 UT</pubDate>
    <guid>https://www.refsmmat.com/posts/2023-10-21-further-accelerometer-adventures.html</guid>
    <dc:creator>Alex Reinhart</dc:creator>
</item>
<item>
    <title>Powering accelerometers for fun, profit, and field recording</title>
    <link>https://www.refsmmat.com/posts/2022-02-12-accelerometers-fun-profit.html</link>
    <description><![CDATA[<p>It’s a common problem that I’m sure many of you have experienced: You find yourself with a <a href="https://www.pcb.com/products?m=352c68">PCB 352C68</a> accelerometer but no ICP signal conditioner to connect it to your recorder.</p>
<p>No?</p>
<p>Let me start over. Suppose you want to know how something sounds <em>on the inside</em>, by listening to the vibrations transmitted through its structure. Like this:</p>
<figure>
<video controls width="700" src="/images/accelerominator-hamilton.mp4">
</figure>

<p>Be sure to watch the video with its sound. That’s not a microphone; it’s an industrial accelerometer that measures extremely fine vibrations, like a contact microphone.</p>
<p>Unfortunately, industrial accelerometers are designed to be connected to industrial data acquisition systems that cost many thousands of dollars, not to cheap audio recorders, and so I needed an adapter. Why? Partly to listen to watermelons, but more on that later.</p>
<section id="a-word-on-recording-vibration" class="level2">
<h2>A word on recording vibration</h2>
<p>Recording vibration is common enough. Many acoustic guitars come with a “piezo pickup” that converts vibrations in the guitar’s body into signals for your amplifier or recorder, so you don’t need to use a microphone that might pick up background noises. You can use the same principle for many acoustic instruments, and professional sound effects designers have used this trick for years. If you want to record an unusual sound without any background noise, why not record the vibrations directly from the source?</p>
<p>In this application, sound designers and field recordists use what they call “contact microphones”. Contact microphones are made from a piezoelectric crystal sandwiched between pieces of metal:</p>
<figure>
<img src="/images/piezo-buzzer.jpg" alt="A piezoelectric disk buzzer, such as you might turn into a DIY contact microphone. Photo by Gophi, CC BY-SA 3.0, via Wikimedia Commons." style="width:50.0%" /><figcaption>A piezoelectric disk buzzer, such as you might turn into a DIY contact microphone. Photo by Gophi, <a href="https://creativecommons.org/licenses/by-sa/3.0/deed.en">CC BY-SA 3.0</a>, via Wikimedia Commons.</figcaption>
</figure>
<p>A piezoelectric crystal produces a voltage when it is compressed. If you place it on an object that vibrates, the vibrations push on the crystal, and the crystal produces a voltage you can record just like the voltage from a microphone. You can make a DIY contact microphone using a cheap piezoelectric buzzer, or order premade versions, such as from <a href="https://jezrileyfrench.co.uk/contact-microphones.php">Jez riley French</a> or <a href="https://cortadomic.com/">Cortado</a>. Creative field recordists place their contact microphones on just about anything, discovering strange noises from things as mundane as <a href="https://criticalvibrations.com/contact-mic-recording-chain-link-fence/">chain link fences</a>, <a href="https://vimeo.com/11176285">suspension bridges</a>, <a href="https://soundcloud.com/maaheli/wind-on-a-dead-pine-branch">dead trees</a>, and <a href="https://soundcloud.com/user-355006298/cracking-ice">ice cracking on a frozen lake</a>.</p>
</section>
<section id="when-a-pcb-352c68-meets-a-watermelon" class="level2">
<h2>When a PCB 352C68 meets a watermelon</h2>
<p>Vibration recording is also very common in science and industry. Consider some examples:</p>
<ol>
<li>Your job is to ensure new car engines meet legal noise requirements and don’t rattle, shake, or vibrate in ways that wear out parts or irritate drivers. You need to measure how they vibrate.</li>
<li>You work in a facility full of heavy machinery with motors, gears, and pumps. If a machine unexpectedly fails, the company loses lots of money. You want to measure vibration in the motors and bearings so you can tell if one is wearing out and needs to be replaced.</li>
<li>You’re designing a lightweight structure for a vehicle. You want to know how that structure will flex and vibrate when it hits bumps and potholes.</li>
</ol>
<p>These scenarios happen every day in engineering and industrial firms, and so specialized tools exist to measure all kinds of vibration. These are generally called “accelerometers.” Unlike the accelerometer in your phone that measures which direction is up, they are designed to measure vibration, often up to tens of thousands of Hertz, and they do so very precisely. Most accelerometers use piezoelectric crystals, just like in contact microphones, but in enclosed metal housings. A good accelerometer comes with a calibration certificate that states exactly how many millivolts of signal it produces for every <em>g</em> of acceleration it experiences, and a chart of how that changes with vibration frequency. A good accelerometer will withstand large vibrations in tough environments filled with heat, oil, and solvents, and will cost you hundreds or thousands of dollars.</p>
<p>Coincidentally, my father falls in category #1 above. For many years, he was a Noise, Vibration, and Harshness (NVH) engineer in the automotive industry. He used accelerometers and measurement microphones routinely in his work, and he still has an uncanny ability to identify engine problems by their sound.</p>
<p>Naturally, when I was a kid – and I’m sure you’re thinking the same thing already – all we wanted him to do was to use his technical abilities to tell us which watermelons are ripe.</p>
<p>Folk wisdom holds that you can knock on watermelons to judge their ripeness. A good watermelon sounds hollow and resonant, not dead or muted. Presumably this has something to do with the stiffness of the flesh, the amount of water it contains, and maybe some chemical changes in its structure as it matures. And if your dad has expensive measurement equipment, why not use it to measure the ideal watermelon?</p>
<p>So that’s what we did. One summer in high school, I was part of the <a href="https://yes.space.swri.edu/">Young Engineers and Scientists</a> program at the Southwest Research Institute, and part of the program asked us to develop our own science project to run over the summer. I chose to study watermelons, and asked Dad for some technical support. He turned to <a href="https://www.pcb.com/">PCB Piezotronics</a> and asked if they might have an accelerometer that could be used for a science project – maybe one that was slightly out of spec or had been returned. To our surprise, we soon received a spotless <a href="https://www.pcb.com/products?m=352c68">model 352C68</a>, and off we went.</p>
<p>The experiment was simple. Dad brought home a high-end laboratory data acquisition system and hooked it to his laptop, while Mom selected eight watermelons for test. We strapped the accelerometer to one side of the watermelon and gently tapped the other side with a small wrench. The result was eight recordings with surprising variety. Just listen to how different Melon A is from Melon C:</p>
<figure>
<figcaption>Melon A:</figcaption>
<audio controls src="/images/melon-a.wav">
</figure>
<figure>
<figcaption>Melon C:</figcaption>
<audio controls src="/images/melon-c.wav">
</figure>

<p>Then Dad invited over some coworkers for a party, and everyone tasted the watermelons and gave them ratings. Using professional acoustics software, we extracted various features from the signals, such as resonant frequencies and reverberation times, and I plugged the numbers into Excel in the hopes of producing a prediction system.</p>
<p>Unfortunately, with only eight melons it’s hard to build a sophisticated model. (Also I was in high school, had never taken a statistics class, and had only a fuzzy understanding of what regression does.) We did note that the mushy and overripe melons were easy to distinguish from the rest, because the mushy ones had no reverb and the knocks damped very quickly. But that’s as far as we got. We considered collecting more data, but eventually I left for college and the accelerometer sat in the closet.<a href="#fn1" class="footnote-ref" id="fnref1"><sup>1</sup></a></p>
</section>
<section id="the-basics-of-icp-signal-conditioning" class="level2">
<h2>The basics of ICP signal conditioning</h2>
<p>Recently I found the accelerometer again and wanted to try it out. But I hit a snag: Industrial accelerometers are not like microphones or headphones and don’t plug into ordinary recorders or amplifiers you might use for podcasting or music. They use a system variously called ICP, IEPE, DeltaTron, CCLD, or IsoTron by different manufacturers. The short version is this: Signals from piezoelectric crystals have high impedance, so when they are plugged into a typical amplifier or audio recorder, they sound quite tinny. You need to <a href="https://www.richardmudhar.com/blog/using-piezo-contact-mics-right/">use a specific type of preamplifier</a> that can convert the output to a low-impedance signal. ICP accelerometers have these preamplifiers built in, but to make those electronics work, they require a power source. To provide that power and also transmit the signal, they use a coaxial cable.</p>
<p>The center conductor of the cable carries the power, from a constant-current supply usually set at 4 mA and 18-30 V. The shield acts as ground. The accelerometer’s integrated electronics consume the 4 mA supply, and the voltage across the accelerometer varies in proportion to the amount of acceleration it experiences – record the voltage and you have the signal. In the case of the PCB 352C68, measurements of ±50 gs of acceleration become ±5 volts. So whatever device you plug the accelerometer into must have the ability to supply the right power and then extract out the signal.</p>
<p>(Professional condenser microphones also have integrated electronics, and receive 48 volt “<a href="https://en.wikipedia.org/wiki/Phantom_power">phantom power</a>” over the same cable that conducts the microphone signal. But the details are different, and you can’t just hook an ICP accelerometer to phantom power.<a href="#fn2" class="footnote-ref" id="fnref2"><sup>2</sup></a>)</p>
<p>Because industrial accelerometers output a precisely calibrated voltage signal, they are typically plugged into precisely calibrated measurement equipment. Much of this equipment can provide the necessary power. If not, you can always buy a “signal conditioner”: plug it between your accelerometer and your recording device and everything will work great.</p>
<p>Except there are two problems:</p>
<ol>
<li>PCB’s <a href="https://www.pcb.com/products?m=480C02">cheapest battery-powered signal conditioner</a> is still $250.</li>
<li>Signal conditioners are designed to be plugged into specialized test equipment, not commodity recording equipment. They come with <a href="https://en.wikipedia.org/wiki/BNC_connector">BNC connectors</a> for coaxial cables to be plugged into industrial data acquisition hardware, not with standard audio connectors (like phone jacks or XLR cables).</li>
</ol>
<p>I’m just a guy who wants to record funny noises. I don’t care about calibration, and I don’t want to pay hundreds of dollars for a signal conditioner and thousands more for a special data acquisition system.</p>
<p>Back in high school I built a simple signal conditioner, in anticipation of further watermelon experiments. It was based on a circuit design from an expert in the field, shoehorned into a small plastic box from Radio Shack. It required three nine-volt batteries so it could provide 27 volts, but that made it bulky; instead of a constant-current supply, it used a resistor to limit the total current; and the only output was a 3.5mm audio jack. I wanted to create a new version using a better circuit design, a shielded metal enclosure, and more convenient output jacks for connection to recording equipment.</p>
<p>Fortunately the pandemic has supplied limitless boredom. So how can we make this problem more complicated while solving it?</p>
</section>
<section id="electronics-for-a-diy-icp-supply" class="level2">
<h2>Electronics for a DIY ICP supply</h2>
<p>The first problem was understanding the circuit I needed to build so I could buy the right parts. Unfortunately, it turns out that very few people have made their own ICP power supplies, or if they have, they haven’t posted it on the Internet. (I’m sure many technicians and engineers have built or repaired them in the course of their work.) The only detailed example I found was <a href="https://sound-au.com/project134.htm">Project 134</a> from Rod Elliott of Elliott Sound Products, who follows the “Why buy a part when I can build it myself?” design philosophy. His version requires wall power, a transformer, and electronics to produce a 24 V DC supply, but I wanted something battery powered and simpler.</p>
<p>After stumbling around, I discovered a PCB manual that provides a handy diagram of their ideal circuit:</p>
<figure>
<img src="/images/icp-schematic.png" alt="From PCB’s General Signal Conditioning Guide." style="width:50.0%" /><figcaption>From PCB’s <a href="https://www.pcb.com/techsupport/docs/pcb/PCB-G0001E-0303.pdf">General Signal Conditioning Guide</a>.</figcaption>
</figure>
<p>The description states:</p>
<blockquote>
<p>The signal conditioner consists of a well-regulated 18 to 30 VDC source (battery or line-powered), a current-regulating diode (or equivalent constant current circuit), and a capacitor for decoupling (removing the bias voltage) the signal…. The current-regulating diode is used instead of a resistor for several reasons. The very high dynamic resistance of the diode yields a source follower gain which is extremely close to unity and independent of input voltage. Also, the diode can be changed to supply higher currents for driving long cable lengths. Constant current diodes, as shown in Figure 8, are used in all of PCB’s battery powered signal conditioners.</p>
</blockquote>
<p>Current-regulating diodes turn about six different components from Project 134 into a <a href="https://www.mouser.com/ProductDetail/954-E-102">four parts</a> you can order for 97 cents each from Mouser. (Four because each current-regulating diode supplies 1 mA.) My previous rat’s nest of electronics was the resistor-based design PCB warns against, so I started sketching out a new design:</p>
<figure>
<img src="/images/accelerominator.png" alt="The Accelerominator 3000 ICP power supply." style="width:75.0%" /><figcaption>The Accelerominator 3000 ICP power supply.</figcaption>
</figure>
<p>Some notes on the components used:</p>
<ul>
<li>The power passes through a <a href="https://www.tracopower.com/series/trn-1">Traco TRN 1-0515</a>, a regulated DC-DC converter that boosts 9 volts to 24 volts. It’s a switch-mode power supply rated for a minimum 100 kHz switching frequency and 45 milliamps of output. It’s nice because it’s tiny and it’s rated for a suitably low power; I tried using a <a href="https://www.pololu.com/product/2890">Pololu adjustable supply</a> that was rated for multiple amps, but I was drawing so little power that the switching supply would skip pulses periodically. Unfortunately the frequency at which it skipped pulses was in the audible range, so this manifested as high-frequency noise in the audio signal.</li>
<li>R3 is not strictly necessary, but allows smartphones to recognize input from the accelerometer as a microphone. Smartphones use <a href="https://en.wikipedia.org/wiki/Phone_connector_(audio)#TRRS_standards">TRRS connectors</a>, which are 3.5mm jacks that support stereo output and mono microphone input; to detect whether you’ve plugged in ordinary headphones or a headset with microphone, your phone senses the resistance between one of the rings and the sleeve. Manufacturers don’t supply specifications for the exact resistance needed, but I read that 1.6 kΩ worked, and I had a 1.5kΩ resistor handy. I’m not using this feature in the current circuit as I haven’t built a TRRS jack into the case, but I could easily add the jack if I find it useful.</li>
<li>Capacitor C1 provides AC coupling between the input and the output, ensuring that the 24 volts supplied to the accelerometer is not supplied to the phone or computer recording the signal. Together with R3, it forms a high-pass filter with a shoulder at about 10 Hz.</li>
<li>The diagram shows a power switch, but I didn’t want a switch poking out of the enclosure that I could bump accidentally. Instead, I used a <a href="https://www.switchcraft.com/ProductSummary.aspx?Parent=67">Switchcraft 113X</a> panel-mount 1/4&quot; TS jack for the audio output, which has a normally open isolated terminal that closes when a plug is inserted. The circuit is hence powered whenever something is plugged into the output jack.</li>
<li>Diodes D6 and D7 are 7.5 V zeners. When the BNC jack is disconnected or the power is turned off, the positive side of C1 can suddenly drop from 12 to 24V down to zero, causing a voltage spike on the output. The diodes clamp this spike to roughly 7.5 V. Most ICP devices can only provide ±7 V of output, so this should never clip a real signal.</li>
</ul>
<p>I assembled the components on a <a href="https://www.adafruit.com/product/1608">Perma-Proto breadboard</a> and crammed it, with a 9V battery, into a small extruded aluminum enclosure <a href="https://www.hammfg.com/electronics/small-case/extruded/1455">from Hammond</a>. The prototype looks great:<a href="#fn3" class="footnote-ref" id="fnref3"><sup>3</sup></a></p>
<figure>
<img src="/images/accelerominator-3000.jpg" alt="The Accelerominator 3000 in its enclosure." style="width:75.0%" /><figcaption>The Accelerominator 3000 in its enclosure.</figcaption>
</figure>
<p>I use a short TS cable to connect the output to a Tascam DR-40X audio recorder, which is able to treat TS inputs as either mic-level or line-level. (I would have used XLR output instead, but I couldn’t find a cheap panel-mount XLR jack that would fit in my enclosure easily.)</p>
</section>
<section id="field-recording-with-an-accelerometer" class="level2">
<h2>Field recording with an accelerometer</h2>
<p>To record interesting sounds, I needed reliable ways to mount the accelerometer onto surfaces. Its end has an integral threaded stud, but the threads are #5-40 UNC, and it turns out nobody uses that thread size in products – by convention, it seems everyone just uses the even-numbered sizes like #4-40 and #6-32. For instance, many vendors sell threaded magnets that could be useful to mount the accelerometer onto metal surface, but none sold them with #5-40 threads. Instead I built my own using a #5-40 washer, a magnet, and Gorilla Glue.</p>
<p>The accelerometer also came with a small box of what PCB calls “petro wax”, which I assume is simply paraffin. This is meant to be used to stick the accelerometer onto a surface temporarily. Because the wax is soft, it attenuates some of the higher vibration frequencies, but it can work for non-metallic surfaces.</p>
<p>(In industrial settings, one usually attaches accelerometers more robustly: either drill and tap a hole into the item being tested, so the accelerometer can be screwed right in, or glue the accelerometer to the surface with cyanoacrylate glue or epoxy. Once the test is done, the glue can be removed with a suitable solvent and the accelerometer carefully pried off the surface. Because the glue is extremely hard, it dampens vibrations very little.)</p>
<p>In any case, how does it sound?</p>
<p>First, here’s the winding and shutter mechanism of my <a href="https://global.canon/en/c-museum/product/film84.html">Canonet G-III QL17</a> film camera (dating from the early 1970s):</p>
<figure>
<figcaption>Canonet QL17 shutter, via accelerometer:</figcaption>
<audio controls src="/images/canonet-shutter.mp3">
</figure>

<p>The Canonet is all-mechanical – no batteries necessary for basic operation. You can hear the winding ratchet mechanism, the shutter firing, and the clockwork mechanism that times the shutter. (In between the two shots, I adjusted the shutter speed to 1/4 second.) It’s like being inside the camera.</p>
<p>For this second test, I wax-mounted the accelerometer on my Unicomp mechanical keyboard, successor to the famous (and famously loud) <a href="https://en.wikipedia.org/wiki/Model_M_keyboard">IBM Model M</a>. Here’s the result of a quick typing test:</p>
<figure>
<figcaption>Model M typing, via accelerometer:</figcaption>
<audio controls src="/images/model-m.mp3">
</figure>

</section>
<section id="bonus-round-measurement-microphones" class="level2">
<h2>Bonus round: Measurement microphones</h2>
<p>Accelerometers are not the only sensors that use the ICP system. Measurement microphones, such as those made by PCB or by Brüel &amp; Kjær, often use ICP because their users already have ICP data acquisition equipment.</p>
<p>Measurement microphones are an interesting category. They’re designed for engineering and scientific applications: they are robustly built, have extremely flat frequency responses over their useful range, and are designed to be extremely stable, meaning they output a very consistent voltage for a certain sound pressure level. This allows them to be used for precise measurements, and because they can be calibrated to measure sound pressure level accurately, they can be used in noise measurements in applications where there’s a legal noise limit on a product or workplace.</p>
<p>Measurement microphones are almost invariably small-diaphragm condenser microphones, just like the pencil microphones you might use in music recording. (But unlike the large-diaphragm condensers you often see used for vocals, which usually do not have flat frequency responses – a recording engineer chooses the microphone whose tone best suits the singer’s voice.) Just like good-quality studio microphones, they are expensive to buy new. And by “expensive”, I mean they don’t even have a price listed, only a form to request a quote.</p>
<p>But through the magic of eBay, I found a <a href="https://www.bksv.com/en/transducers/acoustic/microphones/microphone-cartridges/4188">Brüel &amp; Kjær Type 4188</a> microphone capsule mated to a <a href="https://www.bksv.com/en/transducers/acoustic/microphones/preamplifiers/2695">Type 2695</a> preamplifier for just $240, including shipping. That’s much lower than you’d typically find either listed for individually. (The <em>same seller</em> lists another Type 2695 for $800!) This deal was slightly undermined by needing to spend $50 on a 12-foot cable with the right connectors (BNC and 10-32 microdot) to connect to my ICP power supply, but I still think I came out ahead. The microphone is astonishingly tiny, just 1/2&quot; (12mm) in diameter and 1.5&quot; (40mm) long, but more sensitive and accurate than all but the most expensive studio microphones.<a href="#fn4" class="footnote-ref" id="fnref4"><sup>4</sup></a></p>
<p>Here’s what the same Model M keyboard sounds like, with the microphone perched a few inches above the keyboard on my water bottle, because I don’t own a microphone stand:</p>
<figure>
<figcaption>Model M typing, via microphone:</figcaption>
<audio controls src="/images/model-m-microphone.mp3">
</figure>

</section>
<section id="concluding-thoughts" class="level2">
<h2>Concluding thoughts</h2>
<p>Now that I have the equipment to use them, I’m not sure what to use the microphone or accelerometer <em>for</em>. Maybe there’s a niche for ASMR for mechanical keyboard enthusiasts.</p>
<p>I do think it’s interesting that the field recording community has found uses for piezoelectric contact microphones, and even more esoteric instruments like <a href="https://store.lom.audio/products/geofon">geophones</a>, but I’m not aware of anyone using an industrial accelerometer for any similar recording. Possibly this is because nobody knows they exist; also their cost is likely prohibitive for anyone who just wants to tinker with sound. But used ICP accelerometers are available on eBay regularly for not-outrageous prices, and the ICP power supply above requires about the same skill to build as a good contact microphone preamplifier. If you’re feeling adventurous and don’t mind building your own electronics, maybe it’s worth a try.<a href="#fn5" class="footnote-ref" id="fnref5"><sup>5</sup></a></p>
<p>I hope to explore more interesting noises this year when the weather warms up. I’m sure Pittsburgh’s many metal structures and bridges make interesting vibrations, though I’d prefer they <a href="https://en.wikipedia.org/wiki/Fern_Hollow_Bridge">not get <em>too</em> interesting</a> while I’m standing on the bridge.</p>
</section>
<section class="footnotes">
<hr />
<ol>
<li id="fn1"><p>There has been real scientific research about acoustic watermelon ripeness detection, though some of it seems… dubious. See <a href="/notebooks/watermelons.html">this summary</a> for references. I told this story, including the dubious research results, in the second statistics class I ever taught – an intro course during the summer 2014 session. At the end of the semester, the students brought me a gift: several miniature watermelons. It was touching, except I couldn’t figure out how to carry them all back to my office before the next instructor arrived in the classroom.<a href="#fnref1" class="footnote-back">↩</a></p></li>
<li id="fn2"><p>ACO Pacific does make the <a href="https://www.acopacific.com/ICP1248.html">IEPE 1248</a> phantom power adapter system, but I’m afraid to ask how expensive it is.<a href="#fnref2" class="footnote-back">↩</a></p></li>
<li id="fn3"><p>Special thanks to my friend Alex, who owns one of every power tool and let me use his drill press and step bits to make holes for the audio jacks.<a href="#fnref3" class="footnote-back">↩</a></p></li>
<li id="fn4"><p>That’s not to say it’s <em>better</em> than most studio microphones. Studio microphones are usually directional, so they can record a singer or instrument without picking up other noises from the room, echos from the studio walls, or crowd noise on-stage. Measurement microphones are omnidirectional, so isolating your subject is challenging unless you have a soundproof anechoic chamber. Sadly I could not find one of those on eBay for $240.<a href="#fnref4" class="footnote-back">↩</a></p></li>
<li id="fn5"><p>Be sure to get an ICP accelerometer, not a charge-mode or charge-output accelerometer, which requires a different preamplifier. You’ll see many triaxial models that measure outputs in three directions, and hence have three outputs and need three signal conditioners; but a single-axis model should be plenty. Mine has a sensitivity of 100 mV/g, and some are available with even higher sensitivities. Be aware that some have very low sensitivity, such as 2.5 mV/g; these won’t be useful for recording small and quiet vibrations, but since they can withstand extremely high accelerations, they might be useful if you want to record something extremely violent.<a href="#fnref5" class="footnote-back">↩</a></p></li>
</ol>
</section>]]></description>
    <pubDate>Sat, 12 Feb 2022 00:00:00 UT</pubDate>
    <guid>https://www.refsmmat.com/posts/2022-02-12-accelerometers-fun-profit.html</guid>
    <dc:creator>Alex Reinhart</dc:creator>
</item>
<item>
    <title>Using statistics and cognitive science to understand how students learn statistics</title>
    <link>https://www.refsmmat.com/posts/2020-02-06-cognitive-science-learning-statistics.html</link>
    <description><![CDATA[<blockquote>
<p>On November 18, 2019, I gave a department “internal seminar” on <a href="http://www.stat.cmu.edu/teachstat/">the TeachStat Research Group’s</a> work on statistics education research. The internal seminars are intended for faculty in <a href="http://www.stat.cmu.edu/">Statistics &amp; Data Science</a> here at CMU to get to know each other’s work better, and to interact with graduate students and faculty from other departments who may also be interested. This is not a transcript, but, as <a href="https://www.youtube.com/watch?v=jNKjShmHw7s">Sir Humphrey would say</a>, “a version which represents my views as I would, on reflection, have liked them to emerge”.</p>
</blockquote>
<p>For the past two years, I’ve been working with a group of Ph.D. students and faculty here at CMU on new projects in statistics education research. There have been quite a few people involved:</p>
<figure>
<img src="/images/teachstat-headshots.png" alt="The TeachStat Research Group team. Top, from left: me, Philipp Burckhardt, Peter Elliott, Ciaran Evans, Amanda Luby, Mikaela Meyer, and Josue Orellana. Bottom: Ron Yurko, Gordon Weinberg, Jerzy Wieczorek, and Rebeecca Nugent. Credit also to Sangwon Hyun, Kevin Lin, and Christopher Peter Makris for their support." style="width:75.0%" /><figcaption>The <a href="http://www.stat.cmu.edu/teachstat/">TeachStat Research Group</a> team. Top, from left: me, Philipp Burckhardt, Peter Elliott, Ciaran Evans, Amanda Luby, Mikaela Meyer, and Josue Orellana. Bottom: Ron Yurko, Gordon Weinberg, Jerzy Wieczorek, and Rebeecca Nugent. Credit also to Sangwon Hyun, Kevin Lin, and Christopher Peter Makris for their support.</figcaption>
</figure>
<p>So what’s the problem we’re trying to solve? It’s a big, long-term problem. It’s one you’ve probably all seen when you teach your classes. There is simply a <em>massive</em> gap between how we think, as statisticians with experience analyzing data, and how our students think, as novices seeing data for the first time. And that gap doesn’t shrink nearly as much as we would like it to during a course.</p>
<p>This manifests in several ways. You might have had the experience of teaching an upper-level class and referring to some concept that the students should already know—only to find that they don’t seem to understand it. You might have taught an introductory class and seen that no matter how carefully you explain the meaning of hypothesis tests, the students still misinterpret them. You might have supervised students conducting a course project and seen that they lack intuition about data or the judgment to decide what to try or how to interpret their results.</p>
<p>But it’s not just students. Practicing scientists are notoriously bad at the same things: they misinterpret hypothesis tests, misunderstand regression assumptions, overinterpret small effects, read signal into noise… There’s a lot of research on how scientists understand statistical evidence, and there’s also a lot of research on the prevalence of misinterpreted statistical evidence in science. So much research, in fact, that one can even write <a href="https://www.statisticsdonewrong.com/">a book about it all</a>:</p>
<figure>
<img src="/images/sdw-cover.png" alt="A shameless plug." style="width:35.0%" /><figcaption>A <a href="https://www.statisticsdonewrong.com/">shameless plug</a>.</figcaption>
</figure>
<p>We’ve been pursuing two main projects to address this problem.</p>
<p>First, we’ve been examining and measuring student thinking in introductory statistics courses, using think-aloud interviews and assessments to explore their learning.</p>
<p>Second, we’ve been comparing how students and experts think about problems in a sophomore-level mathematical statistics course. Using think-aloud interviews and cognitive task analysis, we’re exploring the skills involved in solving these problems and exploring which skills are preventing students from succeeding.</p>
<p>We’re planning to use this research to build teaching experiments for our courses: our data will show what concepts students struggle with most, and our assessments will let us measure the effects of any new teaching strategy we try.</p>
<section id="student-learning-in-introductory-courses" class="level2">
<h2>Student learning in introductory courses</h2>
<p><em>This section summarizes work we presented in a <a href="https://arxiv.org/abs/1911.00535">recent preprint</a>. Read it for more detail!</em></p>
<p>Let’s start with introductory statistics courses, where students seem to graduate our courses still holding many misconceptions about <em>p</em> values, sampling distributions, experiments and surveys, and all the other core concepts we aim to teach. (For a survey of the literature, check out my <a href="/notebooks/statistical-misconceptions.html">notebook on statistical misconceptions</a>.)</p>
<p>Statistics education researchers have tried to quantify the size of the problem. They have developed many concept inventories: multiple-choice standardized assessments that you can give to students at the beginning and end of an introductory statistics course, to measure how much they learn. While we can quibble with the details of these inventories and how they’re constructed, one thing is consistent: pre-test scores are low, and post-test scores aren’t much better. There’s just not much evidence that students are learning the concepts we intend them to in the intro class.</p>
<p>For example, the <a href="https://apps3.cehd.umn.edu/artist/caos.html">Comprehensive Assessment of Outcomes in Statistics</a> is the most popular and most thoroughly vetted standardized assessment of student statistical understanding. Large national datasets find average pre-test scores of about 45%, showing that students entering statistics courses have much to learn—but they also find average post-test scores of about 55%, showing that <em>we</em> have much to learn about teaching more effectively.<a href="#fn1" class="footnote-ref" id="fnref1"><sup>1</sup></a></p>
<p>There’s a lot of ongoing work on new teaching strategies to improve this. For example, simulation-based inference is a hot topic right now: rather than teaching statistics through formulas and mathematics, simulation-based inference courses teach the concepts of variation and testing through computer simulations. Instead of learning <span class="math inline">t</span> tests and using tables of distributions, students simulate permutation tests or do a bootstrap. This seems conceptually simpler: they can see directly what they’re doing, they can see that permutation really is making the null hypothesis true by making the two groups equivalent… but the effects are small. At best we’re getting a few more percentage points.<a href="#fn2" class="footnote-ref" id="fnref2"><sup>2</sup></a></p>
<p>Now, it’s worth asking why this is not a solved problem. After all, we’ve been teaching statistics for a century. Statistics education has gone through many revolutions, as computers enter classrooms and students get to practice hands-on with real data. And, of course, we all learn from experience. We adjust our courses based on what students got wrong last year. We introduce new demonstrations and simulations for important concepts. We write new homework and new projects on the topics we think students are missing. And yet here we are.</p>
<p>In fact, during my reading of the statistics education research literature, I have not encountered <em>any</em> experiments showing dramatically improved student learning in an entire course. I just read a <em>Journal of Statistics Education</em> article titled “Do Hands-on Activities Increase Student Understanding?,” and the results indeed confirmed <a href="https://en.wikipedia.org/wiki/Betteridge%27s_law_of_headlines">Betteridge’s Law of Headlines</a>.<a href="#fn3" class="footnote-ref" id="fnref3"><sup>3</sup></a> The same has been happening with simulation-based inference research; the new course designs and new textbooks seem to have only small effects on student learning, and the research is focused on finding exactly which students see a small benefit and which do not.</p>
<p>So why aren’t we making progress? In my view, a key obstacle is our approach. Tinkering with our courses based on intuition, fashion, or frustration is just going to make small steps toward a local optimum. Instead, we need a sound understanding of how our students really think and how they really learn, so we can build new teaching strategies based on systematic knowledge about student learning.</p>
<p>And, of course, we are statisticians. Why do we not teach like statisticians? We need to find ways to model how students learn, so our interventions can be designed based on a formal model of learning. We need to find ways to <em>measure</em> what students learn, so our proposed models can be calibrated and our interventions can be tested empirically. And since we’re statisticians, we need to base our models on real data, and ensure that real data means what we say it does and suits the purposes we want to use it for.</p>
<section id="measuring-learning-in-our-introductory-course" class="level3">
<h3>Measuring learning in our introductory course</h3>
<p>So let’s start with the foundation: measuring student learning. Later I’ll talk about the steps we’re taking to model it, but first we need a foundation of real data.</p>
<p>Our research project began back in summer 2017. In the spring we held a reading group reviewing statistics education research, and we were interested in pursuing education research in the fall. My email over the summer started with somewhat modest goals:</p>
<blockquote>
<p>Any ideas on what our goals should be? We had talked about developing an assessment to replace CAOS and judge whether the new statistical reasoning course is working; other potential topics would be more on psychology and pedagogy, different theories of learning, or writing fan fiction about Galton and Gandhi teaming up. (That was <a href="http://www.stat.cmu.edu/~rnugent/PUBLIC/">Rebecca’s</a> suggestion.)</p>
</blockquote>
<p>Our reasoning, however, was somewhat immodest. There are, of course, pre-existing assessments designed to measure if students are learning concepts in introductory statistics. One is the Comprehensive Assessment of Outcomes in Statistics, as I mentioned above. We weren’t fans of these assessments, which we thought focused on the wrong topics and emphasized memorization of definitions and results over understanding of concepts. We wanted something to measure conceptual understanding of the specific concepts <em>we</em> wanted to teach in <em>our</em> introductory course.</p>
<p>We figured that as statisticians, it can’t be too hard to write some conceptual questions and collect data on student answers. How naive we were.</p>
<p>We soon discovered that writing questions is <em>hard</em>. There’s a reason CAOS questions seemed to focus on remembering definitions: it is <em>very</em> hard to write a question that measures conceptual understanding of basic concepts. It is very hard students to reason about statistical questions and reach conclusions, without relying on them remembering specific terms and specific definitions.</p>
</section>
<section id="think-aloud-interviews-to-the-rescue" class="level3">
<h3>Think-aloud interviews to the rescue</h3>
<p>Fortunately, we can borrow ideas from other areas of education research. In other STEM fields, particularly physics, there is a long history of developing deeply conceptual concept inventories to get at how students think and reason about new situations. This work has been going on since at least the 1990s, and has led to some remarkable results.</p>
<p>The method we adopted was described best by Wendy Adams and Carl Wieman in a paper describing how to build assessments to “measure learning of expert-like thinking”.<a href="#fn4" class="footnote-ref" id="fnref4"><sup>4</sup></a> They describe an iterative method:</p>
<ol>
<li>Experts write questions they believe will measure the intended concepts.</li>
<li>In private interviews, volunteer students answer the draft questions <em>while thinking aloud</em>, so the experts understand how the students approach the questions.</li>
<li>The experts use this data to write new distractor answer choices, improve confusing question wording, write new questions about unexpected misconceptions, and so on.</li>
<li>Even more think-aloud interviews with students validate that the final question versions measure the thinking they are intended to measure.</li>
</ol>
<p>The method that Adams and Wieman advocated for was actually developed here at CMU, by <a href="https://en.wikipedia.org/wiki/Herbert_A._Simon">Herb Simon</a> and Anders Ericsson, back in the late 1970s and early 1980s. As part of their work in artificial intelligence and expert systems, they were interested in learning how human experts reason about complex problems. They developed what they called verbal protocol analysis, and what we now call “think-aloud interviews”, and used these interviews to figure out how an AI system should be designed to think like an expert. A think-aloud interview gets us the closest thing to actual student thinking that we can get without full brain-computer interfaces.<a href="#fn5" class="footnote-ref" id="fnref5"><sup>5</sup></a></p>
<p>In a think-aloud interview, a student—just one student, in a private setting like a conference room—is given one conceptual question to answer. They read it aloud, then say everything they are thinking as they try to find the answer. The interviewer just watches. The interviewer doesn’t prompt the student, offer help, ask questions, or anything else. The goal is to get the student’s authentic thinking, as they would have thought it while answering a question on their own, without the influence from an experimenter making them reflect on decisions or suggesting different strategies. (For practical details and further literature, see my <a href="/notebooks/think-alouds.html">notebook on think-alouds</a>.)</p>
<p>We’ve now completed 47 hour-long think-aloud interviews with students at CMU and at Colby College, covering more than 50 conceptual questions. The results of these interviews are quite dramatic. We found that students frequently misinterpreted questions that we thought were perfectly clear, because students understood wording differently than we did. We found some questions that students could solve entirely through elimination or by using heuristics like “it’s never the answer with ‘always’ in it.” We found that some questions measured completely different thinking than we expected to measure.</p>
<p>As a quick example, we had a question about sampling distributions that we thought was quite good, until think-aloud interviews revealed that most students got it wrong—and got it wrong because they did not understand how to read <em>histograms</em>. Only after we rephrased the question to eliminate these misunderstandings could we trust that students get it wrong because of reasons related to their understanding of sampling distributions, and not of histograms. (For the full story, check out our <a href="https://www.causeweb.org/cause/ecots/ecots18/posters/3-10">eCOTS 2018 video poster</a>.)</p>
<p>This process gave us confidence in our questions. Having seen real students answer the questions, and having heard everything they said while answering them, we now know <em>why</em> they are answering those questions and how they are interpreting them. We eliminated or fixed many questions that turned out to be confusing or elicited student reasoning unrelated to the concepts we intended to measure.</p>
</section>
<section id="assessment-data" class="level3">
<h3>Assessment data</h3>
<p>Along with the interviews, we’ve been collecting quantitative data from students in introductory courses at three different institutions. We started collecting data at Carnegie Mellon and at Colby College in spring 2019, extending to the College of Wooster in fall 2019. We’ve also collected data from students in 36-202, the second-semester statistics class in our department, to see what they retained after the first course. We hope to expand to more institutions in subsequent semesters.</p>
<p>Students complete the pre- and post-test online, through ISLE, the <a href="http://www.stat.cmu.edu/isle/">Integrated Statistics Learning Environment</a>. ISLE presents them with 30 questions in random order and records the data; students get course credit for completing the assessment as part of their first homework and as part of their last homework. They can, of course, opt out of having their data used for research purposes.</p>
</section>
<section id="correlation-and-causation" class="level3">
<h3>Correlation and causation</h3>
<p>The data is useful, and helps us measure changes in the course. But we also found that the access to student thinking we get in think-aloud interviews gave us much deeper insights into student learning.</p>
<p>Consider this question:</p>
<blockquote>
<p>A survey of Californians found a statistically significant positive correlation between number of books read and nearsightedness.</p>
<p>Which of the following can we conclude about Californians?</p>
<p>A. Reading books causes an increased risk of being nearsighted.</p>
<p>B. Being nearsighted causes people to read more books.</p>
<p>C. We cannot determine which factor causes the other, because correlation does not imply causation.</p>
<p>D. We cannot draw any conclusions because Californians aren’t a random sample of people.</p>
</blockquote>
<p>We wanted to test how students understand correlation and causation. We knew, from teaching experience, that introductory students struggle to understand the purpose of randomized experiments and how that differs from random <em>sampling</em>. We also know that people tend to be too willing to draw causal conclusions. So this question was intended to test that understanding. In interviews, and in later data we collected in class, students did quite well on this question. Great, you might think—they get it! But slow down.</p>
<p>Here’s another question we tested in think-aloud interviews.</p>
<blockquote>
<p>A clinical trial randomly assigned subjects to receive either vitamin C or a placebo as a treatment for a cold. The trial found a statistically significant negative correlation between vitamin C dose and the duration of cold symptoms.</p>
<p>Which of the following can we conclude?</p>
</blockquote>
<p>Here, correlation <em>is</em> causation. Because the subjects were randomly assigned, there can be no systematic confounding. Students in interviews answered correctly, and you might assume this means they understand the purpose of randomization—but it doesn’t!</p>
<p>Instead, we observed several students who strongly believed that correlation does not equal causation, and made statements to that effect while answering the question, but then said that this specific case “makes sense” and chose the answer that a causal conclusion can be drawn. One student specifically said that you “usually can’t assume causation,” then said it’s just correlation, then chose the causal answer. Perhaps, we thought, our students were getting the right answer simply because they <em>already</em> believed that vitamin C would help a cold, not because they were applying statistical reasoning.</p>
<p>To test this hypothesis, we tried a new version of the question. We replaced vitamin C, which makes sense as something that might cure colds,<a href="#fn6" class="footnote-ref" id="fnref6"><sup>6</sup></a> with mindfulness meditation. We thought this would avoid the reasoning that the treatment “makes sense,” and would better test whether students really understand the purpose of random assignment:</p>
<blockquote>
<p>A clinical trial randomly assigned subjects to either practice mindfulness meditation or a placebo relaxation exercise as a treatment for a cold. The trial found that subjects who practiced mindfulness meditation had a shorter time to recovery than students assigned to the relaxation exercise, and the result was statistically significant.</p>
<p>Which conclusion does this support?</p>
</blockquote>
<p>The results were dramatically different. Students now insisted that “causes” is too strong a word, and voiced doubts about the possibility of <em>ever</em> proving a causal claim. A couple of choice quotes:</p>
<ul>
<li>“I think the word ‘causes’ is too strong… my friend who’s a stats major always tells me you can’t say this causes that—there’s always other factors”</li>
<li>“Usually [you] can’t assume causation”</li>
</ul>
<p>7 of the 11 students who answered this version of the question in think-aloud interviews got it wrong, answering that correlation is not causation.</p>
<p>We also administered these questions to most students in the class, at the end of the semester. They seem to consistently prefer to deny causal relationships: most students correctly said that in the books question, correlation is not causation, but <em>also</em> said that in the meditation question, correlation is not causation. A smaller proportion recognized that in the meditation question, correlation really is causation.</p>
<table>
<thead>
<tr class="header">
<th></th>
<th>books wrong</th>
<th>books right</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td><strong>meditation wrong</strong></td>
<td>10</td>
<td>67</td>
</tr>
<tr class="even">
<td><strong>meditation right</strong></td>
<td>9</td>
<td>50</td>
</tr>
</tbody>
</table>
<p>That’s exactly the kind of insight we gain by doing interviews instead of just handing out questions. We learned that students were using different reasoning than we expected—they were picking answers because they already believed in the use of Vitamin C—and were able to write new questions to give us a deeper understanding of their reasoning. We now have a small piece of the puzzle in figuring out how to better teach these important concepts.</p>
<p>The results above were from the post test, but the pre-test results were similar, suggesting something else very interesting: that students <em>enter</em> the course already possessing these misconceptions.</p>
<figure>
<img src="/images/xkcd-552-correlation.png" alt="Indeed it did not. (source)" /><figcaption>Indeed it did not. (<a href="https://xkcd.com/552/">source</a>)</figcaption>
</figure>
<p>So where does that leave us? It appears that students are a bit like <a href="https://www.explainxkcd.com/wiki/index.php/Cueball">Cueball</a> in this <a href="https://xkcd.com/">xkcd</a> cartoon: they don’t think correlation implies causation, but that doesn’t mean the class helped. Crucially, they don’t understand when correlation <em>does</em> imply causation. Students seem to <em>enter</em> the class with misconceptions, so the problem may not be that we are teaching them bad habits, but that we are failing to break them.</p>
</section>
<section id="persistent-misconceptions" class="level3">
<h3>Persistent misconceptions</h3>
<p>This gets to a key reason why think-aloud interviews are so important.</p>
<p>Instructors often subscribe to what I call the “empty vessel theory” of teaching. Students begin the semester as empty vessels; as instructors, our job is to carefully distill all the important concepts of the course and carefully pour them into the empty vessel. As long as we use only high-quality ingredients and mix the explanations well, the students will leave the course filled with knowledge.</p>
<p>But, of course, that is not how it works. Students <em>enter</em> our courses with many beliefs about the world and how it works. When they hear our explanations, they do not simply accept them at face value; they <em>already</em> know things, or think they know things, and try to fit our explanations into their existing mental models.</p>
<p>There has been a lot of research on this problem in other fields. Notably, in physics, researchers since the 1980s have explored the numerous misconceptions and prior beliefs students hold about basic Newtonian mechanics. Students enter introductory physics courses having seen that <a href="https://en.wikipedia.org/wiki/Newton%27s_laws_of_motion">objects in motion do <em>not</em> stay in motion</a>, and with colloquial understandings of terms like “force,” “energy,” “momentum,” and so on.<a href="#fn7" class="footnote-ref" id="fnref7"><sup>7</sup></a></p>
<p>And because students “know” these things, they <em>misinterpret our explanations of those same concepts</em> in class. Our explanations do not work because they understand our words differently than we do. Our explanations do not produce a clear understanding in the students because they fit the explanations together with their prior “knowledge” and produce a disjointed, inconsistent understanding.</p>
<p>We have every reason to believe something similar is happening in statistics education. Our students in interviews applied their prior knowledge to override whatever we might have taught about randomized experiments and causality. We have also seen students in interviews appearing to hold multiple mutually incompatible ideas on how to approach problems, switching from one to the other whenever the first doesn’t seem to work—without reflection on how they may be inconsistent.</p>
<p>Fortunately, the education research literature also suggests that this problem can be tackled. It can be tackled <em>when instructors are aware of the misconceptions</em> and approach them head-on, and <em>particularly</em> when instructors use “interactive engagement” teaching strategies that ask students to answer questions and make predictions in class, discussing their predictions with their peers and getting immediate in-class feedback when they are wrong. Extensive data shows these strategies can double or <em>triple</em> student learning.<a href="#fn8" class="footnote-ref" id="fnref8"><sup>8</sup></a> I suspect much of these gains come because students are forced to integrate what they learn in class with their prior beliefs immediately, as they sit in the classroom, instead of passively nodding and accepting a lecture without serious thought.</p>
<p>We hope that think-aloud interviews, combined with our assessment data, can make it possible to craft introductory statistics courses that achieve similar success. But first it will take much more research to fully understand how students think.</p>
</section>
<section id="preliminary-aggregate-results" class="level3">
<h3>Preliminary aggregate results</h3>
<p>From spring, summer, and fall 2019, we have some preliminary results. These are from giving our assessment questions to our existing classes, taught with their usual teaching strategies. You can see here that the mean scores from pre- to post-test do not change dramatically, although there is a sampling bias—some students are not motivated to get a few points at the end of the semester, apparently, so response rates are lower at the end of the semester—that makes strong conclusions hard to draw. Fortunately we are working on addressing that bias in future semesters, and we can match students between pre- and post-test to conduct matched pairs analyses.</p>
<table>
<thead>
<tr class="header">
<th>Section</th>
<th>Pre-test mean</th>
<th>Post-test mean</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td>CMU 200</td>
<td>46.5%</td>
<td>53.0%</td>
</tr>
<tr class="even">
<td>Colby SC 212</td>
<td>51.1%</td>
<td>59.9%</td>
</tr>
<tr class="odd">
<td>CMU 202</td>
<td></td>
<td>57.0%</td>
</tr>
</tbody>
</table>
<p>The small learning gains don’t exactly fill us with hope. But they are not anomalous: prior research using CAOS and other conceptual assessments, flawed though they may be, has found similar results. These results us just how far we have to go.</p>
<p>(Our questions and our full assessment results are available as part of the <a href="https://doi.org/10.1184/R1/10058441">supplemental materials</a> to our <a href="https://arxiv.org/abs/1911.00535">recent preprint</a> describing this work.)</p>
</section>
</section>
<section id="beyond-the-introductory-course" class="level2">
<h2>Beyond the introductory course</h2>
<p>But while this gives us 50-odd questions that we are confident in, it’s only the surface. We teach more than just introductory courses. Many of you have taught or TAed more advanced classes, and you see students struggle there too. I’ve heard lots of anecdotes about students in advanced classes who still don’t seem to understand small <span class="math inline">p</span> values make us reject hypothesis tests, or students who seem to have forgotten everything you swear they must have been taught in prerequisite courses. And we complain that some students seem to want to learn by rote, memorizing procedures without ever developing the statistical <em>thinking</em> they need to succeed. I’ve heard plenty of stories about students who just want to know if their analysis is “right” instead of thinking about what it achieves and how it compares to other methods.</p>
<p>My thesis is that something is wrong with our understanding of how students develop statistical expertise. We’re expecting them to integrate many facts and skills together, then to develop the expertise to know which facts and skills are appropriate to apply to a given problem. How can we explore how students are doing this?</p>
<section id="cognitive-task-analysis" class="level3">
<h3>Cognitive Task Analysis</h3>
<p>One tool is Cognitive Task Analysis. This sounds like a buzzword, but it’s actually just describing something fairly straightforward.</p>
<p>Cognitive Task Analysis models problem-solving as a series of small, discrete steps. Students go from the problem statement to the solution using many specific steps, and we can use interviews with expert problem-solvers to identify the steps experts take. Then, in think-aloud interviews with students, we can learn which steps <em>they</em> take and establish which steps most often lead to errors and mistakes.</p>
<p>Cognitive task analysis has been widely applied for many purposes. Research suggests explicit cognitive task analysis can help better structure teaching, because experts are usually quite bad at identifying the steps they take to solve problems: if asked how they solved a problem, experts often give explanations that are incomplete or outright contradict the result they actually obtained. The evidence suggests that if instructors use explicit cognitive task analyses to guide the skills they teach in a course, student learning can be significantly improved.<a href="#fn9" class="footnote-ref" id="fnref9"><sup>9</sup></a> (For further literature, and ways to assess cognitive tasks quantitatively, check out <a href="/notebooks/cognitive-task-analysis.html">my notebook</a>.)</p>
<p>Also, cognitive task analysis has already been applied to statistics. Marsha Lovett used it to explore how students analyze data in the introductory course—actually, in <em>our</em> introductory course, back around 2000.<a href="#fn10" class="footnote-ref" id="fnref10"><sup>10</sup></a> Think-aloud interviews allowed her to see the cognitive tasks being applied by students as they analyzed data, and led to a simple teaching intervention targeting one specific cognitive task that then improved their performance on another data analysis problem. Ken Koedinger and Elizabeth McLaughlin later showed that these targeted interventions can work better than just providing extra practice solving problems.<a href="#fn11" class="footnote-ref" id="fnref11"><sup>11</sup></a></p>
</section>
<section id="exploring-cognitive-tasks-in-mathematical-statistics" class="level3">
<h3>Exploring cognitive tasks in mathematical statistics</h3>
<p>Now, ideally we could build on that work to develop a full cognitive task model of how students analyze data, break down the pieces in great detail, and then examine how all our courses cover the constituent skills as we lead students to graduation. But this is a fairly intimidating ensemble of skills, and data analysis is a <em>very</em> open-ended outcome.</p>
<p>Instead, TeachStat group members Josue Orellana and Mikaela Meyer started with a different problem. They started by considering how students approach simple mathematical statistics problems on topics like conditional and marginal distributions, maximum likelihood, and expectations and variances. They hypothesized there are at least four separate cognitive tasks involved: after reading the question, the student must</p>
<ol>
<li>identify the relevant variables in the problem, such as which variable we want to maximize or which variables are constant,</li>
<li>select appropriate rules, such as Bayes’ theorem or rules about expectation and variance, that would solve the problem,</li>
<li>match the rules to the variables they must be applied to,</li>
<li>carry out the actual algebra and calculus needed to manipulate the rules and obtain the answer, and finally</li>
<li>report an answer.</li>
</ol>
<p>To explore if this framework was correct, and to see which specific skills students struggle with, we conducted think-aloud interviews. We recruited volunteers from 36-226, our undergraduate introductory mathematical statistics course. Students in this class have already taken a probability course, and calculus is listed as prerequisite. We also recruited statistics and data science Ph.D. students as experts, so we could contrast student approaches to problem-solving with expert approaches. And we drafted 25 questions on the statistics topics, supplementing these with some questions about basic calculus, so we could locate gaps in mathematical understanding. All questions were checked for consistency with the notation and terminology used in the course.</p>
<p>Eventually we conducted 16 interviews with novices and 8 with experts. All were 60 minutes long, and we recorded all of the answers so they could later be transcribed and coded.</p>
</section>
<section id="an-example-finding-maximum-likelihood-estimators" class="level3">
<h3>An example: Finding maximum likelihood estimators</h3>
<p>Here’s one example. We asked the participants to find the maximum likelihood estimate for the mean of a normal distribution, given <span class="math inline">n</span> samples:</p>
<blockquote>
<p>The log-likelihood for <span class="math inline">x_1, x_2, \dots, x_n</span> iid samples from a univariate normal distribution is</p>
<p><span class="math display">
\log L(\mu, \sigma) = - \frac{n}{2} \log(2 \pi \sigma^2) -
\frac{1}{2\sigma^2} \sum_{i=1}^n (x_i - \mu)^2.
</span></p>
<p>Find <span class="math inline">\hat \mu_\text{MLE}</span>.</p>
</blockquote>
<p>The ideal solution would involve taking the derivative with respect to <span class="math inline">\mu</span>, setting it to zero, and finding the maximum in terms of <span class="math inline">x_i</span>. You can probably imagine several ways students could mess this up, based on the cognitive tasks we described. Students might not know which variables are relevant, and take the derivative with respect to the wrong thing. Students might not know the relevant rule, and hence not know they need to take a derivative to maximize. Students might mess up the algebra or calculus as they implement the rule. Our interviews let us isolate these reasons.</p>
<p>In the interviews, we found that as you’d expect, experts immediately knew the procedure and the answer. They commented that the answer must be the sample mean, but they’d take the derivative to be sure.</p>
<p>For students, things were a bit different. One student reported that “I always get weirded out when I have to do the derivative of a sum, like I don’t really know if there’s rules…” We saw this confusion several times across multiple questions and students. Students seem confused by the summation symbol and don’t know how to take derivatives.</p>
<p>But more importantly, several students showed confusion about the relevant variable. Here’s a representative quote from a student who didn’t know what variable to differentiate:</p>
<blockquote>
<p>So we just take the derivative of this with respect to… what do you call it, sigma, right? … Or is [it] with respect to sigma, or with respect to mu?</p>
</blockquote>
<p>Another student wanted to take the derivative with respect to <span class="math inline">x</span>.</p>
<p>Only 4 of the 11 students who answered this question in interviews got it right, despite it being essentially the bread and butter of a mathematical statistics course. And it seems several cognitive tasks are implicated. It’s possible, following Koedinger’s experiment that I mentioned earlier, that targeted practice on the specific skill of identifying which variable is relevant might improve student performance substantially. We’re hoping to find out soon.</p>
<p>Unfortunately we have not yet transcribed and coded many of the interviews, so I can’t go into much more depth about what we found. We will be transcribing and coding more questions soon to summarize the cognitive tasks in more detail and, ideally, find an intervention to experiment with.</p>
<p>Oh—and as an aside, one problem we noticed consistently in our interviews was the <em>Greek alphabet</em>. Statistics often uses symbols like <span class="math inline">\mu</span>, <span class="math inline">\sigma</span>, <span class="math inline">\theta</span>, and so on, but we repeatedly saw that students cannot recognize or name these symbols. Can your lectures be successful if students do not know what you’re referring to when you mention <span class="math inline">\mu</span> or <span class="math inline">\sigma</span> and point at a derivation on the board?</p>
</section>
</section>
<section id="conclusions" class="level2">
<h2>Conclusions</h2>
<p>Let’s review the story so far.</p>
<p>Over the past two years, our group has conducted more than 60 think-aloud interviews with students at the introductory and sophomore level. In the introductory course, this has helped us develop dozens of assessment questions and isolate many misconceptions. We’ve also collected pre- and post-test data for hundreds of students at three separate institutions, leading to a <a href="https://arxiv.org/abs/1911.00535">preprint summarizing our results</a> (and the <a href="https://doi.org/10.1184/R1/10058441">data is available too</a>). Separately, in the sophomore mathematical statistics course we have begun to break down the cognitive tasks involved in doing mathematical statistics problems, so we can see which tasks are most difficult for students.</p>
<p>So what do we plan next?</p>
<p>First, we’d like to use think-aloud interviews and cognitive task analysis to explore some specific topics more deeply. We’re currently working on questions and interviews to explore how students understand correlation and causation, for example, and we’d also like to explore their understanding of populations and sampling distributions. (There is also a surprising amount of confusion about the interpretation of histograms, which should be explored.)</p>
<p>Second, we’d like to use the interviews and psychometric analysis (such as <a href="/notebooks/item-response-theory.html">item response theory</a>) to further refine our assessment questions and produce a set of questions that reliably measure specific introductory concepts. We’re not sure that a single validated instrument, like CAOS or other concept inventories, would be as useful as a collection of questions on various topics that we can choose from as needed.</p>
<p>But having the questions will enable our third goal: designing and evaluating new teaching strategies based on our results. Once we thoroughly understand how students misunderstand a statistical concept, and we have assessment questions that reliably measure their understanding, we can revise our teaching and measure whether the new strategy works. And we can base our new teaching strategy on our research and prior results about student learning, rather than on our intuition about what explanations might work best.</p>
<p>We can then work gradually upwards through the statistics curriculum. Many years from now, I would love to be exploring the cognitive tasks involved in open-ended data analysis tasks such as regression reports and consulting projects, since open-ended analysis is the quintessential expert skill requiring “statistical thinking”, practice, and experience. Perhaps, with the aid of <a href="http://www.stat.cmu.edu/isle/">technological tools</a>, think-aloud interviews, and careful experiments, we can begin to see how experts approach data analysis and help guide our students to think more like experts.</p>
</section>
<section id="acknowledgments" class="level2">
<h2>Acknowledgments</h2>
<p>Carnegie Mellon University’s GSA/Provost GuSH Grant funding was used to support portions of this project. Many thanks to all the students who participated in interviews and assessments, making this research possible. Thanks also to Joel Greenhouse and Nynke Niezink for sharing their experiences teaching mathematical statistics, and to David Gerritsen for a tutorial on conducting think-aloud interviews.</p>
</section>
<section class="footnotes">
<hr />
<ol>
<li id="fn1"><p>R. DelMas, J. Garfield, A. Ooms, and B. Chance, “Assessing students’ conceptual understanding after a first course in statistics,” <em>Statistics Education Research Journal</em>, vol. 6, pp. 28–58, November 2007.<a href="#fnref1" class="footnote-back">↩</a></p></li>
<li id="fn2"><p>B. Chance, J. Wong, and N. Tintle, “<a href="https://doi.org/10.1080/10691898.2016.1223529">Student performance in curricula centered on simulation-based inference: A preliminary report</a>,” <em>Journal of Statistics Education</em>, vol. 24, no. 3, pp. 114–126, 2016.<a href="#fnref2" class="footnote-back">↩</a></p></li>
<li id="fn3"><p>T. J. Pfaff and A. Weinberg, “<a href="https://doi.org/10.1080/10691898.2009.11889536">Do Hands-on Activities Increase Student Understanding?: A Case Study</a>,” <em>Journal of Statistics Education</em>, vol. 17, no. 3, 2009.<a href="#fnref3" class="footnote-back">↩</a></p></li>
<li id="fn4"><p>W. K. Adams and C. E. Wieman, “<a href="https://doi.org/10.1080/09500693.2010.512369">Development and validation of instruments to measure learning of expert-like thinking</a>,” <em>International Journal of Science Education</em>, vol. 33, no. 9, pp. 1289–1312, 2011.<a href="#fnref4" class="footnote-back">↩</a></p></li>
<li id="fn5"><p>K. A. Ericsson and H. Simon, “<a href="https://doi.org/10.1037%2F0033-295X.87.3.215">Verbal reports as data</a>”. <em>Psychological Review</em>, vol. 87, no. 3, pp. 215–251, 1980.</p>
<p>K. A. Ericsson and H. Simon (1993). <em>Protocol Analysis: Verbal Reports as Data</em> (2nd ed.). Boston: MIT Press.<a href="#fnref5" class="footnote-back">↩</a></p></li>
<li id="fn6"><p>The evidence is not yet conclusive on whether vitamin C can prevent or treat the common cold, surprisingly enough: Hemilä H, Chalker E. “<a href="https://doi.org/10.1002/14651858.CD000980.pub4">Vitamin C for preventing and treating the common cold</a>”. <em>Cochrane Database of Systematic Reviews</em> 2013, Issue 1. Art. No.: CD000980.<a href="#fnref6" class="footnote-back">↩</a></p></li>
<li id="fn7"><p>I. A. Halloun and D. Hestenes, “<a href="https://doi.org/10.1119/1.14030">The initial knowledge state of college physics students</a>,” <em>American Journal of Physics</em> vol. 53, no. 11, pp. 1043-1048, 1985.</p>
<p>J. Clement, “<a href="https://doi.org/10.1119/1.12989">Students’ preconceptions in introductory mechanics</a>,” <em>American Journal of Physics</em> vol. 50, no. 1, pp. 66-71, 1982.<a href="#fnref7" class="footnote-back">↩</a></p></li>
<li id="fn8"><p>R. R. Hake, “<a href="https://doi.org/10.1119/1.18809">Interactive-engagement versus traditional methods: A six-thousand-student survey of mechanics test data for introductory physics courses</a>,” <em>American Journal of Physics</em>, vol. 66, pp. 64–74, 1998.</p>
<p>C. Crouch, A. P. Fagen, J. P. Callan, and E. Mazur, “<a href="https://doi.org/10.1119/1.1707018">Classroom demonstrations: Learning tools or entertainment?</a>,” <em>American Journal of Physics</em>, vol. 72, pp. 835–838, 2004.</p>
<p>C. Crouch and E. Mazur, “<a href="https://doi.org/10.1119/1.1374249">Peer instruction: Ten years of experience and results</a>,” <em>American Journal of Physics</em>, vol. 69, pp. 970–977, 2001.<a href="#fnref8" class="footnote-back">↩</a></p></li>
<li id="fn9"><p>D. F. Feldon, “<a href="https://doi.org/10.1007/s10648-006-9009-0">The implications of research on expertise for curriculum and pedagogy</a>,” <em>Educational Psychology Review</em>, vol. 19, pp. 91–110, 2007.</p>
<p>C. Tofel-Grehl and D. F. Feldon, “<a href="https://doi.org/10.1177/1555343412474821">Cognitive task analysis–based training</a>,” <em>Journal of Cognitive Engineering and Decision Making</em>, vol. 7, pp. 293–304, 2013.<a href="#fnref9" class="footnote-back">↩</a></p></li>
<li id="fn10"><p>M. Lovett, “A collaborative convergence on studying reasoning processes: A case study in statistics,” in <em>Cognition and Instruction: Twenty-five Years of Progress</em> (S. M. Carver and D. Klahr, eds.), ch. 11, Psychology Press, 2001.<a href="#fnref10" class="footnote-back">↩</a></p></li>
<li id="fn11"><p>Koedinger, K. R., &amp; McLaughlin, E. A. (2016). “<a href="http://www.educationaldatamining.org/EDM2016/proceedings/paper_152.pdf">Closing the loop with quantitative cognitive task analysis</a>”. In <em>Proceedings of the 9th International Conference on Educational Data Mining</em> (pp. 412–417).<a href="#fnref11" class="footnote-back">↩</a></p></li>
</ol>
</section>]]></description>
    <pubDate>Thu, 06 Feb 2020 00:00:00 UT</pubDate>
    <guid>https://www.refsmmat.com/posts/2020-02-06-cognitive-science-learning-statistics.html</guid>
    <dc:creator>Alex Reinhart</dc:creator>
</item>
<item>
    <title>Books of 2017</title>
    <link>https://www.refsmmat.com/posts/2018-02-02-books-of-2017.html</link>
    <description><![CDATA[<p>Picking up from <a href="2017-02-26-books-of-2016.html">last year</a>, here are a few brief reviews of particularly interesting books I read in 2017, selected from a total of 45.</p>
<section id="the-age-of-american-unreason-by-susan-jacoby" class="level2">
<h2><em>The Age of American Unreason</em>, by Susan Jacoby</h2>
<p>Tries to be the intellectual successor of Hofstadter’s <em>Anti-Intellectualism in American Life</em>, but doesn’t really succeed. Jacoby roughly moves chronologically, jumping from early America to the late 1800s (and the pseudoscience of social Darwinism), through the days of intellectual Marxism and communism, to the middlebrow culture of the 50s and the rebellion of the 60s, and on to a series of chapters on recent decades.</p>
<p>I found chapter 5, on “middlebrow culture”, particularly interesting. Not having lived through the 50s, I can’t judge the representativeness of Jacoby’s examples, but she portrays a nation of citizens aspiring to learn and approach higher culture, manifested through wide sales of encyclopedias, book-of-the-month clubs, public lecture series, thoroughly researched historical novels (as opposed to anything by <a href="http://itre.cis.upenn.edu/~myl/languagelog/archives/000844.html">Dan Brown</a>), and various popular publishing enterprises reprinting classics and outlines of history. Apparently – and I wish good statistics were available – middlebrow culture was popular and people widely aspired to reading more “sophisticated” works, even if they did so via book clubs featuring a few rungs from the top of literary sophistication.</p>
<p>I see almost no analog of this now. Typical reading for self-improvement involves pop science or psychology works which take a few core ideas and pad them out to three hundred pages, rather than aspirational reading of “serious” (whatever that means) novels. I don’t know anyone (apart from my father) who reads history for the pleasure of understanding. There are, of course, people who take pleasure in the feeling of superiority derived from highbrow culture, but they’re the kind of people featured on <a href="https://www.reddit.com/r/iamverysmart/">/r/iamverysmart</a>; most people don’t see the point of middlebrow aspirations now. Popular respect goes to those with great DIY or technical skills.</p>
<p>I giggled a bit in the final chapter, “Public Life: Defining Dumbness Downward”, as Jacoby commented on Bush’s clear non-intellectualism and expressed hope that the next crop of politicians – the book was published during the 2008 election season, apparently – seemed more willing to read detailed briefings and background material. Alas, Donald J. Trump has arrived.</p>
<p>Some of the pleasure in reading this book derives from looking down on the parts of culture deemed inferior. Jacoby is on the shakiest foundation here, generally making implicit assumptions about what kinds of culture are superior and what people should aspire to read and watch, assuming her audience agrees with her choice of culture instead of justifying it in any depth. I particularly enjoyed one part where she quoted a music critic writing</p>
<blockquote>
<p>Lately I’ve been wondering why, as a more than casual Beatles fan, I’m not interested in note-perfect covers by Beatles tribute bands, even though, as a classical music critic, I happily spend my nights listening to re-creations—covers, in a way—of Beethoven symphonies and Haydn string quartets. What, when it comes down to it, is the difference?</p>
</blockquote>
<p>The critic goes on to discuss the difference between covers and classical performances. Jacoby, on the other hand, retorts:</p>
<blockquote>
<p>What, when it comes down to it, is the difference? It is the difference between Beethoven’s Ninth Symphony (or any Beethoven symphony) and any song or collection of songs by the Beatles. The difference is the infinitely greater emotional richness, technical complexity, and beauty of Beethoven. I too am a Beatles fan, but, let’s face it, if you’ve heard one version of “Sgt. Pepper’s Lonely Hearts Club Band,” you’ve pretty much heard them all.</p>
</blockquote>
<p>Way to miss the point! Perhaps there’s a genuine retort to the critic in there somewhere – pop songs aren’t complex enough for covers to have room to differentiate, which any listener to Postmodern Jukebox knows is not true – but mostly Jacoby wants to complain about how inferior modern music is, and assumes we share her feelings. It’s fun snootiness if you agree, but since I’m listening to Steve Martin playing bluegrass banjo right now, maybe I don’t quite agree with her.</p>
<p>Now, maybe there <em>is</em> a good argument she could have made. In classical music, with the score already written, the focus is on the musicianship and interpretation, and we enjoy a performance which demonstrates great skill or puts a piece in a new light. In popular music, the musicianship is often not important at all – the band members aren’t even named, just the celebrity doing the singing. The focus is on the overall sound, the lyrics, and the celebrity doing the singing, and on marketing them. Covers are interesting when a new celebrity does something different with the lyrics.</p>
<p>That would fit with Jacoby’s thesis about the commercialization of music, but she’s too focused on scorn to think of the point. This distinguishes her from Hofstadter, who tried to trace the history of anti-intellectualism instead of rendering value judgments. I may agree with Jacoby’s judgment that intellectual curiosity and education are necessary for good citizenship, but she could have tempered her criticism of specific parts of culture (or buttressed it with argument instead of ridicule).</p>
</section>
<section id="the-debate-on-the-constitution-part-one" class="level2">
<h2><em>The Debate on the Constitution, Part One</em></h2>
<p>A fascinating compilation by the <a href="https://loa.org/">Library of America</a> of pamphlets, letters, editorials, and speeches made in the months after the Constitutional Convention’s proposal of a new constitution for the United States.</p>
<p>The opposition to the Constitution was louder than I had realized, sometimes bordering on hysterical: claims that ratification of the Constitution would amount to slavery, monarchy, or aristocracy; that amendment would be impossible and end only in civil war or rebellion; that state governments would be subsumed by the federal government and soon wither to empty shells; or that a federal government would be so ruinously expensive as to be impossible.</p>
<p>Some of the objections seemed to be founded on very little. The insistence that Congress would quickly become an aristocracy, defeating the checks and balances inherent in its separation into two Houses by colluding to deprive the people of their liberties, is easily answered by noting that the House of Representatives can be entirely voted out in just two years. A fear that Congress’s authority to regulate the election of representatives would lead to elections being held, say, at the least convenient place in the state, so as to stack the elections, was never realized as far as I am aware. The claim that federal taxes would subsume state taxes and render the states incapable of raising revenue seems hard to reconcile with the role of the Senate as representatives of the state legislatures.</p>
<p>A lot of time was spent on the vastness of the United States and the difficulty of travel across them: anyone seeking relief in a federal court may have to travel hundreds of miles, making justice impossible to find, and some doubted the possibility of electing a President when finding a man known to everyone in the States would be so difficult. (George Washington excepted, of course.) Two hundred years later, with air travel and interstate highways, these concerns seem quaint.</p>
<p>Other objections make clear how much of our system depends on norms of behavior rather than law. Many writers insisted the Congress would never approve Constitutional amendments which limit its power, no matter how necessary; the subsequent passage of the Bill of Rights showed this to be false. Others insisted that nobody would obey the federal government without threat of force, making the internal use of a vast standing army inevitable, eliminating liberty; legal action proved to be sufficient instead. Supporters of the Constitution argued that the personal honor and integrity of the great men selected to the Senate or voted to the House would restrain them from actions which would impugn their character; perhaps too optimistic today.</p>
<p>Several writers seemed concerned by the prospect of bribery – of representatives, or of those who elect them. The electoral college meets on the same day in every state to make it difficult to coordinate simultaneous bribery of every elector; some defend the cap on the number of representatives by arguing that very small districts would make it easy for representatives to re-elect themselves through bribery of the voters. Modern electoral campaigns, and their enormous expenses, don’t seem to have been anticipated at all, and the influence of campaign money on politics is not recognized at all – I would at least consider it a possible reason to make terms longer, to reduce the time spent on reelection, but many argued terms are already too long and preferred annual reelection so tyrannical representatives could be immediately voted out.</p>
<p>It’s also interesting how little of the modern role of the federal government was anticipated by the founders. Healthcare is an obvious example given current political debates, but also telecommunications regulation (obviously), agriculture, scientific laboratories and grants, conservation, weather, emergency response (beyond a simple militia), massive infrastructure and transportation projects, international agencies, workplace regulations, environmental regulation, intelligence agencies… the role of the federal government is vastly larger than the simple commerce and international affairs imagined by the founders, and yet the states continue to have independent existences and maintain clear sovereignty.</p>
<p>The language of the time is also fascinating to read. I admit that when I first glanced at the Federalist Papers years ago, I decided not to read them because of their long, winding sentences and archaic vocabulary. With a bit of practice that is not an obstacle. But standards of spelling, punctuation, and style have clearly changed a great deal: dashes, colons, and semicolons are often used in different roles than we now accept, paragraphs often stretch for a page or more and contain multiple independent ideas, sentences frequently feature many complicated clauses stitched together with copious commas, and variant spellings like “shew” and “chuse” are in abundance.</p>
</section>
<section id="the-attention-merchants-by-tim-wu" class="level2">
<h2><em>The Attention Merchants</em>, by Tim Wu</h2>
<p>A breezy history of “attention merchants”: those who sell attention as a business. Starts talking about the earliest advertisers – patent medicine hawkers – and works through early radio, television, the Internet, and finally mobile devices, showing how our attention has been sliced and diced into ever-smaller fragments to be sold.</p>
<p>Early patent medicine advertisements were a new concept and, of course, appeared mostly in print. Radio surprised its early developers when people willingly set aside time each day to listen to their favorite radio shows. Television began to command the power to have millions of Americans watch shows simultaneously. And at each step, attention was sliced into smaller bits to be sold: first entire programs were sponsored on radio and TV, then the “magazine” format with ads splitting up programs, to the banner ads of the Internet and intrusive banners on phones which only grab us for a few seconds at a time.</p>
<p>The history was fast and not greatly detailed, though enjoyable. This was more interesting just for the idea of being aware of our own attention and what demands are made of it, and not allowing outside forces to exert so much control over it without consent.</p>
</section>
<section id="weapons-of-math-destruction-by-cathy-oneil" class="level2">
<h2><em>Weapons of Math Destruction</em>, by Cathy O’Neil</h2>
<p>I found this to be a frustrating book to read. O’Neil has a very important thesis: that unaccountable algorithms used to make decisions about people, whether for employment screening, bail decisions, or insurance quotes, are often wildly inaccurate and perpetuate bias against the poor, disabled, or historically disadvantaged. By turning a formerly human decision into one made by an algorithm, companies can appear more objective even when they make it impossible for those rejected by the algorithm to seek an explanation or correct faulty data.</p>
<p>But the development of this thesis is poor. O’Neil goes through several fields, quoting examples from each: recidivism prediction software, teacher evaluations from standardized tests, credit scores, online ad targeting, and many others. But examples are only examined in superficial detail, and in ways that do not suggest O’Neil is terribly familiar with statistics or machine learning. In one segment, for example, on a company developing ad targeting models using anonymous cell phone data, she mentions how the algorithm picked out patterns without any guidance, perhaps noticing how much time people spend on roads starting with the letter J. I know of no algorithm or feature selection method that would be so open-ended, or so stupid.</p>
<p>Or take this discussion of ad effectiveness:</p>
<blockquote>
<p>The data scientists start off with a Bayesian approach, which in statistics is pretty close to plain vanilla. The point of Bayesian analysis is to rank the variables with the most impact on the desired outcome. Search advertising, TV, billboards, and other promotions would be measured as a function of their effectiveness per dollar. Each develops a different probability, which is expressed as a value, or a weight. (page 74)</p>
</blockquote>
<p>This paragraph is deeply confused. What does Bayesian analysis have to do with ranking variables? Isn’t this just a classification problem? Are we talking about naive Bayes? How is expressiveness per dollar a probability? Either O’Neil does not understand the methods, or she has simplified the discussion beyond all recognition.</p>
<p>I do not mean to argue that she should have quoted mathematics or given a cogent and accessible description of support vector machines. But simplification should clarify, not obscure.</p>
<p>In other examples I left frustrated because O’Neil glossed over interesting details. One section talked about a project at St George’s Hospital Medical School in the 1970s, using a computer to screen applicants to the medical school to reduce the workload of the humans reviewing the paperwork. O’Neil says the computer was trained to use information from prior applications and ended up perpetuating human biases, like biases against foreign-born applicants or against women. But all I wanted to know was how a computer in the 70s was doing machine learning, and what kind of method it used. Did it really “learn” to perpetuate bias, or was computing sufficiently limited that it has to be directly programmed to do so? I can’t imagine anything more complicated than regression being practical then, and certainly it was not doing deep learning on applicant files.</p>
<p>And then there were the small errors:</p>
<blockquote>
<p>In previous generations, those in the know were careful to organize the résumé items clearly and consistently, type them on a quality computer, like an IBM Selectric, and print them on paper with a high rag content. (page 114)</p>
</blockquote>
<p>Uh. A quality <a href="https://en.wikipedia.org/wiki/IBM_Selectric_typewriter">IBM Selectric computer</a>?</p>
<p>I realize I am not the intended audience of this book, since I have the mathematical and statistical training to understand many of the “weapons of math destruction” discussed in the book. I would have liked more depth, more clarity, and more thorough analysis of the issues (and related topics, like the Fourth Amendment connections to predictive policing and Europe’s approach to privacy law), but perhaps O’Neil judged that additional depth would have been harmful. Maybe I just want a different book than she wanted to write. But I think there’s room for a better account of the issues than O’Neil provides.</p>
</section>
<section id="do-guns-make-us-free-by-firmin-debrabander" class="level2">
<h2><em>Do Guns Make Us Free?</em>, by Firmin DeBrabander</h2>
<p>An interesting argument, attempting to show that rather than serving as our last line of defense against tyranny, guns actually make us less free.</p>
<p>First, one inevitable complaint. DeBrabander criticizes gun owners who make fun of gun critics who don’t know much about guns, as though the only people qualified to participate in the gun debate are those who own guns (and hence only people on one side of the debate). But later he shows why gun knowledge would be useful for critics. In one passage, he notes that after open carry laws passed in many states, purchases of larger handguns increased. Why, he asks, did gun owners want bigger handguns? Why were the smaller, more easily concealed handguns not good enough for open carry as well? The implication is that gun owners wanted to wave around bigger and more powerful weapons for no good reason; had DeBrabander talked to gun owners, he’d know that small concealed handguns can be hard to control and unpleasant to shoot (their light weight makes the recoil more potent), while full-size handguns are more ergonomic.</p>
<p>But that is a minor point. DeBrabander’s main arguments, neatly separated by chapter:</p>
<ol>
<li><p>The NRA, and gun advocates more generally, have encouraged a “Culture of Fear”. The NRA talks about “lunatics” roving the streets, madmen who will burst into your house to kill you for no reason, and even riots and looting. Mental illness is out of control and untreated psychotics rove the streets. You should be afraid, and you should defend yourself.</p>
<p>But the narrative is false. Violent crime has fallen dramatically, and we live in one of the most peaceful times in modern history. (And history in general, if you believe Steven Pinker’s <em>The Better Angels of Our Nature</em>.) The mentally ill are not more likely to commit violent crime than the general population. Most acts of violence are not committed by random unhinged strangers. And most acts of violence occur between poor, urban minorities, not the kinds of people who own lots of legal guns: middle-class suburban whites.</p>
<p>This fear makes gun owners more likely to perceive ordinary situations as lethal threats to themselves, leading to episodes such as the guy who shot someone in a movie theater during an argument and claimed self-defense. (On gun forums you tend to see stories of how, say, the vigilant narrator was at a gas station and noticed an undesirable acting suspiciously while walking toward his car, and successfully deterred the obvious impending violence by showing his weapon.)</p></li>
<li><p>Guns, it is claimed, are also protections against encroaching tyranny. We grant power to the government as part of the social contract; should it violate our trust and abuse that power, we must have a remedy. But, according to DeBrabander, this conflicts with the justifications for Stand Your Ground laws, which allow gun owners to take justice into their own hands. If guns are meant to uphold the social contract which grants a government exclusive use of force to ensure order, taking the power away from warring individuals, why Stand Your Ground laws implicitly deny the government’s exclusive use of force and assume we are back in the state of nature, when every man must fend for himself?</p>
<p>DeBrabander also makes a silly suggestion here about Stand Your Ground laws being misused by criminals, who could, say, murder someone on the street to steal his wallet, then claim they felt threatened and had to stand their ground. Until this actually happens, I’ll put it in the category of “weird hypothetical things that no criminal would actually bother with”.</p>
<p>A better point follows. Would gun owners really be able to fend off a tyrannical United States government? Some point to Vietnam, noting that guerrilla warfare worked very well, but (a) the US military is phenomenally overpowered and (b) Vietnam paid incredible human cost for its successful guerrilla campaign, which was by no means easy.</p></li>
<li><p>Here’s where the argument gets more interesting. Why, DeBrabander asks, do politicians allow guns when they are clearly a threat to their authority? If politicians are as corrupt and power-hungry as the NRA would have you believe, surely they’d scramble to push gun regulations, NRA or not.</p>
<p>DeBrabander makes a detour through Machiavelli to answer this, but the point is actually simple. Tyranny no longer needs violence. Politicians can allow us to have guns because politicians can exert power in more effective, more subtle ways. DeBrabander, though without citing Solove as far as I can tell, portrays mass surveillance and Fourth Amendment violations as greater threats to liberty than gun regulation; the erosion of privacy allows subtle exertion of power that makes dissent less likely, for fear that someone may be watching. But the people advocating for civil liberties are most often liberal groups like the ACLU, while gun advocates are all for the government being granted sweeping powers when they’re supposed to be used against terrorists.</p></li>
<li><p>Guns are a threat to democracy. Their threat of violence silences discussion and undermines the rule of law. If we are to argue that guns are necessary to prevent tyranny, we are saying that unaccountable unelected gun owners should overthrow democratically elected governments when they overstep some ill-defined line of tyranny.</p>
<p>To quote DeBrabander, “the gun rights movement has already abandoned the democratic project: it has decided that portions of society cannot be negotiated with, and government can be negotiated with only by threat of force.”</p></li>
<li><p>Finally, a somewhat unfocused chapter on the meaning of power. Pro-gun arguments undermine the rule of law by arguing that the government is ineffective and untrustworthy, ironically creating the dangerous lawless world that gun owners fear. Threats of violence against government are more likely to harden the government and make it retaliate in kind; organized nonviolent protests are a more powerful mechanism to effect political change. And finally, a suggestion that the same demographic that buys guns has also been the biggest political loser in recent decades: blue-collar white men, with no wage growth, disappearing job opportunities, vanishing pensions, and uncaring politicians. Perhaps they think guns will give them the power they are missing.</p></li>
</ol>
<p>Overall an interesting read, though I think it could have been more powerfully and clearly written. Some of the silly speculation, such as criminals taking advantage of Stand Your Ground laws, invites easy rebuttal by gun rights advocates, and a lot of the book quotes extensively from philosophers and journalists instead of developing its own coherent narrative. DeBrabander needed a stronger editor, more knowledge of the gun world, and more time to simplify and streamline his arguments.</p>
</section>]]></description>
    <pubDate>Fri, 02 Feb 2018 00:00:00 UT</pubDate>
    <guid>https://www.refsmmat.com/posts/2018-02-02-books-of-2017.html</guid>
    <dc:creator>Alex Reinhart</dc:creator>
</item>
<item>
    <title>Books of 2016</title>
    <link>https://www.refsmmat.com/posts/2017-02-26-books-of-2016.html</link>
    <description><![CDATA[<p>As part of my <a href="/notebooks/">obsession with tracking things I’ve read</a>, I keep a file with every book I’ve read since 2012(ish). I write myself brief reviews or commentaries for particularly interesting books, so I remember what they’re about in a few years. Here are some of the best of 2016, selected from a total of 32.</p>
<section id="the-day-of-the-jackal-by-frederick-forsyth" class="level2">
<h2><em>The Day of the Jackal</em>, by Frederick Forsyth</h2>
<p>This is what I needed after Tom Clancy: a sharp, well-written thriller with plenty of plausible detail. I’ll have to start reading Forsyth’s other work to see if he fell into Clancy’s trap of modernizing his work until it sucks.</p>
<p>I do wonder – the book is set during de Gaulle’s presidency in France in the 60s, so all the spycraft is based on disguises, falsified passports, shadowy meetings in semi-public places, etc. A modern version would involve the OAS exchanging encrypted text messages and emails, hiding their plans with steganography, and ditching burner phones, while the police use big electronic surveillance systems instead of canvassing hotels for occupancy records. Would the modern version come across as a nerd novel? Too much tech fanciness to enjoy the plot? The original spycraft just makes the assassin seem sophisticated and smart, not nerdy or technologically advanced – it’s a battle of wits between assassin and police, not just who has the biggest electronic surveillance budget and the fanciest apps.</p>
</section>
<section id="the-space-merchants-by-frederik-pohl-and-c.-m.-kornbluth" class="level2">
<h2><em>The Space Merchants</em>, by Frederik Pohl and C. M. Kornbluth</h2>
<p>An interesting world-building exercise: it’s The Future, and the world is controlled by large corporations and advertising agencies, with governments largely subservient to them. (The House of Representatives consists of representatives to specific companies, not districts.) The world is vastly overpopulated, with everyone living in cramped apartments with fold-up beds and saltwater taps for bathing. Consumption is the primary good: the more you consume, the more you boost the economy, allowing large companies to thrive and pay for advertising to make you consume even more. Addictive substances are added to coffee and sodas. Many workers start in indentured servitude in systems engineered to create more debts to their employers, like the old mining towns and company stores. Companies settle disputes with physical violence and private security contractors.</p>
<p>For a book written in 1953, it’s surprisingly prescient. Growth and consumption are still our highest priorities. Instead of adding addictive substances to our coffee, ad companies try to learn everything about us, using megabytes of Javascript tracking code on every webpage to target advertisements directly to our preferences. They aren’t nearly as good as the advertisers in the novel yet, who apparently have incredible power over the subconscious minds of consumers, but they would happily use the power if they had it.</p>
<p>The plot itself didn’t grip me much – Conservationists don’t want the planned colonization of Venus to continue under the control of an ad agency – and the writing was good but not amazing. I just enjoyed the parallels with today’s economy, where <a href="http://idlewords.com/2015/11/the_advertising_bubble.htm">questioning</a> <a href="http://idlewords.com/talks/what_happens_next_will_amaze_you.htm">advertising</a> is edgy, questioning consumerism is only acceptable if you continue buying useless gadgets anyway, and presidential candidates routinely advocate for the reckless use of natural resources for the benefit of our economy.</p>
<p>Makes you want to spend the rest of the evening with another lovely hardcover book, instead of Twitter, Facebook, and YouTube.</p>
</section>
<section id="double-star-by-robert-heinlein" class="level2">
<h2><em>Double Star</em>, by Robert Heinlein</h2>
<p>Fun and interesting. An actor is hired to double for the solar system’s most prominent politician to avoid a political crisis, and ends up far deeper into the job than he anticipated. Turns out he’s a better Bonforte than Bonforte himself.</p>
<p>Doesn’t attempt to be nearly as deep or poetic as Sturgeon’s <em>More than Human</em>, but it’s a fun story, blemished only by some poor characterization (the only woman, Penny, is an emotional wreck who has to be repeatedly told to pull herself together) and his tendency to string along the plot by introducing one more crisis for the actor to manage. There’s no real ending either. But it was fun while it lasted.</p>
<p>It’s always fun to see our limited conception of the future. <em>Double Star</em> is set in a future where nuclear-powered spacecraft can travel at 2 <em>g</em> acceleration to Mars and back, but government records are kept on microfilm in a giant archive on the Moon. More subtly, they mention “scramblers” for video and audio calls which can undoubtedly be broken – actual secure cryptography wasn’t foreseen either.</p>
</section>
<section id="the-public-domain-by-james-doyle" class="level2">
<h2><em>The Public Domain</em>, by James Doyle</h2>
<p>See my <a href="/posts/2016-02-17-public-domain.html">full review</a>.</p>
</section>
<section id="the-closing-of-the-western-mind-by-charles-freeman" class="level2">
<h2><em>The Closing of the Western Mind</em>, by Charles Freeman</h2>
<p>Despite the title, this is not a Sam Harris- or Richard Dawkins-style polemic against Christianity. (Not that I have read books by either of those people.) Instead, this is a detailed accounting of the early development of Christian theology and its roots in (and separation from) Greek philosophy. Freeman details how the Greeks developed a rich tradition of rational thought and empirical investigation, exemplified by Aristotle, but early Christianity leaned more Platonic, favoring the idea that there are pure truths about God which cannot be discovered from empirical evidence alone.</p>
<p>Once the Roman Empire adopted Christianity and made it the state religion, with patronage and tax benefits and all the related benefits, the definition of “orthodox” Christianity quickly became a serious issue, and the many disparate theologies that had arisen from the contradictory and incomplete mass of scriptures, Gospels, and epistles had to be formed into a single creed. This led to centuries of church infighting, imperial interventions and meddling, and political intrigues – bishops were scheming to depose each other, riots broke out over obscure details of the theology of the Trinity, and heretics were exiled outright.</p>
<p>Gradually the Church (at least the Western church) settled on many of the details, but rational thought and disagreement were stifled to protect the consensus. Church leaders openly denigrated pagan philosophers as foolish for attempting to understand the world God created. It became more important to be orthodox than to think freely, for fear of sanction, and as the Church became more Latin-speaking, the works of the Greek philosophers and theologians faded away.</p>
<p>Freeman spends most of his time on a straightforward account of the theological disputes rending the church, and the various imperial interventions to resolve them, rather than hammering home the thesis again and again. This means the book is interesting as a history as well – it covers the basic history of the early church without boring me like <em>Christianity: The First Three Thousand Years</em> did, though I admit to losing track of all the sects and their opinions on the Trinity and Christ’s divinity.</p>
</section>
<section id="the-rise-and-fall-of-american-growth-by-robert-j.-gordon" class="level2">
<h2><em>The Rise and Fall of American Growth</em>, by Robert J. Gordon</h2>
<p>I have mixed feelings about this book. The first part of the book, detailing the enormous growth in the American standard of living beginning in 1870, is fascinating: we often talk about how life was so simple and calm in the old days, but don’t mention needing to carry in buckets of water and firewood just to have a hot bath, rampant infectious disease, monotonous diets, homemade clothing, slow and dangerous travel to anywhere more than a few miles away, and everything else that comes with a “simple” life. I learned quite a lot about life in America around 1900.</p>
<p>On the other hand, much of this knowledge came through Gordon’s detailed descriptions of charts and graphs, rather than through evocative prose. Much time is spent discussing inflation-adjusted indices and productivity ratios and quality-adjusted life expectancies, even when the core points would be well-supported with much less detail.</p>
<p>But anyway. The second portion of the book describes a claimed slowdown in quality-of-life improvements after 1970: a frequent refrain, after each pre-1970 improvement, is that it “could have only happened once”. Once you’ve provided everyone with clean running water, what can you do that would bring that magnitude of benefit again? You can’t re-eliminate cholera.</p>
<p>Gordon reviews the areas of American life that <em>have</em> dramatically improved since 1970, mostly focusing on communications and computers. Yes, we have the Internet, smartphones, a Jeopardy-playing computer program, and plenty else. But these haven’t dramatically improved our lives, argues Gordon, and can’t provide the same benefits and growth as, say, not dying from typhoid fever. And computers and automation are eliminating much of the core of middle-class jobs: jobs requiring moderate but routine intellectual or manual labor, like assembly-line manufacturing or routine bookkeeping. Instead we’re left with high-end non-automated jobs (famous musician, professional lawyer or doctor, engineer, etc.) and low-end manual labor that can’t be entirely automated.</p>
<p>I can buy this argument. Short of a Singularity event which eliminates death, we can’t replicate the same health gains we made from 1870-1970; short of teleportation or hypersonic airplanes, we can’t beat the 20th century for transportation improvement; short of ubiquitous high-speed Amazon drones, we won’t replicate the gain in convenience and variety brought by supermarkets instead of small general stores. But I suspect we are not very good at predicting the impact of modern inventions – 3D printing, ubiquitous machine learning, networked everything – on the quality of life.<a href="#fn1" class="footnote-ref" id="fnref1"><sup>1</sup></a> There is less room for gains, because so many have been made, but hindered by our liminted imaginations, we do not see where gains can be made.</p>
<p>Gordon then offers an analysis of what can be done to improve growth. Some of this – reduce government regulation, eliminate some patent and copyright barriers, reduce inequality – seems straightforward, but I am in no way qualified to understand the economic implications. I will reserve judgment. I was somewhat disappointed that the recommendations were not more detailed or accompanied by evidence that they’d work – say, comparisons with European countries with different regulatory regimes, or between states introducing different policies. But fixing American growth is surely an entire book on its own, so I can’t blame Gordon for not spending more time on the topic.</p>
</section>
<section id="tinker-tailor-soldier-spy-by-john-le-carré" class="level2">
<h2><em>Tinker Tailor Soldier Spy</em>, by John le Carré</h2>
<p>This is my second reading of this book, after reading it last in 2012 and seeing the movie in 2011 and again earlier this year. It finally all made sense. I finally could keep track of all the characters, by remembering their faces from the movie, and I could finally make sense of the plot and Smiley’s schemes. A great novel but one that requires careful reading. I should move on to <em>The Honorable Schoolboy</em> and <em>Smiley’s People</em>.</p>
<p>As with <em>The Day of the Jackal</em>, this book makes me wonder if it’s possible to set an engaging spy thriller in modern times. It makes me think of Mark Kac’s old explanation of genius:</p>
<blockquote>
<p>There are two kinds of geniuses: the ‘ordinary’ and the ‘magicians.’ An ordinary genius is a fellow whom you and I would be just as good as, if we were only many times better. There is no mystery as to how his mind works. Once we understand what they’ve done, we feel certain that we, too, could have done it. It is different with the magicians.</p>
</blockquote>
<p>(He then went on to say that Feynman was “magician of the highest caliber”.)</p>
<p>Good mysteries and thrillers often involve the ‘ordinary’ genius, Smiley being an exemplar. Inspector Lebel of <em>The Day of the Jackal</em> was another example, as is Jack Ryan of the Clancyverse. But any modern thriller I see – usually in movie form, because I haven’t found an author I like – tends to lean heavily on technology (see recent Bond movies, for example), and technology ends up being a technobabble <em>deus ex machina</em>. Technicians are magicians. (Possibly because many authors are not technical experts, as evidenced by Dan Brown’s <em>Digital Fortress</em>. I wonder if a digital native would be able to craft a mystery story centered on technology and accessible to other digital natives. A nerd’s novel, say.)</p>
</section>
<section id="on-paper-by-nicholas-basbanes" class="level2">
<h2><em>On Paper</em>, by Nicholas Basbanes</h2>
<p>This is an interesting book, for its form as much as its content. The modern trend seems to be for nonfiction books to be framed around the author’s journey to find out about the subject of the book—read any Mary Roach book, for example, and you’ll hear zany stories of the scientists and colorful characters she meets as she does her research for the book. Some books take this far enough that there’s very little in the way of actual content.</p>
<p>Basbanes, on the other hand, is immensely knowledgeable, and fits a few paragraphs of narrative around a wealth of interesting material on all manner of topics related to paper: Chinese and Japanese papermaking, the use of paper in intelligence work, the paper that fell from the World Trade Center during its destruction, paper records of early American history, and much more in between. This is a book that will make you want to buy some nice cotton bond paper for no good reason.</p>
</section>
<section class="footnotes">
<hr />
<ol>
<li id="fn1"><p>Ten or twenty years ago, we probably didn’t expect that the greatest application of “big data” and machine learning would be in advertising. I guess that says something about the kind of world we live in.<a href="#fnref1" class="footnote-back">↩</a></p></li>
</ol>
</section>]]></description>
    <pubDate>Sun, 26 Feb 2017 00:00:00 UT</pubDate>
    <guid>https://www.refsmmat.com/posts/2017-02-26-books-of-2016.html</guid>
    <dc:creator>Alex Reinhart</dc:creator>
</item>
<item>
    <title>R's Lists and its Detestable Dearth of Data-Structures</title>
    <link>https://www.refsmmat.com/posts/2016-09-12-r-lists.html</link>
    <description><![CDATA[<p><em>Update, September 2018:</em> The <em>R Journal</em> recently published an interesting review of the state of data structures and collections in R: Timothy Barry (2018), “<a href="https://journal.r-project.org/archive/2018/RJ-2018-037/index.html">Collections in R: Review and Proposal</a>”, vol 10 no. 1, pages 455-471.</p>
<p><a href="https://www.r-project.org/">R</a> is the <em>lingua franca</em> of academic statistics. Many papers introducing new statistical methods are accompanied by a package posted on <a href="https://cran.r-project.org/">CRAN</a>, R’s repository of useful packages and tools. Undergraduate programs often teach R and use it throughout their courses, as do most graduate programs—most PhD students I know are implementing their work in R as they do their research. R’s popularity is exploding, and even Microsoft has <a href="https://mran.revolutionanalytics.com/">their own R distribution</a> these days.</p>
<p>But R is an unusual language. It was designed by statisticians for statisticians, and has a number of convenience features—for example, there are no scalars. The number <code>17</code> is just a vector of length one, and the <code>+</code> operator can add arbitrary vectors elementwise by dispatching to fast C code. On the one hand, this means I can write <code>foo + bar</code> for two large vectors and get an efficient sum, but on the other hand, it means <code>1 + 2</code> has to go through the same loop instead of being converted to a fast addition.</p>
<p>There are other curious features of R, like Ross Ihaka’s famous<a href="#fn1" class="footnote-ref" id="fnref1"><sup>1</sup></a> example of a function whose return value <code>x</code> is randomly local or global:</p>
<div class="sourceCode" id="cb1" data-org-language="R"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb1-1" title="1">f &lt;-<span class="st"> </span><span class="cf">function</span>() {</a>
<a class="sourceLine" id="cb1-2" title="2">    <span class="cf">if</span> (<span class="kw">runif</span>(<span class="dv">1</span>) <span class="op">&gt;</span><span class="st"> </span><span class="fl">.5</span>) {</a>
<a class="sourceLine" id="cb1-3" title="3">        x &lt;-<span class="st"> </span><span class="dv">10</span></a>
<a class="sourceLine" id="cb1-4" title="4">    }</a>
<a class="sourceLine" id="cb1-5" title="5">    x</a>
<a class="sourceLine" id="cb1-6" title="6">}</a></code></pre></div>
<p><a href="https://xianblog.wordpress.com/2010/09/13/simply-start-over-and-build-something-better/">Ihaka says</a> “No sensible language would allow this,” and misfeatures like this seriously limit R’s performance by making it difficult to efficiently run R code. (How can an optimizer deal with a variable that is randomly local or global?)</p>
<p>But the performance of a program depends on more than just how quickly the interpreter can execute the instructions. For a program doing vectorized operations on large arrays of numbers, sure, but what about a program that needs different data structures, like sets, graphs, or trees? What about a hash table? Do we have the tools to efficiently store and search data in appropriate data structures?</p>
<section id="lists-lists-lists" class="level2">
<h2>Lists lists lists</h2>
<p>Besides vectors, and their multidimensional generalizations in matrices and arrays, the other core type in R is the list. If we want to build data structures, we’ll have to build them from lists. A list has named fields which can contain arbitrary data—vectors, other lists, strings, functions, and anything else. For example,</p>
<div class="sourceCode" id="cb2" data-org-language="R"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb2-1" title="1">foo &lt;-<span class="st"> </span><span class="kw">list</span>(<span class="dt">walrus=</span><span class="st">&quot;walrus&quot;</span>, <span class="dt">func=</span><span class="cf">function</span>(x) { <span class="dv">-4</span> <span class="op">*</span><span class="st"> </span>x <span class="op">+</span><span class="st"> </span><span class="dv">3</span> },</a>
<a class="sourceLine" id="cb2-2" title="2">            <span class="dt">walden=</span><span class="kw">c</span>(<span class="dv">1</span>, <span class="dv">2</span>, <span class="dv">3</span>, <span class="dv">4</span>, <span class="dv">5</span>))</a>
<a class="sourceLine" id="cb2-3" title="3"></a>
<a class="sourceLine" id="cb2-4" title="4">foo<span class="op">$</span><span class="kw">func</span>(<span class="dv">2</span>)</a>
<a class="sourceLine" id="cb2-5" title="5"><span class="co"># -5</span></a>
<a class="sourceLine" id="cb2-6" title="6"></a>
<a class="sourceLine" id="cb2-7" title="7">foo<span class="op">$</span>walrus</a>
<a class="sourceLine" id="cb2-8" title="8"><span class="co"># &quot;walrus&quot;</span></a></code></pre></div>
<p>Lists are the structures upon which much of R’s other features are built. For example, R’s famed data frames are just lists with one named field per column, and S3 classes (such as the <code>lm</code> objects returned from a linear model fit) are usually just lists with their <code>class</code> attribute set to their class name. Generic functions like <code>predict</code> are implemented by checking the <code>class</code> attribute and passing the list to the appropriate function.</p>
<p>Lists also support numbered entries, and some R functions return lists without any names. We can access named and unnamed entries by their numbers:</p>
<div class="sourceCode" id="cb3" data-org-language="R"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb3-1" title="1">foo[[<span class="dv">3</span>]]</a>
<a class="sourceLine" id="cb3-2" title="2"><span class="co"># [1] 1 2 3 4 5</span></a></code></pre></div>
<p>Lists are the only key-value mapping type provided in base R: there are no dictionaries or associative arrays.<a href="#fn2" class="footnote-ref" id="fnref2"><sup>2</sup></a> Nor are there structure or record types. So you’re encouraged to use lists for everything. Returning a complicated set of results from a model fit? Use a list. Looking up items by their name? Use a list.</p>
<p>It’s great to have such a flexible data structure, but it turns out that lists are a poor foundation to build a language upon. Let’s start with the basic problem: finding elements in a list.</p>
</section>
<section id="what-about-the-lookups" class="level2">
<h2>What about the lookups?</h2>
<p>Lists support some unusual features. For example, we can access their elements with shortened names, and we’ll get the element with the best match:</p>
<div class="sourceCode" id="cb4" data-org-language="R"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb4-1" title="1">foo<span class="op">$</span>wald</a>
<a class="sourceLine" id="cb4-2" title="2"><span class="co"># [1] 1 2 3 4 5</span></a></code></pre></div>
<p>Hang on—how does R do that? In a standard <a href="https://en.wikipedia.org/wiki/Hash_table">hash table</a>, we hash the key (turn the string “wald” into a numeric code), map that into an array, and look up the entry. But if we look up “wald” instead of “walden”, we’d end up in the wrong place and fail to find the entry. How does R do it?</p>
<p>Simple: it’s not a hash table. It’s a named array. Lookup means an O(n) linear search through the array, checking the names as we go, not an O(1) hash table lookup.</p>
<p>We can see how lists are constructed in <code>src/main/builtin.c</code>, inside <code>do_makelist</code>. There are two steps. First, R iterates through the arguments to <code>list</code> (which are provided as a <code>SEXP</code>—yes, in reference to <a href="https://en.wikipedia.org/wiki/S-expression">S-expressions</a>, since R code is internally kept as linked lists) and checks if any of them have names. If they do, it allocates a <code>names</code> vector and fills it up with the names of the list elements, then attaches it as an attribute to the resulting list, which is internally stored as a vector (an array).</p>
<p>So lists are a pair of arrays: one array of pointers to the list elements, one array of their corresponding names.</p>
<p>Subsetting (the <code>$</code> operator) is implemented in <code>src/main/subset.c</code>, inside <code>R_subset3_dflt</code>, where R iterates through the list to find the element with a matching name:</p>
<div class="sourceCode" id="cb5" data-org-language="C"><pre class="sourceCode c"><code class="sourceCode c"><a class="sourceLine" id="cb5-1" title="1">R_xlen_t i, n, imatch = <span class="dv">-1</span>;</a>
<a class="sourceLine" id="cb5-2" title="2"><span class="dt">int</span> havematch;</a>
<a class="sourceLine" id="cb5-3" title="3">nlist = getAttrib(x, R_NamesSymbol);</a>
<a class="sourceLine" id="cb5-4" title="4"></a>
<a class="sourceLine" id="cb5-5" title="5">n = xlength(nlist);</a>
<a class="sourceLine" id="cb5-6" title="6">havematch = <span class="dv">0</span>;</a>
<a class="sourceLine" id="cb5-7" title="7"><span class="cf">for</span> (i = <span class="dv">0</span> ; i &lt; n ; i = i + <span class="dv">1</span>) {</a>
<a class="sourceLine" id="cb5-8" title="8">    <span class="cf">switch</span>(pstrmatch(STRING_ELT(nlist, i), input, slen)) {</a>
<a class="sourceLine" id="cb5-9" title="9">    <span class="cf">case</span> EXACT_MATCH:</a>
<a class="sourceLine" id="cb5-10" title="10">        y = VECTOR_ELT(x, i);</a>
<a class="sourceLine" id="cb5-11" title="11">        <span class="cf">if</span> (NAMED(x) &gt; NAMED(y))</a>
<a class="sourceLine" id="cb5-12" title="12">            SET_NAMED(y, NAMED(x));</a>
<a class="sourceLine" id="cb5-13" title="13">        UNPROTECT(<span class="dv">2</span>); <span class="co">/* input, x */</span></a>
<a class="sourceLine" id="cb5-14" title="14">        <span class="cf">return</span> y;</a>
<a class="sourceLine" id="cb5-15" title="15">    <span class="cf">case</span> PARTIAL_MATCH:</a>
<a class="sourceLine" id="cb5-16" title="16">        havematch++;</a>
<a class="sourceLine" id="cb5-17" title="17">        <span class="cf">if</span> (havematch == <span class="dv">1</span>) {</a>
<a class="sourceLine" id="cb5-18" title="18">            <span class="co">/* partial matches can cause aliasing in eval.c:evalseq</span></a>
<a class="sourceLine" id="cb5-19" title="19"><span class="co">               This is overkill, but alternative ways to prevent</span></a>
<a class="sourceLine" id="cb5-20" title="20"><span class="co">               the aliasing appear to be even worse */</span></a>
<a class="sourceLine" id="cb5-21" title="21">            y = VECTOR_ELT(x,i);</a>
<a class="sourceLine" id="cb5-22" title="22">            SET_NAMED(y,<span class="dv">2</span>);</a>
<a class="sourceLine" id="cb5-23" title="23">            SET_VECTOR_ELT(x,i,y);</a>
<a class="sourceLine" id="cb5-24" title="24">        }</a>
<a class="sourceLine" id="cb5-25" title="25">        imatch = i;</a>
<a class="sourceLine" id="cb5-26" title="26">        <span class="cf">break</span>;</a>
<a class="sourceLine" id="cb5-27" title="27">    <span class="cf">case</span> NO_MATCH:</a>
<a class="sourceLine" id="cb5-28" title="28">        <span class="cf">break</span>;</a>
<a class="sourceLine" id="cb5-29" title="29">    }</a>
<a class="sourceLine" id="cb5-30" title="30">}</a></code></pre></div>
<p>So we iterate through the elements of the list, checking their names. Exact matches are returned immediately, but unique partial matches require extra processing later (R optionally throws warnings on partial matches, since they’re easy ways to screw up). If there are multiple matches, no match is returned, since picking one arbitrarily would surprise the user.</p>
<p>Now, I mentioned this means it’s an O(n) linear search, not a O(1) hash table lookup. What implications does this have for practical programs? Unfortunately, it makes lists unusable for many tasks you’d want a hash table for.</p>
<p>For example, in our <a href="file:///posts/2016-01-22-stat-computing.html">statistical computing course</a>, we give students a simple challenge: given a file of dictionary words, find sets of words which are anagrams of each other, and print out the sets of grouped anagrams. (For example, “iceman” and “cinema” would be printed together.) The best way to do this is with a hash table, keyed cleverly so that anagrams have the same key.<a href="#fn3" class="footnote-ref" id="fnref3"><sup>3</sup></a></p>
<p>As an example, I read in 91,000 English words from a text file and made them keys of a list, with the values just always 1. I then selected a random subset of 200 of the words.</p>
<div class="sourceCode" id="cb6" data-org-language="R"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb6-1" title="1">words &lt;-<span class="st"> </span><span class="kw">read.csv</span>(<span class="st">&quot;english-words.txt&quot;</span>, <span class="dt">stringsAsFactors=</span><span class="ot">FALSE</span>,</a>
<a class="sourceLine" id="cb6-2" title="2">                  <span class="dt">header=</span><span class="ot">FALSE</span>)</a>
<a class="sourceLine" id="cb6-3" title="3"></a>
<a class="sourceLine" id="cb6-4" title="4">wordlist &lt;-<span class="st"> </span><span class="kw">as.list</span>(<span class="kw">rep</span>(<span class="dv">1</span>, <span class="kw">length</span>(words<span class="op">$</span>V1)))</a>
<a class="sourceLine" id="cb6-5" title="5"><span class="kw">names</span>(wordlist) &lt;-<span class="st"> </span>words<span class="op">$</span>V1</a>
<a class="sourceLine" id="cb6-6" title="6"></a>
<a class="sourceLine" id="cb6-7" title="7">keys &lt;-<span class="st"> </span><span class="kw">sample</span>(words<span class="op">$</span>V1, <span class="dt">size=</span><span class="dv">200</span>)</a></code></pre></div>
<p>I then wrote a simple function to time how long it takes to look up those <code>keys</code> in lists of varying sizes:</p>
<div class="sourceCode" id="cb7" data-org-language="R"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb7-1" title="1">time.lookup &lt;-<span class="st"> </span><span class="cf">function</span>(n) {</a>
<a class="sourceLine" id="cb7-2" title="2">    sublist &lt;-<span class="st"> </span><span class="kw">sample</span>(wordlist, n)</a>
<a class="sourceLine" id="cb7-3" title="3"></a>
<a class="sourceLine" id="cb7-4" title="4">    t &lt;-<span class="st"> </span><span class="kw">system.time</span>({</a>
<a class="sourceLine" id="cb7-5" title="5">        <span class="cf">for</span> (key <span class="cf">in</span> keys) { sublist[[key]] }</a>
<a class="sourceLine" id="cb7-6" title="6">    })</a>
<a class="sourceLine" id="cb7-7" title="7"></a>
<a class="sourceLine" id="cb7-8" title="8">    t[[<span class="st">&quot;elapsed&quot;</span>]]</a>
<a class="sourceLine" id="cb7-9" title="9">}</a></code></pre></div>
<p>Some quick plotting and we obtain:</p>
<div class="sourceCode" id="cb8" data-org-language="R"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb8-1" title="1"><span class="kw">svg</span>(<span class="st">&quot;list-lookup.svg&quot;</span>, <span class="dt">width=</span><span class="dv">5</span>, <span class="dt">height=</span><span class="dv">4</span>)</a>
<a class="sourceLine" id="cb8-2" title="2">sizes &lt;-<span class="st"> </span><span class="kw">seq</span>(<span class="dt">from=</span><span class="dv">1000</span>, <span class="dt">to=</span><span class="dv">90000</span>, <span class="dt">by=</span><span class="dv">500</span>)</a>
<a class="sourceLine" id="cb8-3" title="3">times &lt;-<span class="st"> </span><span class="kw">sapply</span>(sizes, time.lookup)</a>
<a class="sourceLine" id="cb8-4" title="4"><span class="kw">plot</span>(times <span class="op">~</span><span class="st"> </span>sizes, <span class="dt">xlab=</span><span class="st">&quot;List size&quot;</span>, <span class="dt">ylab=</span><span class="st">&quot;Lookup time (seconds)&quot;</span>,</a>
<a class="sourceLine" id="cb8-5" title="5">     <span class="dt">pch=</span><span class="dv">20</span>, <span class="dt">las=</span><span class="dv">1</span>)</a>
<a class="sourceLine" id="cb8-6" title="6"><span class="kw">dev.off</span>()</a></code></pre></div>
<p><img src="/images/list-lookup.svg" /></p>
<p>Yes, it’s roughly linear, so list lookups are O(n). For the anagrams problem, this becomes a prohibitive time cost, making the program orders of magnitude slower than the equivalent in Python or another language with built-in O(1) hash tables.</p>
<p>Obviously, for small lists (like a data frame with five columns), a linear search through such a small array is hardly a cost at all—it may even be faster than calculating a hash function. But once we start storing large datasets in lists, we run into problems.</p>
</section>
<section id="lists-powerful-but-inflexible" class="level2">
<h2>Lists: powerful but inflexible</h2>
<p>Lists are flexible and widely used in R. They’re the basis of S3 classes, they can store heterogeneous and deeply nested data, and the default vectorization machinery (like <code>apply</code> and <code>lapply</code>) produces lists. There’s extended list subsetting syntax with the <code>[</code> and <code>[[</code> operators, along with <code>$</code>, and useful features like record types (or structs) can be emulated by simply using a list.</p>
<p>But the next problem with R’s approach to lists is the names: they may only be strings. In Python (or Racket, or many other languages), on the other hand, I could use any immutable type as a key:</p>
<div class="sourceCode" id="cb9"><pre class="sourceCode python"><code class="sourceCode python"><a class="sourceLine" id="cb9-1" title="1">foo <span class="op">=</span> {(<span class="dv">1</span>, <span class="dv">2</span>): <span class="dv">7</span>, <span class="st">&quot;bar&quot;</span>: <span class="st">&quot;baz&quot;</span>}</a>
<a class="sourceLine" id="cb9-2" title="2"></a>
<a class="sourceLine" id="cb9-3" title="3">foo[(<span class="dv">1</span>, <span class="dv">2</span>)]</a>
<a class="sourceLine" id="cb9-4" title="4"><span class="co"># 7</span></a></code></pre></div>
<p>Any immutable type can be hashed, so there’s no reason it can’t be used as a key in a dictionary. But R only supports strings as list keys. This may seem like a minor niggle, but it turns out that arbitrary keys can be amazingly useful for O(1) lookups of things other than strings. They’re also useful for storing <em>sets</em>, collections of items for which every item appears only once and which support efficient unions and intersections. I often make use of sets in my own code:</p>
<ul>
<li>Finding duplicates in sets of data other than strings.</li>
<li>Storing sets; for example, my <a href="/posts/2016-01-25-conway-game-of-life.html">Conway’s Game of Life code</a> (in Racket) keeps track of which cells are live by storing the current set of live cells, in terms of their (x, y) coordinates. (This way, I don’t need to store a matrix of all the grid cells—I can just store the live ones, and hence support an infinitely large grid. This trick came from <a href="http://www.stat.cmu.edu/~genovese/">Chris Genovese</a>.) But in R, I couldn’t use this trick: there’s no way to look up if a cell is live without an O(n) search, and I’d have to convert the coordinates to “x,y” strings instead of using more natural <code>c(x,y)</code> vectors.</li>
</ul>
<p>Code that tries to get around these restrictions has to use convoluted workarounds. The <a href="https://cran.r-project.org/web/packages/sets/index.html">sets</a> package, for example, offers native set data structures in R, but stores them as sorted lists. (Sorting is necessary to make it easy to check if two sets are equal.) For sets containing non-numeric elements, the elements are sorted by their string representation, so every object has to be converted to a string. To perform set intersection operations, or others that would require O(1) access, the list is converted to a hash table by converting all its elements to strings and using an R environment.</p>
<p>All these convolutions cost efficiency and complexity. Of course, the user of the sets package need not worry with the details, but if they care about performance, they’ll notice the cost.</p>
</section>
<section id="the-problem-with-absent-data-structures" class="level2">
<h2>The problem with absent data structures</h2>
<p>R users have various superstitions about writing fast code: vectorize everything, avoid <code>for</code> loops, use built-in functions when you can, and write hot functions in C++ (through <a href="http://rcpp.org/">Rcpp</a>) whenever necessary. And that’s about it.</p>
<p>And yes, vectorization can gain you a large constant factor in performance over a <code>for</code> loop, since the loop is done in fast C code instead of a slow bytecode interpreter. But if you want to go from O(n<sup>2</sup>) to O(n), you need to use the right data structure instead of munging together lists of lists using <code>vapply</code> and <code>merge</code> and whatever other functions you can piece together.</p>
<p>I’d love to see basic sets, hash tables, and trees built into R. I don’t know if it can be done while keeping compatibility, but it’s necessary if R is to become a more general-purpose programming language. I don’t know if that will happen or if Julia and Python eat its lunch.</p>
</section>
<section class="footnotes">
<hr />
<ol>
<li id="fn1"><p>For certain values of “famous”.<a href="#fnref1" class="footnote-back">↩</a></p></li>
<li id="fn2"><p>I realize there are <a href="http://adv-r.had.co.nz/Environments.html">environments</a>, but they are a curious beast of their own. The <a href="https://cran.r-project.org/web/packages/hash/index.html">hash</a> package uses them to implement hash tables with string keys.<a href="#fnref2" class="footnote-back">↩</a></p></li>
<li id="fn3"><p>Stat computing students: it’s cheating to read the rest of this footnote. But, in short, sort the characters in the words. “iceman” and “cinema” both sort to “aceimn”, so they’d end up at the same key in the hash table.<a href="#fnref3" class="footnote-back">↩</a></p></li>
</ol>
</section>]]></description>
    <pubDate>Mon, 12 Sep 2016 00:00:00 UT</pubDate>
    <guid>https://www.refsmmat.com/posts/2016-09-12-r-lists.html</guid>
    <dc:creator>Alex Reinhart</dc:creator>
</item>
<item>
    <title>Simpson's Paradox and Statistical Urban Legends: Gender Bias at Berkeley</title>
    <link>https://www.refsmmat.com/posts/2016-05-08-simpsons-paradox-berkeley.html</link>
    <description><![CDATA[<p>Introductory statistics textbooks usually point out <a href="https://en.wikipedia.org/wiki/Simpson&#39;s_paradox">Simpson’s paradox</a>, an interesting phenomenon that’s usually illustrated with a story from the University of California, Berkeley. The story goes something like this:</p>
<p>In 1973, UC Berkeley was sued for gender bias, because their graduate school admission figures showed obvious bias against women:<a href="#fn1" class="footnote-ref" id="fnref1"><sup>1</sup></a></p>
<table>
<thead>
<tr class="header">
<th></th>
<th style="text-align: right;">Applicants</th>
<th style="text-align: right;">Admitted</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td>Men</td>
<td style="text-align: right;">8442</td>
<td style="text-align: right;">44%</td>
</tr>
<tr class="even">
<td>Women</td>
<td style="text-align: right;">4321</td>
<td style="text-align: right;">35%</td>
</tr>
</tbody>
</table>
<p>Men were much more successful in admissions than women, leading Berkeley to be <a href="http://rationalwiki.org/wiki/Simpson&#39;s_paradox#Example_1_-_Berkeley.E2.80.99s_sex_bias_case">“one of the first universities to be sued for sexual discrimination”</a>. (The difference is statistically significant with <em>p</em> ≈ 10<sup>-26</sup>!) The lawsuit failed, however, when statisticians examined each department separately. Graduate departments have independent admissions systems, so it makes sense to check them separately—and when you do, there appears to be a bias <em>in favor</em> of women.</p>
<p>How does this happen? The simple explanation is that women tended to apply to the departments that are the hardest to get into, and men tended to apply to departments that were easier to get into. (Humanities departments tended to have less research funding to support graduate students, while science and engineer departments were awash with money.) So women were rejected more than men. Presumably, the bias wasn’t at Berkeley but earlier in women’s education, when other biases led them to different fields of study than men.</p>
<p>Now, this example has been analyzed to death in many places: <a href="https://en.wikipedia.org/wiki/Simpson&#39;s_paradox#UC_Berkeley_gender_bias">on Wikipedia</a>, in <a href="http://www.brookings.edu/blogs/social-mobility-memos/posts/2015/07/29-simpsons-paradox-education-earnings-hershbein">various</a> <a href="http://mathemathinking.blogspot.com/2012/06/simpsons-paradox.html">blogs</a>, in many textbooks (including <a href="http://www.statisticsdonewrong.com/">my own book</a>), and pretty much everywhere else. I’m not going to present a new analysis of the data or of Simpson’s paradox.</p>
<p>I just want to point out something simpler: There never was a lawsuit!</p>
<section id="the-real-berkeley-story" class="level2">
<h2>The real Berkeley story</h2>
<p>A <a href="http://www.wsj.com/news/articles/SB125970744553071829"><em>Wall Street Journal</em> interview</a> with Peter Bickel, one of the statisticians involved in the original study, makes clear that Berkeley was never sued—it was merely <em>afraid</em> of being sued:</p>
<blockquote>
<p>Simpson’s Paradox has fooled many. In the fall of 1973, for instance, the University of California, Berkeley’s graduate division admitted about 44% of male applicants and 35% of female applicants. That raised eyebrows among school officials, who feared bias and asked Peter Bickel, now a professor emeritus of statistics at Berkeley, to analyze the data.</p>
</blockquote>
<blockquote>
<p>“The associate dean of the graduate school thought that the university might be sued,” Mr. Bickel says.</p>
</blockquote>
<blockquote>
<p>When Mr. Bickel and his colleagues scrutinized the data, they found little evidence of gender bias. Instead, they discovered that more women had applied to departments that admitted a small percentage of applicants, like English, than to departments that admitted a large percentage of applicants, like mechanical engineering.</p>
</blockquote>
<p>The core paradox matches the usual story, but no lawsuit was involved. I’ve done some digging and I haven’t been able to find the original source of the mythical lawsuit—perhaps an early textbook or journal article author misheard the original story, wrote about a lawsuit, and authors ever since have copied the story unchanged.</p>
</section>
<section id="academic-urban-legends" class="level2">
<h2>Academic urban legends</h2>
<p>A scan through Google Books reveals this urban legend has infected many recent books, and undoubtedly many older ones:</p>
<ul>
<li><em>Paradoxes in Scientific Inference</em> (2012), by Mark Chang</li>
<li><em>Learning Statistics with R</em>, by Daniel Navarro</li>
<li><em>R Graphics Cookbook</em> (2013), by Winston Chang</li>
<li><em>Math on Trial: How Numbers get Used and Abused in the Courtroom</em> (2013), by Leila Schneps and Corali Colmez. Surprisingly, this book makes the claim in an entire chapter dedicated to Simpson’s paradox, after carefully explaining a separate lawsuit about gender bias in Berkeley’s faculty hiring process. After explaining the suit in detail, the mythical graduate admissions lawsuit is thrown in as an aside.</li>
<li><em>Einstein’s Riddle: 50 Riddles, Puzzles, and Conundrums to Stretch Your Mind</em> (2009), by Jeremy Stangroom</li>
<li><em>Impossible? Surprising Solutions to Counterintuitive Conundrums</em> (2011), by Julian Havil</li>
</ul>
<p>It’s also present in the scientific literature:</p>
<ul>
<li>Harris Cooper and Erika A. Patall. “The relative benefits of meta-analysis conducted with individual participant data versus aggregated data,” <em>Psychological Methods</em> (2009), vol 14(2), pp. 165-176. <a href="http://dx.doi.org/10.1037/a0015565">10.1037/a0015565</a>. “Perhaps the best known example of Simpson’s paradox involves a lawsuit brought against the University of California at Berkeley alleging bias against women in the selection of graduate school applicants”</li>
<li>Stanley A. Taylor and Amy E. Mickel. “<a href="http://www.amstat.org/publications/jse/v22n1/mickel.pdf">Simpson’s Paradox: A Data Set and Discrimination Case Study Exercise</a>,” <em>Journal of Statistics Education</em> (2014), vol 22(1). “An example of this phenomenon is when the University of California, Berkeley was sued for bias against women who had applied for admission to graduate schools in 1973.”</li>
<li>Matteo G A Paris. “Two quantum Simpson’s paradoxes,” <em>Journal of Physics A</em> (2012), vol 45(13). <a href="http://dx.doi.org/10.1088/1751-8113/45/13/132001">10.1088/1751-8113/45/13/132001</a>. “One of the best known real life examples of Simpson’s paradox occurred when the University of California, Berkeley was sued for bias against women who had applied for admission to graduate schools there.”</li>
</ul>
<p>Now, this isn’t the first time scientists have unwittingly propagated a myth through decades of the literature. The best example is possibly the century-old myth that spinach is a rich dietary source of iron: even the <em>myth</em> is a myth, as it turns out the common explanation (that German chemists measuring the iron content of spinach had misplaced a decimal point) is <em>also</em> a myth, propagated through the literature by scientists copying references without checking up on their provenance.<a href="#fn2" class="footnote-ref" id="fnref2"><sup>2</sup></a></p>
<p>It seems Simpson’s paradox has experienced a similar problem. Someone, perhaps back in the 1970s or 1980s, before the story was easily Googleable, wrote about a lawsuit to spice up their example, and the story has been repeated ever since.<a href="#fn3" class="footnote-ref" id="fnref3"><sup>3</sup></a> I only detected the problem because I am the type of nerd who wonders “Is the court opinion in this case available online? I’d love to read what the judge thought of the statistics”, and so I started hunting for a nonexistent court case.</p>
<p>Perhaps when we use stories to illustrate common statistical errors, we should make sure our stories are not in error as well.</p>
</section>
<section class="footnotes">
<hr />
<ol>
<li id="fn1"><p>Bickel, P. J., Hammel, E. A., &amp; O’Connell, J. W. (1975). Sex bias in graduate admissions: Data from Berkeley. <em>Science</em>, 187(4175), 398–404. <a href="http://doi.org/10.1126/science.187.4175.398" class="uri">http://doi.org/10.1126/science.187.4175.398</a><a href="#fnref1" class="footnote-back">↩</a></p></li>
<li id="fn2"><p>Rekdal, O. B. (2014). Academic urban legends. <em>Social Studies of Science</em>, 44(4), 638–654. <a href="http://doi.org/10.1177/0306312714535679" class="uri">http://doi.org/10.1177/0306312714535679</a><a href="#fnref2" class="footnote-back">↩</a></p></li>
<li id="fn3"><p>Kudos to the anonymous Wikipedian who <a href="https://en.wikipedia.org/w/index.php?title=Simpson%27s_paradox&amp;diff=717258021&amp;oldid=704772363">noticed that none of the Simpson’s Paradox article’s sources could confirm a lawsuit and removed the mention</a>.<a href="#fnref3" class="footnote-back">↩</a></p></li>
</ol>
</section>]]></description>
    <pubDate>Sun, 08 May 2016 00:00:00 UT</pubDate>
    <guid>https://www.refsmmat.com/posts/2016-05-08-simpsons-paradox-berkeley.html</guid>
    <dc:creator>Alex Reinhart</dc:creator>
</item>
<item>
    <title>Review: James Boyle's 'The Public Domain'</title>
    <link>https://www.refsmmat.com/posts/2016-02-17-public-domain.html</link>
    <description><![CDATA[<p>James Boyle is a law professor specializing in copyright law, and <em>The Public Domain</em> is some of the most readable legal writing I’ve seen in a long time. (He gets bonus points for making the ePub and PDF freely available on <a href="http://www.thepublicdomain.org/">his website</a>.) Boyle covers the recent expansion of copyright law to protect more works for longer terms, depriving our culture of the benefit of their free use. He starts by covering the foundational arguments of copyright law: just what <em>is</em> “intellectual property,” and what sorts of rights do authors have in their works?</p>
<p>Boyle is a fan of Thomas Jefferson’s thoughts on the subject. Jefferson argued that there is no inherent property right in intellectual works: once you read my book or hear my speech, you have an irrevocable mental copy, and your possession of the work does not prevent anyone else’s. Unlike physical property, many people can have the work simultaneously. Copyright is instead a limited grant of a monopoly by the government, with the intent of promoting artists and authors; because monopolies were axiomatically considered Bad Things at the time, the monopoly must be as limited as possible to carry out its purpose.</p>
<p>This stands in contrast to the common European (and, most often, French) views of copyright, usually phrased in terms of “author’s rights” instead. In this system, authors have an inherent perpetual right to works they produce—works that are the embodiment of their unique genius, works they poured tremendous creative energy into, works which others could only spoil with their tampering. The distinction is better explored in Peter Baldwin’s <em>Copyright Wars</em>, though just about everything else is done better by Boyle; Baldwin’s work, though exhaustive, was not nearly as fluid and readable, and showed symptoms of Academic Sentence Convolution Syndrome.<a href="#fn1" class="footnote-ref" id="fnref1"><sup>1</sup></a></p>
<p>Boyle reframes the argument in favor of limited copyright terms in terms of government subsidies. Using government power to protect the revenues of the tiny fraction of works which still draw revenue several decades after publication has a cost: it renders the vast majority of unprofitable and abandoned works completely unavailable to anyone. We ban ourselves from the majority of culture to subsidize a few percent of published works.<a href="#fn2" class="footnote-ref" id="fnref2"><sup>2</sup></a></p>
<p>I find this argument convincing. <a href="https://www.gutenberg.org/">Project Gutenberg</a> shows that old culture can be digitized and reused for all sorts of interesting purposes, <a href="https://en.wikipedia.org/wiki/Main_Page">Wikipedia</a> just how valuable free culture can be, the entire Internet what can happen when information can be shared freely and easily. Why not make the war correspondence and novels of the 1940s available to all? Why let the literature of the 1950s slowly rot away in libraries when it can be read and enjoyed again?<a href="#fn3" class="footnote-ref" id="fnref3"><sup>3</sup></a></p>
<p>Boyle also discusses the “Internet Threat”: that computers and the Internet will make copying and redistribution so easy that new rights must be granted to copyright holders to prevent serious loss of business. Digital Rights Management falls in this category: companies must be granted a right not only to monopolize distribution of their work but to prevent reuse, under fair use or not, of work already sold to a paying customer. Media companies describe DRM-breaking tools as burglary tools, while advocates point out that they’re breaking into works they already own. Boyle says the DMCA’s prohibitions on DRM-breaking are a new, and constitutionally unfounded, right granted to media companies: there is no similar scheme whereby I can put a mark on a book to say “you may not copy this, even under fair use”, so why should breaking DRM be any different?</p>
<p>(As an aside, Boyle’s comments on <a href="https://en.wikipedia.org/wiki/DeCSS">DeCSS</a> and movie piracy are amusing. He quotes from the decision in <em>Universal City Studios, Inc. v. Reimerdes</em>, a 2000 court case against DeCSS, a description of the process of movie piracy: half an hour decrypting the DVD, 10 to 20 hours synchronizing the compressed audio and video, and six hours to transfer it to someone else over IRC. Compared to “renting the same movie at Blockbuster for $3”, Boyle thinks, this is no threat. Blockbuster’s shareholders would beg to differ, as would The Pirate Bay.)</p>
<p>Similarly, some companies tried to use copyright law in lieu of patent or trademark law, preventing competitors from making garage door remotes compatible with their openers or music stores compatible with their iPods. The courts looked down on this; while it may count as circumvention, there certainly was no intent to redistribute copyrighted works or otherwise violate the rights of the rightsholders.</p>
<p>Circumvention is followed with a discussion of copyright in music, where nearly every work is a derivative work: borrowing melodies, arrangements, styles, and even portions of recordings is an entirely normal part of the creative process. But I’m not very interested in the music world (to my detriment, perhaps), so I skipped past much of this discussion.</p>
<p>Next, Boyle covers open-source software and the <a href="https://creativecommons.org/">Creative Commons</a> movement, which has somehow produced high-quality works without any profit incentive whatsoever, and uses copyright law to <em>enforce</em> inclusivity (through <a href="https://en.wikipedia.org/wiki/Copyleft">copyleft</a>), rather than to exclude uses. The existence of open-source software and free culture suggests a flaw in the usual arguments for intellectual property: quite a lot of intellectual property needs no profit motive to be created. People write code because they want to, not because they expect payment. People write entire books because they enjoy the process or because they believe the message is important (as <a href="http://www.statisticsdonewrong.com/">I did</a>). As a result, Boyle argues that proposed intellectual property legislation should consider not just its impact on commercial ventures but on open-source and free-culture works, because they are just as important a source of innovation; advance commercial interests at the cost of open-source software and you will damage a number of businesses unintentionally.<a href="#fn4" class="footnote-ref" id="fnref4"><sup>4</sup></a></p>
<p>Patents also apply to software, though the book was written before <em><a href="https://en.wikipedia.org/wiki/Alice_Corp._v._CLS_Bank_Int&#39;l">Alice Corp v. CLS Bank</a></em> demolished the idea that the phrase “by means of a computer” turns unpatentable abstract ideas into patentable inventions. Some of the discussion is hence out of date. Software patents are still a legal minefield, though, and one (from my admittedly biased perspective) worth exploring in more depth.</p>
<p>The final chapters explore evidence-based intellectual property policy, like evaluations of Europe’s odd <a href="https://en.wikipedia.org/wiki/Sui_generis_database_right">database rights</a> scheme, and how policy is often based on the bald assertion that “more rights terms benefit authors” without any analysis of costs, incentives, or economics. (Retroactive term extensions are particularly inexcusable in economic terms, since the authors were clearly willing to produce the works without them.) As a statistician I’m particularly annoyed by database rights; most databases I encounter were created or funded by government agencies and hence by my tax dollars, and my current research project involves combining an assortment of databases to answer questions the original compilers would never have thought of.<a href="#fn5" class="footnote-ref" id="fnref5"><sup>5</sup></a> Database rights would make my work much more difficult, blocking important research, and bring very little benefit to the compilers of the databases.</p>
<p>Overall I was happy with <em>The Public Domain</em>, and I wish more people involved in intellectual property policy (politicians, scientists and publishers involved in the big open access debates, authors) would read it. Perhaps it doesn’t go into incredible academic depth on every issue, but it is likely a better book for it. To put it another way: I finished the book wanting to learn more, showing not that it was too short but that it was interesting and engaging enough to leave me wanting more.</p>
<section class="footnotes">
<hr />
<ol>
<li id="fn1"><p>Fred Rodell <a href="https://www.refsmmat.com/files/goodbye.pdf">famously complained</a> that lawyers are incapable of saying anything directly or forcefully. Criticizing a judicial decision, a lawyer might write “It would seem that a contrary conclusion might perhaps have been better justified.” Baldwin is guilty of this kind of writing; Boyle simply writes “If this [decision] were a law school exam, it would get a ‘D’. (Maybe a C given grade inflation.)”<a href="#fnref1" class="footnote-back">↩</a></p></li>
<li id="fn2"><p><a href="http://www.thepublicdomain.org/2014/07/19/mark-twain-on-the-need-for-perpetual-copyright/">Mark Twain argued</a> that this was exactly why copyright terms <em>should</em> be long: you benefit the children of those few authors, and harm nobody else. But making culture unavailable <em>is</em> a harm, and a state subsidy for the children of successful authors should be recognized for what it is: a state subsidy for the children of successful people. Hardly popular in today’s political climate.<a href="#fnref2" class="footnote-back">↩</a></p></li>
<li id="fn3"><p>I once heard a vaguely plausible counter-argument: free access to 20th-century literature and art would mean new work has to compete with free older work. Publishers currently can put books out of print after a few years, removing them from competition, but if a vast back-catalog of out-of-copyright works suddenly appeared, would people still read new books? Watch new movies? Well, yes, probably; the marketing power of the publishers is considerable. But would you deny us the benefit of learning from our history to subsidize new work?<a href="#fnref3" class="footnote-back">↩</a></p></li>
<li id="fn4"><p>It’s interesting to see that there’s a modern backlash against copyleft in the open source community: many modern projects choose licenses like the <a href="https://en.wikipedia.org/wiki/BSD_licenses">BSD</a> and <a href="https://en.wikipedia.org/wiki/MIT_License">MIT</a> licenses, which have no copyleft terms and are compatible with reuse in proprietary software. Developers now regard adoption of their code by closed-source for-profit software a good thing rather than a detriment to user freedom. Copyleft licenses like the <a href="https://en.wikipedia.org/wiki/GNU_General_Public_License">GPL</a> are seen as only restricting the potential uses of your software. I’m not sure how this shift happened—perhaps the wide success of open source software makes people believe copyleft terms are not necessary to ensure its continued existence?<a href="#fnref4" class="footnote-back">↩</a></p></li>
<li id="fn5"><p>A lot of statisticians can say this.<a href="#fnref5" class="footnote-back">↩</a></p></li>
</ol>
</section>]]></description>
    <pubDate>Wed, 17 Feb 2016 00:00:00 UT</pubDate>
    <guid>https://www.refsmmat.com/posts/2016-02-17-public-domain.html</guid>
    <dc:creator>Alex Reinhart</dc:creator>
</item>
<item>
    <title>A flexible implementation of Conway's Game of Life</title>
    <link>https://www.refsmmat.com/posts/2016-01-25-conway-game-of-life.html</link>
    <description><![CDATA[<p><a href="https://en.wikipedia.org/wiki/Conway&#39;s_Game_of_Life">Conway’s Game of Life</a> is a simple simulation with surprisingly complex behavior. We start with a simple 2D grid of cells. Each cell can be either alive or dead. The rules are:</p>
<ul>
<li>A live cell stays alive if it has two or three live neighbors.</li>
<li>A dead cell becomes alive if it has exactly three live neighbors.</li>
</ul>
<p>We started with a certain set of cell states and then iterate, applying the rules to every cell at each iteration. Despite their simplicity, these rules can produce amazingly complicated behavior. For example, here is Gosper’s Glider Gun, which produces “gliders” which wander off to infinity:<a href="#fn1" class="footnote-ref" id="fnref1"><sup>1</sup></a></p>
<figure>
<img src="/images/Gospers_glider_gun.gif" alt="An animation of Gosper’s Glider Gun in action." /><figcaption>An animation of Gosper’s Glider Gun in action.</figcaption>
</figure>
<p>For our <a href="/posts/2016-01-22-stat-computing.html">Statistical Computing course</a>, Chris Genovese used the Game of Life as an example at the very beginning of the course to illustrate the flexible design of programs. Students first were told to write an ordinary implementation following the rules above – then asked how they’d abstract their algorithm so they could replace the rules or even work on a non-rectangular grid. Without careful planning, that kind of abstraction could be very difficult.</p>
<p>So here’s a sample implementation in <a href="http://racket-lang.org/">Racket</a>, my favorite little Lisp.</p>
<section id="setting-up-the-rules" class="level2">
<h2>Setting up the rules</h2>
<p>First we need to specify the rules of the game. Conway’s rules are the most popular, but it’s possible to use different rules to decide which cells live or die, so we’ll abstract the rules out to a function.</p>
<p>The rules function only needs to know two things: the number of neighbors the cell has, and whether or not it’s currently alive. Then it returns a boolean indicating whether the cell will stay alive.<a href="#fn2" class="footnote-ref" id="fnref2"><sup>2</sup></a></p>
<div class="sourceCode" id="cb1"><pre class="sourceCode clojure"><code class="sourceCode clojure"><a class="sourceLine" id="cb1-1" title="1">(define (conway-rules neighbors alive?)</a>
<a class="sourceLine" id="cb1-2" title="2">  (<span class="kw">if</span> alive? (<span class="kw">or</span> (<span class="kw">=</span> neighbors <span class="dv">2</span>) (<span class="kw">=</span> neighbors <span class="dv">3</span>))</a>
<a class="sourceLine" id="cb1-3" title="3">      (<span class="kw">=</span> neighbors <span class="dv">3</span>)))</a></code></pre></div>
<p>If we want to try out different sets of rules, it’s easy to define entirely new functions – with arbitrary logic and complexity – which can replace <code>conway-rules</code>. As you’ll see below, <code>conway-rules</code> is passed as an argument to our other functions, so replacing it requires no source code changes at all.</p>
</section>
<section id="operating-on-the-grid" class="level2">
<h2>Operating on the grid</h2>
<p>It’s tempting to store the state of the Game of Life using some kind of two-dimensional array or matrix. Then, on each step, we’d loop through the whole board, checking which cells should live or die. But this would become slow – the gliders we saw earlier can wander off arbitrarily far, so our board would have to be large and the loop slow. If our board isn’t large enough, cells could reach the edge, and we’d either need to increase the board size or accept that their behavior will be wrong.</p>
<p>Worse, the amount of computation needed would grow with the board size, regardless of how many cells in the board are actually alive. In the worst case, we’d have an enormous board of entirely dead cells, and at every step we’d still loop through the whole thing checking if anything should come alive.</p>
<p>But look back at the rules. All we really need to keep track of is the live cells. We can tell if a cell comes alive just by knowing if it has live neighbors.</p>
<p>Imagine we have a list of currently live cells. If we find the neighbors of each live cell, we’ll have a big list of coordinates; if a cell is the neighbor of three live cells, it’ll appear in that list three times. So, for example, a currently dead cell which is the neighbor of three live cells will appear in the list, and we can mark it as alive on the next step.</p>
<p>On our rectangular grid, we can easily find the neighbors of a single cell with</p>
<div class="sourceCode" id="cb2"><pre class="sourceCode clojure"><code class="sourceCode clojure"><a class="sourceLine" id="cb2-1" title="1">(define (neighbors-rect location)</a>
<a class="sourceLine" id="cb2-2" title="2">  (<span class="kw">let</span> ([x (<span class="kw">first</span> location)]</a>
<a class="sourceLine" id="cb2-3" title="3">        [y (<span class="kw">last</span> location)])</a>
<a class="sourceLine" id="cb2-4" title="4">    (for*/list ([dx &#39;(-<span class="dv">1</span> <span class="dv">0</span> <span class="dv">1</span>)]</a>
<a class="sourceLine" id="cb2-5" title="5">                [dy &#39;(-<span class="dv">1</span> <span class="dv">0</span> <span class="dv">1</span>)]</a>
<a class="sourceLine" id="cb2-6" title="6">                #<span class="at">:when</span> (<span class="kw">not</span> (<span class="kw">=</span> dx dy <span class="dv">0</span>)))</a>
<a class="sourceLine" id="cb2-7" title="7">      (<span class="kw">list</span> (<span class="kw">+</span> x dx) (<span class="kw">+</span> y dy)))))</a></code></pre></div>
<p>Coordinates are stored as <code>(x, y)</code> pairs. We loop through perturbations, adding or subtracting 1 from <code>x</code> and <code>y</code>, generating the eight neighbor coordinates.</p>
</section>
<section id="taking-the-next-step" class="level2">
<h2>Taking the next step</h2>
<p>I’m going to put together a key function from a few pieces here. Let’s start with the basic bits. To apply Conway’s rules, we start by getting the list of all neighbors of all cells:</p>
<div class="sourceCode" id="cb3"><pre class="sourceCode clojure"><code class="sourceCode clojure"><a class="sourceLine" id="cb3-1" title="1">(append-map neighbors (set-&gt;list live-cells))</a></code></pre></div>
<p>We need to count how many times each coordinate appears in this list, so we’ll use a hash table. The result is a table of <code>item,count</code> pairs:</p>
<div class="sourceCode" id="cb4"><pre class="sourceCode clojure"><code class="sourceCode clojure"><a class="sourceLine" id="cb4-1" title="1">(define (count-occurrences neighbors)</a>
<a class="sourceLine" id="cb4-2" title="2">  (for/fold ([ht (<span class="kw">hash</span>)])</a>
<a class="sourceLine" id="cb4-3" title="3">            ([item neighbors])</a>
<a class="sourceLine" id="cb4-4" title="4">    (hash-update ht item add1 <span class="dv">0</span>)))</a></code></pre></div>
<p><code>hash-update</code> takes a hash table, looks for a key (<code>item</code>), and updates it according to the function passed to it – in this case <code>add1</code>, so the count is incremented by 1. If the key doesn’t exist, we pass 0 to <code>add1</code> as the default. As a result, we have a count of how many time each <code>item</code> appears in the <code>neighbors</code> list.</p>
<p>Then it’s just a matter of applying the rules. If we have the number of neighbors and a set of live cells, then applying the rules is as simple as</p>
<div class="sourceCode" id="cb5"><pre class="sourceCode clojure"><code class="sourceCode clojure"><a class="sourceLine" id="cb5-1" title="1">(conway-rules (hash-ref num-neighbors cell)</a>
<a class="sourceLine" id="cb5-2" title="2">              (set-member? live-cells cell))</a></code></pre></div>
<p>The <code>hash-ref</code> simply looks up the <code>cell</code> in the table, returning how many neighbors it has.</p>
<p>Now we can assemble together a function to take a set of live cells and return a new set:</p>
<div class="sourceCode" id="cb6"><pre class="sourceCode clojure"><code class="sourceCode clojure"><a class="sourceLine" id="cb6-1" title="1">(define (step rules neighbors live-cells)</a>
<a class="sourceLine" id="cb6-2" title="2">  (<span class="kw">let</span> ([num-neighbors</a>
<a class="sourceLine" id="cb6-3" title="3">         (count-occurrences (append-map neighbors (set-&gt;list live-cells)))])</a>
<a class="sourceLine" id="cb6-4" title="4">    (list-&gt;set (<span class="kw">filter</span> (lambda (cell) </a>
<a class="sourceLine" id="cb6-5" title="5">                         (conway-rules (hash-ref num-neighbors cell)</a>
<a class="sourceLine" id="cb6-6" title="6">                                       (set-member? live-cells cell)))</a>
<a class="sourceLine" id="cb6-7" title="7">                       (hash-keys num-neighbors)))))</a></code></pre></div>
</section>
<section id="running-more-generations" class="level2">
<h2>Running more generations</h2>
<p>Our <code>step</code> function only runs one iteration: it applies the rules, generates the new set of live cells, and returns it. How do we run the Game of Life for more steps?</p>
<p>A simple route would be a <code>for</code> loop. But we can be fancier. Racket supports <em>lazy sequences</em>: infinitely long sequences whose elements are calculated only when we ask for them. We can define one recursively.</p>
<div class="sourceCode" id="cb7"><pre class="sourceCode clojure"><code class="sourceCode clojure"><a class="sourceLine" id="cb7-1" title="1">(define (life cells)</a>
<a class="sourceLine" id="cb7-2" title="2">  (stream-cons cells (life (step conway-rules neighbors-rect cells))))</a></code></pre></div>
<p><code>stream-cons</code> is an interesting function that works recursively. It defines a stream (a sequence) that begins with <code>cells</code> and whose next element is formed by calling its second argument – which creates another sequence that starts at the next step.</p>
<p>In summary, <code>life</code> applies Conway’s rules on a rectangular grid, making an infinite sequence of cell states. We can ask Racket to provide any element in the sequence and it’ll be calculated on demand.</p>
</section>
<section id="the-results" class="level2">
<h2>The results</h2>
<p>Let’s try our code on a sample set of live cells. We’ll use the “acorn”, a configuration which starts small and then grows for thousands of generations. I’ve imported a <code>draw-game</code> function which draws the results. At the beginning, it looks like this:</p>
<div class="sourceCode" id="cb8"><pre class="sourceCode clojure"><code class="sourceCode clojure"><a class="sourceLine" id="cb8-1" title="1">(define acorn (<span class="kw">set</span> &#39;(<span class="dv">1</span> <span class="dv">1</span>) &#39;(<span class="dv">2</span> <span class="dv">1</span>) &#39;(<span class="dv">2</span> <span class="dv">3</span>) &#39;(<span class="dv">4</span> <span class="dv">2</span>) &#39;(<span class="dv">5</span> <span class="dv">1</span>) &#39;(<span class="dv">6</span> <span class="dv">1</span>) &#39;(<span class="dv">7</span> <span class="dv">1</span>)))</a>
<a class="sourceLine" id="cb8-2" title="2">(draw-game (set-&gt;list acorn))</a></code></pre></div>
<figure>
<img src="/images/acorn.png" alt="The acorn configuration." /><figcaption>The acorn configuration.</figcaption>
</figure>
<p>But after just fifty steps, we have:</p>
<div class="sourceCode" id="cb9"><pre class="sourceCode clojure"><code class="sourceCode clojure"><a class="sourceLine" id="cb9-1" title="1">(draw-game (set-&gt;list (stream-ref (life acorn) <span class="dv">50</span>)))</a></code></pre></div>
<figure>
<img src="/images/acorn-50.png" alt="The acorn configuration after fifty steps." /><figcaption>The acorn configuration after fifty steps.</figcaption>
</figure>
<p>And after fifty more:</p>
<div class="sourceCode" id="cb10"><pre class="sourceCode clojure"><code class="sourceCode clojure"><a class="sourceLine" id="cb10-1" title="1">(draw-game (set-&gt;list (stream-ref (life acorn) <span class="dv">100</span>)))</a></code></pre></div>
<figure>
<img src="/images/acorn-100.png" alt="The acorn configuration after 100 steps." /><figcaption>The acorn configuration after 100 steps.</figcaption>
</figure>
</section>
<section id="life-on-a-hexagonal-grid" class="level2">
<h2>Life on a hexagonal grid</h2>
<p>One more thing. Previously we defined a neighbors function, which gets the list of neighbors of a cell. That function assumed we were working on a rectangular grid. But, if you look carefully, you’ll see it’s the only function which assumes that. If we want to change the grid, we need only swap out the neighbors function.</p>
<p>Suppose, then, we swap out the rectangular grid for a hexagonal one. There are <a href="http://www.redblobgames.com/grids/hexagons/">many possible hexagonal grid coordinate systems</a>, so I’ve chosen one arbitrarily, and to make it brief, each cell has six neighbors instead of eight, and we can generate them all with a slightly different function:</p>
<div class="sourceCode" id="cb11"><pre class="sourceCode clojure"><code class="sourceCode clojure"><a class="sourceLine" id="cb11-1" title="1">(define (neighbors-hex location)</a>
<a class="sourceLine" id="cb11-2" title="2">  (<span class="kw">let</span> ([x (<span class="kw">first</span> location)]</a>
<a class="sourceLine" id="cb11-3" title="3">        [y (<span class="kw">last</span> location)])</a>
<a class="sourceLine" id="cb11-4" title="4">    (for*/list ([dx &#39;(-<span class="dv">1</span> <span class="dv">0</span> <span class="dv">1</span>)]</a>
<a class="sourceLine" id="cb11-5" title="5">                [dy &#39;(-<span class="dv">1</span> <span class="dv">0</span> <span class="dv">1</span>)]</a>
<a class="sourceLine" id="cb11-6" title="6">                #<span class="at">:when</span> (<span class="kw">and</span> (<span class="kw">not</span> (<span class="kw">=</span> dx dy <span class="dv">1</span>))</a>
<a class="sourceLine" id="cb11-7" title="7">                            (<span class="kw">not</span> (<span class="kw">=</span> dx dy <span class="dv">-1</span>))</a>
<a class="sourceLine" id="cb11-8" title="8">                            (<span class="kw">not</span> (<span class="kw">=</span> dx dy <span class="dv">0</span>))))</a>
<a class="sourceLine" id="cb11-9" title="9">      (<span class="kw">list</span> (<span class="kw">+</span> x dx) (<span class="kw">+</span> y dy)))))</a></code></pre></div>
<p>By swapping out <code>neighbors-rect</code> for <code>neighbors-hex</code> in our definition of life, we can work on a hexagonal grid. No other code needs to change except for how we draw the grid.</p>
</section>
<section class="footnotes">
<hr />
<ol>
<li id="fn1"><p>Animation from <a href="https://commons.wikimedia.org/wiki/File:Gospers_glider_gun.gif#">Wikimedia Commons</a>.<a href="#fnref1" class="footnote-back">↩</a></p></li>
<li id="fn2"><p>I apologize for the minimal syntax highlighting. <a href="http://pandoc.org/">pandoc</a>’s syntax highlighting library doesn’t support Racket yet, so I’m using the Clojure highlighting, which doesn’t recognize most of Racket’s keywords.<a href="#fnref2" class="footnote-back">↩</a></p></li>
</ol>
</section>]]></description>
    <pubDate>Mon, 25 Jan 2016 00:00:00 UT</pubDate>
    <guid>https://www.refsmmat.com/posts/2016-01-25-conway-game-of-life.html</guid>
    <dc:creator>Alex Reinhart</dc:creator>
</item>
<item>
    <title>Review: Neil Postman's 'Amusing Ourselves to Death'</title>
    <link>https://www.refsmmat.com/posts/2016-01-23-amusing-ourselves-to-death.html</link>
    <description><![CDATA[<p><em>Amusing Ourselves to Death</em> is interesting both for its arguments and the realization that things have gotten much, much worse since it was published in 1985. The key to Postman’s argument is that <em>the medium affects the message</em>: yes, you can say the same thing on TV as you would in print, but you probably won’t. To illustrate this, Postman begins by describing typographic America: America in the 1800s, before the invention of photography or the telegraph, when nearly every aspect of public discourse occurred in print. Print is a great format for argumentation—for laying out logical propositions and supporting evidence—because it is susceptible to careful analysis: arguments laid in front of you on a page can be dissected and examined any way you want.</p>
<p>Discourse not in print, like the many popular public lectures and speeches, was heavily inspired by print—public speakers used language and syntax that very much sounds like it was written, with complex multiclause sentences and subtle arguments.<a href="#fn1" class="footnote-ref" id="fnref1"><sup>1</sup></a> People were expected to carefully listen to hours of public debates and lectures. The inherent biases of print shaped the rest of our culture.</p>
<p>Then came the telegraph and the explosion of irrelevance. Suddenly we were deluged with information which, we claimed, stood on its own merits—that is, information with no inherent use except as information. What are we to do about the latest Middle East conflict or political dispute? Or the price of beans in New Brunswick? We can vote, but voting is a blunt instrument, and our only other option is, essentially, to answer opinion polls and simply become more news. Worse, rapid-fire media like radio and television are intrinsically unsuitable for detailed exposition and argument, and so they now aim to <em>amuse</em>, not to inform. Postman puts this change pithily:</p>
<blockquote>
<p>“We might even say that America was founded by intellectuals, from which it has taken us two centuries and a communications revolution to recover.”</p>
</blockquote>
<p>I can see the point here. Read the <em>New York Times</em> (or, hell, the <em>Daily Mail</em>) every day for a week and you’ll find very little you can actually act upon. Maybe something that will influence how you vote,<a href="#fn2" class="footnote-ref" id="fnref2"><sup>2</sup></a> maybe a book or product you want to buy, but most of the news items are irrelevant. Since 1985, things have gotten worse: the <em>Daily Mail</em>, Buzzfeed, and most of online media are aimed at brief moments of amusement (through listicles and animated GIFs), so much so that long-form articles are rare enough to have <a href="https://longform.org/">their own website curating them</a>. We no longer carefully examine political discourse, and politicians know better than to attempt using sophisticated and subtle arguments in TV debates where they have only 30 seconds to provide a soundbite.</p>
<p>The Internet would horrify Postman. Now, not only do we demand that everything amuse us, we leave if it fails to amuse us within two or three seconds. Slow page load? Back! <a href="https://www.reddit.com/">Reddit</a> is the epitome of this: the default front page is people voting on what amuses them most. Comment threads are either puns (rapid-fire amusement) or funny stories, a few paragraphs at most. Political discourse is reduced to one-line expressions of outrage or disbelief. Serious discussion cannot survive unless determined moderators ruthlessly delete amusing posts.<a href="#fn3" class="footnote-ref" id="fnref3"><sup>3</sup></a></p>
<p>In short, we’re way past the Kodak moment. We live in search of the tweetable moment.</p>
<p>This much is easy to see. But: of all the long-form writing and arguments the so-called typographic Americans were digesting, what fraction was relevant? What fraction were actually informative? Were they reading for recreation, or were they reading about issues that mattered to them? Postman ignores this question entirely. Perhaps they were all reading about getting the best soybean crop or reading about politics and vigorously participating in the local city council, but I have no idea what people did on average, and it’s not clear that all the careful analysis amounted to anything. Just how rosy is Postman’s view of the 1800s?</p>
<p>I also wonder about quantitative support for Postman’s argument. As far as I know, books are selling more than ever, and I recall a <a href="http://www.theguardian.com/books/2015/dec/10/are-books-getting-longer-survey-marlon-james-hanya-yanagihara">recent article</a> suggesting that fiction has been getting longer and longer over the years. If this is what we’d expect given Postman’s hypothesis? Or are the books less complex, more padded, despite the increased length? I don’t know how you’d evaluate that, though modern popular nonfiction does often seem content-free.</p>
<p>More broadly, there’s a possible quantitative counter-argument to Postman: in “typographic America”, print was the dominant medium, but it was also <em>small</em>. There wasn’t anything like the volume of publishing we see today, with everything from big publishing houses down to self-published authors and random people with blogs. More people participate in typographic media than ever before. It may be a smaller fraction of overall media consumption than it used to be, drowned in hours of Netflix and HBO, but in absolute terms it is enormously larger than it was in the 1800s. Of course, television and the GIF side of the Internet are crushingly larger, and they dictate popular culture and views. Donald Trump exists because he doesn’t need a coherent argument, just <a href="https://www.youtube.com/watch?v=F5zjVUZA7rY">fabulous sound bites</a>. Politics, news, and business are driven by non-typographic media. It doesn’t matter how large print is—it has lost the battle.</p>
<p>On an unrelated note,<a href="#fn4" class="footnote-ref" id="fnref4"><sup>4</sup></a> I also wonder how Postman would react to the recent emergence of TV dramas with long, complicated plots spread over entire seasons. They are, of course, still intended to amuse instead of inform, but they expect more than complete passivity from their viewers, who are expected to keep track of legions of characters and plot details over weeks or months. I suppose this is the medium shaping the message again: Netflix means a binge-watcher can down an entire season in an afternoon, so instead of four hours of unrelated programs, he can get four or five hours of a single continuous plot. Or, in other words, long story arcs became popular as soon as it was possible to time-shift them with DVRs, Netflix, and DVD boxed sets.</p>
<p>Overall, I enjoyed <em>Amusing Ourselves to Death</em>, and it’s a fascinating subject to think about.<a href="#fn5" class="footnote-ref" id="fnref5"><sup>5</sup></a> I just wish Postman were around to update the book to the modern era, and that he could marshal more evidence to his positions.</p>
<section class="footnotes">
<hr />
<ol>
<li id="fn1"><p>I assume this is why dialogue in old novels always seems so improbable—nobody talks in long convoluted sentences anymore. They probably don’t even know how to <a href="https://www.youtube.com/watch?v=lQ91SVKryYU">properly pronounce punctuation</a>.<a href="#fnref1" class="footnote-back">↩</a></p></li>
<li id="fn2"><p>That’s optimistic. Normally we just see things we use to justify the voting decisions we’ve already made.<a href="#fnref2" class="footnote-back">↩</a></p></li>
<li id="fn3"><p>Perhaps as a reaction to reddit, <a href="https://news.ycombinator.com/">Hacker News</a> has a strong social taboo against puns and jokes, which are instantly downvoted. Instead, its users avoid serious discussion with <a href="http://www.byrnehobart.com/blog/why-are-middlebrow-dismissals-so-tempting/">middlebrow dismissals</a> and pointless arguments about pointless details.<a href="#fnref3" class="footnote-back">↩</a></p></li>
<li id="fn4"><p>Postman’s most hated feature of modern media is its tendency to say “Now, this”—to drop one subject after thirty seconds of consideration and move to something completely different, tacitly admitting that you won’t pay attention unless they keep you amused with new things. This paragraph hence feels transgressive.<a href="#fnref4" class="footnote-back">↩</a></p></li>
<li id="fn5"><p>He says, in between checking Twitter, Facebook, and Hacker News for updates. Apparently it didn’t stick.<a href="#fnref5" class="footnote-back">↩</a></p></li>
</ol>
</section>]]></description>
    <pubDate>Sat, 23 Jan 2016 00:00:00 UT</pubDate>
    <guid>https://www.refsmmat.com/posts/2016-01-23-amusing-ourselves-to-death.html</guid>
    <dc:creator>Alex Reinhart</dc:creator>
</item>

    </channel>
</rss>
