Gini Coefficients and the Olympic Medal Race

Today’s post will attempt to answer a provocative question: is the race for Olympic medal dominance getting more competitive? In the process of addressing this topic, we’ll learn how to directly import data from WolframAlpha into Mathematica.

If you watched any of the Olympics over the past two weeks, you likely became familiar with the medal count table. This table is a grossly reductionist metric of national achievement at the Olympics. Nonetheless, it provides a useful way to quantify the aggregate performance of different nations.

The United States took home 104 medals from the 2012 games, placing it at the top of the medal table. The race for the most medals was exciting, though, as China and Russia were not far behind.

Continue reading “Gini Coefficients and the Olympic Medal Race” »

Six little data points and one huge story

It has been an exciting summer in science news. In early July, CERN announced the probable discovery of a Higgs-like particle at the Large Hadron Collider, filling a long open hole in the standard model of physics. On Sunday, the Curiosity rover successfully executed a phenomenally difficult landing on Mars.

Sandwiched between these headline-grabbing events, a story of arguably equal significance has been overshadowed: evidence from the remote Amazon that unvaccinated humans can develop antibodies to rabies.

Rabies is a scary disease (jokes on The Office notwithstanding). It causes approximately 55,000 deaths annually. Victims suffer anxiety, hallucinations, delirium, paralysis and eventually death. It is hard to imagine a more horrific way to die.

Continue reading “Six little data points and one huge story” »

Transformation of axes in R

As a general rule, you should not transform your data to try to fit a linear model. But proportions can be tricky. If the proportion data do not arise from a binomial process (e.g., proportion of a leaf consumed by a caterpillar), then transformation is still the best option. In an excellent paper, David Warton* and Francis Hui propose that the conventional transformation for proportion data (i.e., arcsine square root) is asinine, particularly if you have binomial data, and that the logit transformation is preferable for non-binomial proportion data.

The objective of this post is simply to demonstrate how to transform the axes of plots in R, but the context of the example is the logit transformation of non-binomial proportion data. First, we need to generate some data.

Continue reading “Transformation of axes in R” »

Spacing of multi-panel figures in R

In a previous post, I showed how to keep text and symbols at the same size across figures that have different numbers of panels. The figures in that post were ugly because they used the default panel spacing associated with the mfrow argument of the par( ) function. Below I will walk through how to adjust the spacing of the panels when using mfrow.

Continue reading “Spacing of multi-panel figures in R” »

A Traveling Salesman on a Sphere: Pitbull’s Arctic Adventure

You’ve probably heard of the traveling salesman problem: given a set of cities, what is the shortest possible route that visits each city exactly once and returns to the origin city? This problem pops up in a huge number of applications.

For the purposes of this post, let’s focus on a concrete example: a musician is planning a tour and wants to travel as efficiently as possible. Suppose that concerts are to be held in the following cities (with an encore concert in the origin city): Anchorage, Athens, Barrow, Berlin, Brussels, Cairo, Copenhagen, Denver, Detroit, Dublin, Helsinki, Istanbul, Jerusalem, Kabul, Lagos, Lisbon, London, Los Angeles, Miami, Moscow, Murmansk, New York, Prague, Reykjavik, Rome, Seattle, Stockholm, and Toronto.

Perhaps you’ll object that this is an unlikely list, because it includes several high latitude cities with limited concert venues. Musicians can get sent to some pretty obscure locations, though. Take the rapper Pitbull’s recent trip to Kodiak, for example. Bear with me.

Fortunately, Mathematica has a built-in function, FindShortestTour to help compute the solution to our problem. Before we get too excited, though, we should remember that the world is not flat, and hence we won’t be able to use our usual Euclidean distance metric.

Continue reading “A Traveling Salesman on a Sphere: Pitbull’s Arctic Adventure” »

Text and symbol size in multi-panel figures in R

In R, there are a couple of packages that allow you to create multi-panel figures (see examples here and here), but, of course, you can also make multi-panel figures in the base package*. Below I provide a simple example for creating a multi-panel figure in the R base package with the focus on making the text and symbols the same size in all of your figures, which is a desirable trait for a set of figures that will appear in the same manuscript.

Continue reading “Text and symbol size in multi-panel figures in R” »

Voronoi Diagrams in Mathematica

Ecological models sometimes find very unexpected applications. Work on wolf territory modeling by Mark Lewis’s research group at the University of Alberta has been employed by researchers studying gang territories in Los Angeles. You can check out that paper by Smith, Bertozzi, Tita, and Valasik in the September 2012 issue of the Journal of Discrete and Continuous Dynamical Systems.

This Smith et al. paper uses Voronoi diagrams as a null model for territorial use. Voronoi diagrams pop up in modeling forest canopy structure, and a variety of other ecological applications. Given the their utility, I am devoting today’s post to an overview of computing and displaying them in Mathematica.

Continue reading “Voronoi Diagrams in Mathematica” »

Call it the decline and fall of popular music… maybe?

You’ve probably already experienced the agony that accompanies an infection of Carly Rae Jepsen’s inane earworm “Call Me Maybe”. You’ve probably also been subjected to the current number one song in America, Flo Rida’s “Whistle”, a ditty whose only creative merit is its ability to evade censorship despite its explicit subject material. These two songs are representative of a dismaying trend in popular music: songs are becoming symphonically simpler and more predictable.

Were Mr. Rida to read my pretentious lament over the state of popular music, he would undoubtedly counter that I lack data to support my claim. Do I have metrics to quantify a song’s banality? No. Fortunately, a group of researchers lead by Joan Serra of the Artificial Intelligence Research Institute in Spain does. In a recent Nature paper, “Measuring the Evolution of Contemporary Western Popular Music”, Serra’s team concludes that popular music is headed “towards less variety in pitch transitions, towards a consistent homogenization of the timbral palette, and towards louder and, in the end, potentially poorer volume dynamics.” So yes, Mr. Rida, there is science behind my assertion that popular music is becoming increasingly stupid.

Continue reading “Call it the decline and fall of popular music… maybe?” »