UK Elections 2017

A quick look at the UK 2017 election results with R

Robert McDonnell

1 minute read

This post is a quickie to show how we can visualize the UK election results with just a few lines of R code. (Really, very few). 1 We can load in our usual tidyverse tools, along with a handy little data package, parlitools. library(readr) library(dplyr) library(ggplot2) library(parlitools) library(sf) Thanks to this R Bloggers post, we have the data (the UK Electoral Commission must have it up by now anyway), so

CausalImpact & Healthcare Costs in the US

A quick look at the CausalImpact package in R, studying US healthcare costs over time

Robert Myles MCDonnell

4 minute read

This article by Mike Holly on Mises.org interested me. I wasn’t aware of the history of healthcare costs in the US, and it’s quite surprising, especially the take-off in costs after the 1960s. Holly’s argument is that the “U.S. ‘health care cost crisis’ didn’t start until 1965. The government increased demand with the passage of Medicare and Medicaid while restricting the supply of doctors and hospitals.” In fact, I was quite impressed with this graph: x <- c("rvest", "dplyr", "tidyr", "ggplot2", "magrittr", "lubridate") lapply(x, require, character.only = TRUE) I’ve wanted an excuse to use Google’s CausalImpact package for a while now, so let’s give it a shot using these data.

Robert McDonnell

5 minute read

This Guardian article on the prospective French President Macron got me thinking, especially this passage: France’s economic performance in recent years has been underwhelming, especially when compared to that of Germany. Fifteen years ago, the eurozone’s two biggest countries enjoyed comparable living standards. Today, Germany’s are almost a fifth higher than those in France. Likewise, at the time when euro notes and coins were introduced in 2002, French and German unemployment rates were both around 8%.

Robert McDonnell

3 minute read

From time to time, you might need to copy and paste something into R and turn it into a character string. Maybe it’s something from the output of an error message, or from someone else’s malformed data, or something copied from a document or the internet. If it’s something small, then it’s usually OK to just manually insert "" around the strings and , between them. For something large, that’s just a nightmare.

Update R from inside R

How to quickly update R from inside R itself

Robert McDonnell

1 minute read

I was just about to update R a while ago when I thought to myself that there must be a way to do this inside of R (RStudio, I mean). A quick Google search brought me to the installr package. Very nice, but I use a Mac. Hmmm… A bit more searching and I found Andrea Cirillo’s updateR package, which was made for OS X, fantastic. I tried it out, and although it worked great, I still had to leave RStudio to check to see if the latest version installed.

Robert McDonnell

4 minute read

This week I was working with some RSS feeds in R. You can parse these feeds directly with packages like XML or xml2, or use the rss package (not on CRAN) or the feedeR package (on CRAN). However, I noticed that both rss and feedeR return lists, which necessitates further work in R to get the data into a tidy format, and that both packages leave interesting data behind. With that in mind, I decided to make tidyRSS, a package for parsing these feeds and returning a tidy data frame to the user.

3 minute read

Brazil, where I live, has a shockingly high murder rate. I mean, it’s freaking astounding. A recent blog I read (see it here) caused a bit of discussion among some friends of mine on facebook. Is Brazil a failed state? The obvious answer seems ‘no’, but then again, isn’t security one of the basic functions of the state? Just how bad is it with regard to murders in Brazil? (Pretty nuts is the answer.) We can visualize this is in R to get some idea of how nuts it is.

8 minute read

I really like this image by Tom Burns.1 The liberal2 in me appreciates making cheap fun of people who were horribly mistaken (Lenin; Marx, although I don’t mean to slight his contributions to social science), scum like Stalin, and Fidel Castro, who might have started out with a laudable takedown of a corrupt dictator, but who then became…a corrupt dictator, of course. The artist in me just loves the awesome colours.

Carnaval!

A Shiny app to find Carnaval blocos in São Paulo

8 minute read

I’ve been getting more and more interested in web graphics, particularly d3. All of this of course depends on javascript, a language I don’t know very well. As a way to start learning it, I thought I’d give Shiny a go, as a bridge between R and javascript (I’ve since started a javascript course proper). I’ve been surprised by how simple and powerful Shiny is, although the problems I ran into I wasn’t able to solve.

Robert McDonnell

15 minute read

Update: for some people who may have some issues setting up the blog the way I’ve set out here, see Kate’s helpful comments below. Since April or so of last year, I’ve had a personal website on GitHub pages, where I keep this blog and a few other things. Setting it up was at times frustrating, but a good learning process (I especially picked up a lot of Git through that experience).