<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">

  <title><![CDATA[Category: R | Kieran Healy]]></title>
  <link href="http://kieranhealy.org//blog/categories/r/atom.xml" rel="self"/>
  <link href="http://kieranhealy.org//"/>
  <updated>2013-05-15T18:29:34-04:00</updated>
  <id>http://kieranhealy.org//</id>
  <author>
    <name><![CDATA[Kieran Healy]]></name>
    
  </author>
  <generator uri="http://octopress.org/">Octopress</generator>

  
  <entry>
    <title type="html"><![CDATA[Updates to the Emacs Starter Kit for the Social Sciences]]></title>
    <link href="http://kieranhealy.org//blog/archives/2012/04/23/updates-to-the-emacs-starter-kit-for-the-social-sciences/"/>
    <updated>2012-04-23T09:09:00-04:00</updated>
    <id>http://kieranhealy.org//blog/archives/2012/04/23/updates-to-the-emacs-starter-kit-for-the-social-sciences</id>
    <content type="html"><![CDATA[<p>I've made some updates to the <a href="http://kieranhealy.org/emacs-starter-kit.html">Emacs Starter Kit for the Social Sciences</a>. The kit builds on Phil Hagelberg's original and <a href="http://eschulte.me/emacs24-starter-kit/">Eric Schulte's</a> org-mode version, and incorporates some packages and settings that are particularly useful for the social sciences. See the <a href="http://kieranhealy.org/emacs-starter-kit.html">Starter Kit's Homepage</a> for more details. The new version requires Emacs 24, which is not quite officially released but is in very good shape. See <a href="http://kieranhealy.org/emacs-starter-kit.html">the project page</a> for more information about what's included in the starter kit and how to install it.</p>

<p>The latest version is a little more streamlined than before, because we can now take advantage of the package-management system that comes standard with Emacs 24. So, several packages that had been bundled-in with the starter kit are now fetched during installation instead. ESS is <a href="https://github.com/emacs-ess">now on github</a>, which makes it possible to include it as a submodule. The color theming now uses Emacs 24's native theming system, not the color-theme package.</p>

<p>I also removed the org-mode submodule, as an up-to-date version of it now comes with Emacs 24. Ideally I'll shortly be able to do this for ESS, too, as it ought to be installable as a package.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Visualizing iOS Text Editors]]></title>
    <link href="http://kieranhealy.org//blog/archives/2012/04/18/visualizing-ios-text-editors/"/>
    <updated>2012-04-18T13:06:00-04:00</updated>
    <id>http://kieranhealy.org//blog/archives/2012/04/18/visualizing-ios-text-editors</id>
    <content type="html"><![CDATA[<p>The other day <a href="http://brettterpstra.com/ios-text-editors/">Brett Terpstra posted</a> a gigantic and quite beautifully-executed feature comparison of all of the text editors available for iOS devices. The table is really terrific and also a bit overwhelming, as there's so much data. On the bus home yesterday, it struck me that it might make for a nice data  visualization exercise. There are all kinds of ways one might choose to represent the information, of course---how you visualize data depends on what you want to do with it.  Brett's way of presenting it is great, not least because of the way it's styled and augmented with dynamic touches which are all way beyond me. Naturally, it's focused on looking at the features of specific editors. I found myself wondering whether the information in the table could be used to highlight similarities and differences between editors and features, and maybe find whether there is any coherence in feature-sets and the editors that offer them.</p>

<p>I made a CSV file of the table and dumped it into R. Here's a reproduction of Brett's table as a figure, with blocks of color for the data values. The figure was produced with ggplot.</p>

<p><img class="center" src="http://kieranhealy.org/files/misc/spec-cluster-alphabetical.png" title="&#34;A version of the original table.&#34;" alt="&#34;A version of the original table.&#34;">
<em>A version of the original table.</em> (<a href="http://kieranhealy.org/files/misc/spec-cluster-alphabetical.png">PNG</a> or a <a href="http://kieranhealy.org/files/misc/spec-cluster-alphabetical.pdf">PDF</a> of this.)</p>

<p>The apps are ordered alphabetically from top to bottom, and the features are grouped as presented in the original table---columns are grouped left to right under by Platform, Sync capabilities, Export options, and miscellaneous other features. (Note that I've omitted the price information in this version.) If you're interested in specific editors, you can look at their features across the rows, and you can see the prevalence of particular features looking down the columns.</p>

<p>What if we just wanted to get a bird's-eye sense of the sort of features that tend to go together, or which editors are similar to one another in terms of their features? We can  cluster editors by features they share. Here's one way of doing that:</p>

<p><img class="center" src="http://kieranhealy.org/files/misc/cluster-by-name.png" title="&#34;Editor clustering.&#34;" alt="&#34;Editor clustering.&#34;">
<em>Clustering Editors</em> (<a href="http://kieranhealy.org/files/misc/cluster-by-name.png">PNG</a>, <a href="http://kieranhealy.org/files/misc/cluster-by-name.pdf">PDF</a>.)</p>

<p>The dendrogram suggests some hypotheses about groups of editors that are similar. I've only used one or two of these products, so it's hard for me to say whether it's a plausible clustering overall. The fine-grain of it seems pretty decent, with, e.g., Gusto and Gusto Mobile ending up adjacent to each other. Two of the apps I've used (Writing Kit and Notesy) are also close to one another, and far away from apps like Vim and AppWriter, which in turn are close to one another.</p>

<p>We can cluster features as well as clustering the apps themselves:</p>

<p><img class="center" src="http://kieranhealy.org/files/misc/cluster-by-feature.png" title="&#34;Feature clustering.&#34;" alt="&#34;Feature clustering.&#34;">
<em>Clustering Features</em> (<a href="http://kieranhealy.org/files/misc/cluster-by-feature.png">PNG</a>, <a href="http://kieranhealy.org/files/misc/cluster-by-feature.pdf">PDF</a>.)</p>

<p>This arranges the feature set a little differenty from the original table. There's one broad set of clusters around HTML and Markdown support; syncing features <em>except</em> Dropbox (e.g. WebDAV, iTunes, proprietary, etc) together with Text search, and Browser/URL support. Then there's Price, sort of by itself, and a second clustering around Platform, live-editing features such as word count and appearance options, printing, Dropbox, and TextExpander support.</p>

<p>If we take the orderings yielded by the cluster analyses and apply them to the table---i.e., permute the rows according to the editor clustering and the columns according to the feature clustering we get this:</p>

<p><img class="center" src="http://kieranhealy.org/files/misc/spec-cluster-full.png" title="&#34;Clustered Table.&#34;" alt="&#34;Clustered Table.&#34;">
<em>Re-ordering the table based on the clustering</em> (<a href="http://kieranhealy.org/files/misc/spec-cluster-full.png">PNG</a>, <a href="http://kieranhealy.org/files/misc/spec-cluster-full.pdf">PDF</a>.)</p>

<p>The clustering reorganizes the features and editors pretty well---reading across the rows you can now see the editors which implement simlilar feature sets. Looking down the columns we can see (to the right) the set of features that most of the editors implement, and (toward the left) the features which are much less common. They're separated by a couple of features which most editors either don't support or for which information is unavailable right now.</p>

<p>Finally, we can facet the rows of the table according to the price of the app:</p>

<p><img class="center" src="http://kieranhealy.org/files/misc/spec-cluster-by-price.png" title="&#34;Clustered Table with Prices.&#34;" alt="&#34;Clustered Table with Prices.&#34;">
<em>Faceting on Price</em> (<a href="http://kieranhealy.org/files/misc/spec-cluster-by-price.png">PNG</a>, <a href="http://kieranhealy.org/files/misc/spec-cluster-price.pdf">PDF</a>.)</p>

<p>This suggests to me that there isn't a straightforward relationship between features and price. The green tiles don't become more and more common as you go down the rows from free apps to the most expensive ones. There is <em>some</em> relationship: you can see that the apps priced at $1.99 or below are not as feature-rich as those priced at $2.99 or above. But within each of those broad classes features are about the same.</p>

<p>Of course, not all features are equally important, and lists of features---even one as extensive as this---won't capture everything about an app. But it's fun to look for patterns here, especially given that the sheer number of text-editing apps available is so large.</p>

<p>If you are interested, the code and data used to make the plots are in <a href="https://github.com/kjhealy/editors">this github repo</a>.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Text Editors in The Lord of the Rings]]></title>
    <link href="http://kieranhealy.org//blog/archives/2011/07/29/text-editors-in-the-lord-of-the-rings/"/>
    <updated>2011-07-29T22:05:44-04:00</updated>
    <id>http://kieranhealy.org//blog/archives/2011/07/29/text-editors-in-the-lord-of-the-rings</id>
    <content type="html"><![CDATA[<p>Prompted by <a href="https://twitter.com/#!/kjhealy/status/97107896885719041">a passing thought</a> about TextMate, I thought I'd make a comprehensive, accurate, unbiased, and irrefutable survey of text editors by way of comparison to locations in <em>The Lord of the Rings</em>.</p>

<h3>TextMate: Minas Tirith</h3>

<p><img src="http://kieranhealy.org/files/misc/minastirith.jpg" alt="image" /></p>

<p>A once-great but now decaying city. Only the King has the power to renew it, but he is a long absent, indeed half-legendary figure—though there are persistent rumors that he is alive still in some distant land. In his stead, the city slowly falls in upon itself, kept in some sort of working order by its melancholy people. They can repair but not truly rebuild it, and they pray daily for the Return of the King.</p>

<h3>BBEdit: The Shire</h3>

<p><img src="http://kieranhealy.org/files/misc/shire.jpg" alt="image" /></p>

<p>A quiet, long-overlooked land populated by simple folk who keep mostly to themselves. They are somewhat set in their ways, awkward in their manners, and superficially incapable of apparently simple tasks. Yet they hide deep roots and unexpected strengths.</p>

<h3>Emacs: Fangorn</h3>

<p><img src="http://kieranhealy.org/files/misc/fangorn.jpg" alt="image" /></p>

<p>Vast, ancient, gnarled and mostly impenetrable, tended by a small band of shepherds old as the world itself, under the command of their leader, Neckbeard. They possess unbelievable strength, are infuriatingly slow, and their land is entirely devoid of women. It takes forever to say anything in their strange, rumbling language.</p>

<h3>Sublime Text 2: The Grey Havens</h3>

<p><img src="http://kieranhealy.org/files/misc/greyhavens.jpg" alt="image" /></p>

<p>Gateway to Valinor, the elvish paradise. The chosen ones goto anything there, and never again return to this fallen realm. "The grey rain curtain of this world rolls back, and all turns to silver glass. And then you see it. White shores. And beyond, a far green country under a swift sunrise, with multiple cursors."</p>

<h3>vi: Moria</h3>

<p><img src="http://kieranhealy.org/files/misc/moria.jpg" alt="image" /></p>

<p>Like Fangorn, ancient and deep, with hints of the long labor of a great people. There is, supposedly, a monumental city of stone down here somewhere but it's so dark I can't see a damn thing. No, wait! A shaft of light illuminates some runes! <a href="http://bash.org/?795779">They read as follows</a>:</p>

<p><code>^C^X^X^Xquit  qQ!qdammit[esc]qwertyuiopasdfghjkl;  :xwhat</code></p>

<p>The Wizard translates: "We cannot get out! We cannot get out! They are coming!"</p>

<h3>Microsoft Word: Barad-dur</h3>

<p><img src="http://kieranhealy.org/files/misc/baraddur.jpg" alt="image" /></p>

<p>No need to explain this one.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Workflow Articles in "The Political Methodologist"]]></title>
    <link href="http://kieranhealy.org//blog/archives/2011/04/01/workflow-articles-in-the-political-methodologist/"/>
    <updated>2011-04-01T10:43:15-04:00</updated>
    <id>http://kieranhealy.org//blog/archives/2011/04/01/workflow-articles-in-the-political-methodologist</id>
    <content type="html"><![CDATA[<p>I've written a few times before about how to choose the software you work with, and what you should and should not care about when making those choices. I maintain a page <a href="http://www.kieranhealy.org/resources.html">with various resources</a> related to this, if you're interested, most notably the <a href="http://kjhealy.github.com/emacs-starter-kit/">Emacs Starter Kit for the Social Sciences</a>. A revised version of an article of mine on this topic called "Choosing Your Workflow Applications", which I've had online for a while, has now been published in <a href="http://polmeth.wustl.edu/methodologist/tpm_v18_n2.pdf">The Political Methodologist</a>, the newsletter of the <a href="http://polmeth.wustl.edu">Society for Political Methodology</a>. (The <a href="https://github.com/kjhealy/workflow-paper">source document</a> for my article is also available, as I wanted the piece to walk its own talk.) There are also some great contributions from others along similar lines, covering different aspects of setting up and running your research so that you can collaborate easily, remember what you did, easily revisit work when needed, and do good, reproducible social science in a relatively hassle-free way. I think the issue as a whole is something that grad students in any social science program—especially those just starting out—could benefit from reading, and there's a lot there for faculty to chew on, too.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Aligning labels in circular igraph layouts]]></title>
    <link href="http://kieranhealy.org//blog/archives/2011/02/18/aligning-labels-in-circular-igraph-layouts/"/>
    <updated>2011-02-18T21:57:05-05:00</updated>
    <id>http://kieranhealy.org//blog/archives/2011/02/18/aligning-labels-in-circular-igraph-layouts</id>
    <content type="html"><![CDATA[<p><img src="http://kieranhealy.org/files/misc/ipe-unc-graph.png" alt="IPE financial integraption network " /></p>

<p>The folks at <a href="http://ipeatunc.blogspot.com/2011/02/modeling-global-financial-integration.html">IPE at UNC</a> have produced this <a href="http://dl.dropbox.com/u/14507110/pdfout.gif">nice animated gif</a> of some network data on increasing financial integration in the run-up to the 2008 crisis. They used a small trick I <a href="http://www.kieranhealy.org/blog/archives/2010/03/04/lists-and-loops-in-r/">pointed to</a> a while ago (just using a pipe, nothing fancy) that lets you generate the gif from within R without tediously typing in filenames. Then they ask,</p>

<blockquote><p>Also, a nerdy request: I wasn't able to find a way to put the country labels outside the graph, next to the nodes. I.e., I can move all the labels up or down, left or right, some constant distance. But I want to move them all outward so they sit next to their respective nodes, rather than above/below/to the side of the node. They would be more clearly visible that way. Any suggestions? I'm using igraph, because it supports tnet, so it would have to be something that works with those packages.</p></blockquote>

<p>So, with a circular graph layout, how to get the labels aligned nicely? Here's an approach that I think will work, and should generalize to however many vertices you have around the circle. The igraph documentation says that the alignment of a label with respect to its vertex is controlled by <code>vertex.label.degree</code>, and that</p>

<blockquote><p>It is interpreted as an angle in radian, zero means 'to the right', and 'pi' means to the left, up is -pi/2 and down is pi/2. The default value is pi/4</p></blockquote>

<p>As is common in R, you can give this parameter a scalar argument (0, say, so all labels are aligned to the right) but it will also accept a vector. Because we're plotting the entire graph in a circle, and igraph lays out its nodes predictably when plotting in a circle, we can take advantage of this and calculate the right position for each label with respect to its vertex given the vertex's position on the big circle. Like this:</p>

<script src="https://gist.github.com/834774.js?file=polar-labels.r"></script>


<p>This gives us a graph with a nice layout, like this:</p>

<p><img src="http://kieranhealy.org/files/misc/circle-labels.png" alt="circular igraph with properly-aligned labels" /></p>

<p>I think this is what they're looking for.</p>
]]></content>
  </entry>
  
</feed>
