**Peter's stats stuff - R**, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)

Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Disclaimer on all that follows – I am not an earthquake scientist and have cobbled together this post from sources like Wikipedia, official open data, and a range of information sites. There may be mistakes and misinterpretations that follow.

## Energy release from earthquakes is extremely variable

My last blog post left me interested in finding out more about energy generated by earthquakes and how it relates to magnitude. I was vaguely aware that magnitude was on a logarithmic scale so *something* is ten times the size for increase of one in magnitude, but it turns out that that is the shaking amplitude. Energy is going to be proportionate to to the power of magnitude, which means an increase in one magnitude point increases the energy released by about 31.6. Here’s an R function I cobbled together to convert earthquake magnitudes into rough equivalent megatons of TNT, a measure usually used to measure the oomph of nuclear weapons.

The pie chart that I had taken from the media and polished up in my last post, which showed how much of the earthquake energy in recent years came in a single day last weekend, had a slightly naughtily chosen starting point of 2010. Extending this a year back would have made the pie chart much more nuanced. But rather than battle it out with pie charts, I downloaded all the data on individual earthquakes (some of them back to well before 1800!) from the https://quakesearch.geonet.org.nz site, converted each magnitude to energy (ignoring for my purposes the nuances of different ways that magnitudes were measured and slightly different scales), and aggregated the total energy up by day. That delivered this revealing chart (note that dates are in Greenwich mean time, which is not how earthquakes’ dates are usually referred to locally of course):

Yes, the 2009 Dusky Sounds earthquake and last weekend’s Kaikoura earthquake dwarf everything back until the 1855 Wairarapa earthquake. It should be noted that the further back this chart goes, the more it underestimates total energy released, because only very major events have estimates and the energy released by aftershocks and day to day events were not recorded. Even in the instrument-measured era, the instruments have changed over time.

This is a good reminder that destructiveness is only weakly related to magnitude. Obviously, location, depth and timing are key factors. While the Canterbury earthquakes in 2010 and 2011 were low energy relative to the larger ones New Zealand has experienced, they were devasting to life and property.

## Maps should show the energy more

This exercise made me think about the maps which are commonly drawn of earthquakes, with the area of points representing the magnitude. In fact, to avoid misleading, it might be better for the area to represent on a non-logarithmic scale the shaking or the energy released. This would make maps look more like this one:

Big events like last Sunday night release so much energy that everything else looks like a pin prick in comparison.

## Some interesting historical patches

One thing I was interested in was the largest magnitude earthquake in any particular day, so I made this graphic:

Those are some interesting periods of time, where for a reasonable proportion of days the largest magnitude earthquake was not particularly large. So that prompted me to wonder if there was a connection between the number of earthquakes and their average and maximum magnitudes. There is in fact a relationship of that sort in the data, but it looks to be an artefact of the improving measurement – the better the monitors get, the more small earthquakes they pick up and record, which gives the impression that over time there are more and more earthquakes but on average they are getting smaller. Discovering this was one of the things that made me want to estimate energy and aggregate it, so the plethora of small low energy earthquakes don’t warp the overall picture. To mitigate the impact of improving measurement over time, I knock out all earthquakes of magnitude less than two before estimating total energy. I don’t think this would have much substantive impact.

Here is an interesting image of the number of earthquakes of magnitude two or higher:

That’s a very marked drop in 2012. So marked in fact that my first reaction was to think there might have been a change in how the measurement was happening. A quick google didn’t reveal what was going on there. Anyone who knows – whether it’s a bug in my code, or something more interesting – please leave a comment!

## Total energy on a logarithmic scale

While the first graphic in this post is good at showing the rarity of the really high energy earthquake events, it’s no good at showing trends over time. The simpler plots just above, looking at the biggest earthquake each day and the number of earthquakes greater than magnitude two each day, are not satisfactory either.

Putting daily total earthquake energy on a logarithmic scale is a good way to visually inspect for trends. At a medium time scale, we see again that drop in energy in early 2012, and an irregular cycle of spikes. The blue line in the next three graphics shows a 60 day moving average:

Here’s the code behind all that. As I’m not sure geonet would be thrilled at people copying my code and doing bulk downloads, I’ve saved a copy of the cut down data needed to reproduce this on my own site. The actual source code to download it is simple enough and is available in the .

**leave a comment**for the author, please follow the link and comment on their blog:

**Peter's stats stuff - R**.

R-bloggers.com offers

**daily e-mail updates**about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.

Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.