Publications by Karl Broman
Learning a new language
It had been a very long time since I’d tried to learn a new programming language. I started C in 1987, S in 1992, and Perl in 1997, but nothing really new in the subsequent 15 years. A friend now has me doing D, wanting to find time to learn ruby, and, most recently, playing with JavaScript and D3. I’m really excited about D3. It’s long pas...
2093 sym 6 img
Curved arrows in R
I briefly investigated how to draw curved arrows in R. Here’s a small piece of the figure that I ultimately created: A google search for “curved arrows in R” revealed three options: curvedarrow in the diagram package The internal function igraph.Arrows within the igraph package (mentioned by Gabor Csardi in R help) Using xspline for the s...
1345 sym R (1046 sym/1 pcs) 8 img
x[[c(5,3)]]
An R tip: Did you know that x[[c(5,3)]] is the same as x[[5]][[3]]? I should make more thorough use of this. In the help file for [[: [[ can be applied recursively to lists, so that if the single index i is a vector of length p, alist[[i]] is equivalent to alist[[i1]]...[[ip]] providing all but the final indexing results in a list. I never knew...
929 sym 4 img
apply vs for
It’s widely understood that, in R programming, one should avoid for loops and always try to use apply-type functions. But this isn’t entirely true. It may have been true for Splus, back in the day: As I recall, that had to do with the entire environment from each iteration being retained in memory. Here’s a simple example: > x <- matrix(r...
1320 sym R (280 sym/1 pcs) 4 img
Beware of grep with a list
Another R tip: beware of as.character applied to a list. > as.character( list(letters[1:3], letters[4:6]) ) [1] "c(\"a\", \"b\", \"c\")" "c(\"d\", \"e\", \"f\")" Really, beware of grep with a list: > grep("c", list(letters[1:3], letters[4:6])) [1] 1 2 You might have thought that the result would be just 1, but grep expects a vector of character...
791 sym R (159 sym/2 pcs) 4 img
Tutorials on git/github and GNU make
If you’re not using version control, you should be. Learn git. If you’re not on github, you should be. That’s real open source. To help some colleagues get started with git and github, I wrote a minimal tutorial. There are lots of git and github resources available, but I thought I’d give just the bare minimum to get started; after usin...
1247 sym R (85 sym/1 pcs) 4 img
Stack Exchange: Why I dropped out
Stack Exchange is a series of question-and-answer sites, including Stack Overflow for programming and Cross Validated for statistics. I was introduced to these sites at a short talk by Barry Rowlingson at the 2011 UseR! meeting, “Why R-help must die!“ These sites have a lot of advantages over R-help: The format is easier to read, math and ...
2081 sym 4 img
Chutes & ladders: How long is this going to take?
I was playing Chutes & Ladders with my four-year-old daughter yesterday, and I thought, “How long is this going to take?” I saw an interesting mathematical analysis of the game a few years ago, but it seems to be offline, though you can read it via the wayback machine. But that didn’t answer my specific question, namely, “How long is this...
2134 sym 6 img
More on Chutes & Ladders
Matt Maenner asked about the sawtooth pattern in the figure in my last post on Chutes & Ladders. Damn you, Matt! I thought I was done with this. Don’t feed my obsession. My response was that if the game ends early, it’s even more likely that it’ll be the kid who went first who won. But, my intuition was wrong: exactly the opposite is tru...
3416 sym 10 img
Read the source code
The other day, there was a bit of a twitter conversation about qqline in R. It made me think: how exactly is the line produced by qqline chosen? I seemed to recall that the line was through the first and third quartiles. An advantage of R is that you can just type the name of the function and see the code: # qqline function (y, datax = FALSE, dis...
1654 sym R (694 sym/7 pcs) 4 img