Blog Archives

user2013: The caret tutorial

July 9, 2013
By
user2013: The caret tutorial

This afternoon I went to Max Kuhn’s tutorial on his caret package. caret stands for classification and regression (something beginning with e) trees. It provides a consistent interface to nearly 150 different models in R, in much the same way as the plyr package provides a consistent interface to the apply functions. The basic usage

Read more »

user2013: The Rcpp tutorial

July 9, 2013
By
user2013: The Rcpp tutorial

I’m at user 2013, and this morning I attended Hadley Wickham and Romain Francois’s tutorial on the Rcpp package for calling C++ code from R. I’ve spent the last eight years avoiding C++ afer having nightmares about obscure pointer bugs, so I went into the room slightly skeptical about this package. I think the most

Read more »

A brainfuck interpreter for R

April 24, 2013
By
A brainfuck interpreter for R

The deadline for my book on R is fast approaching, so naturally I’m in full procrastination mode.  So much so that I’ve spent this evening creating a brainfuck interpreter for R.  brainfuck is a very simple programming language: you get an array of 30000 bytes, an index, and just 8 eight commands.  You move the

Read more »

Have my old job!

November 14, 2012
By
Have my old job!

My old job at the Health & Safety Laboratory is being advertised, and at a higher pay grade to boot.  (Though it is still civil service pay, and thus not going to make you rich.) You’ll need to have solid mathematical modelling skills, particularly solving systems of ODEs, and be proficient at writing scientific code,

Read more »

Indexing with factors

November 8, 2012
By
Indexing with factors

This is a silly problem that bit me again recently. It’s an elementary mistake that I’ve somehow repeatedly failed to learn to avoid in eight years of R coding. Here’s an example to demonstrate. Suppose we create a data frame with a categorical column, in this case the heights of ten adults along with their

Read more »

Make your data famous!

October 30, 2012
By
Make your data famous!

I’m writing a book on R for O’Reilly, and I need interesting datasets for the examples. Any data that you provide will get you a mention in the book and in the publicity material, so it’s a great opportunity to publicise your work or your organisation. Datasets from any area or industry are suitable; the

Read more »

Look ma! No typing! Autorunning code on R startup

July 20, 2012
By
Look ma! No typing! Autorunning code on R startup

Regular readers may know that I often make R-based GUIs. They’re great for giving non-technical users safe and easy access to statistical models. The safety comes from the restrictions of a GUI: you can limit what the users does more easily than with a command line, helping to reduce the number of opportunities for bad

Read more »

How long does it take to get pregnant?

June 15, 2012
By
How long does it take to get pregnant?

My girlfriend’s biological clock is ticking, and so we’ve started trying to spawn. Since I’m impatient, that has naturally lead to questions like “how long will it take?”. If I were to believe everything on TV, the answer would be easy: have unprotected sex once and pregnancy is guaranteed. A more cynical me suggests that

Read more »

Be assertive!

May 30, 2012
By
Be assertive!

assertive, my new package for writing robust code, is now on CRAN. It consists of lots of is functions for checking variables, and corresponding assert functions that throw an error if the condition doesn’t hold. For example, is_a_number checks that the input is numeric and scalar. In the last two cases, the return value of

Read more »

Benford’s Law and fraud in the Russian election

March 5, 2012
By
Benford’s Law and fraud in the Russian election

Earlier today Ben Goldacre posted about using Benford’s Law to try and detect fraud in the Russian elections. Read that now, or the rest of this post won’t make sense. This is a loose R translation of Ben’s Stata code. The data is held in a Google doc. While it is possible to directly retrieve

Read more »