Roger Peng — R Programming, Data Science, and Reproducible Research
Dr. Roger Peng is an associate professor of biostatistics at the Johns Hopkins Bloomberg School of Public Health, co-founder of the Johns Hopkins Data Science Specialization on Coursera and of the Simply Statistics blog. In this Leanpub interview with Len Epp, he discusses his work on air pollution and health, reproducible research, the R programming language, and his book R Programming for Data Science.
Len Epp: Can you tell us how you first became interested in statistics generally, and in biostatistics specifically?
Roger Peng: It’s a weird path that I took. I studied math in college, and I think that’s how a lot of people get involved in statistics initially. Part of my math requirements required that I take a course in statistics, so I took probability theory and I really enjoyed it. So I kept going down that road and ended up being like a minor in that area. My older brother had gone to graduate school, so I just figured that was the right thing to do. And it was funny because I graduated from college in 1999, and it was dot com craziness. Everyone was just going to these software companies, and here I was going to apply to graduate school. So I bucked the trend there.
So I applied to graduate school in statistics, went to UCLA and got my PhD there. There was no bio in my work there. I wasn’t really working in biomedical sciences. And so I was looking for a job, and my advisor’s grad school roommate was a professor at Johns Hopkins. I had no intention of really applying there because I didn’t think I was doing biostatistics. And so he basically said, “my old roommate’s there, he really loves the place, so you should check it out.” So I applied, and I interviewed, and I really liked the people there, and I thought, “okay, well, even though I’m not specialized in this topic area, it seems like a great environment, a great institution.” So I got the job here and I came. It was weird because it wasn’t necessarily directly what my training was. But for me, a lot of decisions I make in terms of what to do or where to go are based on what people are involved. If there’s good people involved and I like being with them, then that’s the bottom line for me.
Len: It’s interesting how you bring up the startup world as well. That’s how a lot of decisions are made in startup land too — the people that you’re going to be involved with are often a driving factor.
Roger: Yeah, because everything’s always changing and people need to be able to deal with it, and you’ve got to make sure that you’re with the right people when things go wrong.
Len: You’re working on environmental biostatistics, and how air pollution and climate change affect human health. Can you give us a little bit of information about how you would use statistics to study those effects?
Roger: Sure. My biggest area is probably looking at outdoor air pollution and population health. This work directly informs national level regulation on air pollution standards. In the U.S., the U.S. Environmental Protection Agency monitors air pollution all across the country and all the major cities. And the idea is that we want to see how the levels of air pollution that are changing in the air are related to different population health metrics. So we might look at the number of people who have been hospitalized for a heart attack on a given day, or the number of people who were hospitalized for respiratory infection, something that we think is linked to air pollution exposure. And so we have these very long time series of daily levels of pollutants, and from day to day things go up and down. So you would imagine that if pollution is linked to health, as pollution is going up and down, the various health metrics also should be going up and down.
But the problem is that teasing out that signal is really hard, because air pollution is not the kind of thing that knocks you over as soon as you walk outside, at least not in the United States. There are all kinds of other competing factors that are a risk for your health. So teasing out the signal that air pollution contributes to either morbidity or mortality risk is really where statistical models are needed. Back in the old days, like in the 40s and the 50s where pollution was just out of control, you didn’t need fancy statistical models to see that it was affecting people’s health. You just had to go out in the street and see people having problems. But now that pollution levels are lower, it’s not so obvious — but nevertheless we still do see pretty strong associations between changes in pollution levels and various health outcomes.
Len: I imagine it must be even more complex when you factor in climate change.
Roger: Yeah, so climate change is an aspect that affects how we think about things in the longer term. There are different time scales at which you can think about air pollution problems. One of them is the day-to-day level, but another one is how things change over time, and are things improving as air pollution levels go down. And climate change can affect that in a variety of ways. One, in affecting the weather, which has an interaction with air pollution levels, and the other is that as we implement policies to deal with climate change, that has a direct effect on air pollution levels too. If we want to deal with climate change by shutting down some power plants, then that will also affect the direct levels of pollution. So there’s lots of interactions. Statistical modeling is useful for integrating all the different kinds of data that you come across, whether it’s climate data or air pollution data or health data, and it’s also useful for teasing out these very small signals that we have to detect.
Len: And are you working with a national data set, or do you focus on a specific region?
Roger: My work focuses on national level studies. On the pollution side we get data from the entire U.S. EPA monitoring network. And then we also get health data from really large administrative claims databases like Medicare and Medicaid, which are these large national insurance programs. So we can look at insurance records and see, okay, every time someone was hospitalized, we can mark that up and then see if it’s related to changes in air pollution levels from the monitoring network.
Len: This reminds me of stories in the media about Paris shutting down half the cars on the streets — you can only drive if your license plate ends in an even or an odd number on a given day, to cut down on car pollution. You were saying pollution levels have gone down generally in the States in the last couple of decades. Do you see any problem like that emerging in an American city in the next ten or fifteen years?
Roger: Well, if you look across the nation, things have gotten much better over the last few decades. But there are still cities that have very high levels of pollution and still have problems. For example, in the 1996 Atlanta summer Olympics, they implemented a scheme like that in terms of traffic control, just because they envisioned lots of people coming. But there are cities that are still beyond the regulations here in the United States that need to improve their levels. Although conditions are generally much better, it’s not like a solved problem yet.
Len: Switching gears slightly, and talking about data science more generally. The Johns Hopkins data science lab website says the revolution in measurement and the resulting deluge of data has made data science the most important field of study in the world today. Can you explain why data science is so important, for people who might not be familiar with it?
Roger: Sure. If you just look around yourself, everything that you look at is essentially generating data. And if it’s not generating data itself, we have some device that can collect data from it. Everywhere you go in the world and in your life today, there is information that’s being generated and spewn out into the world. A lot of it we can’t collect because there’s too much, but we can collect more and more of it as time goes on because of the improvements in technology and in computing power.
If you look back many years, let’s say 100 years, the biggest issue was collecting the data, because it was very expensive and you had to be very careful not to waste a lot of resources collecting data. And then, once you got the data, assuming you did it right, the analysis is pretty straightforward because there’s maybe 10 data points. But now we have the reverse situation where the collection of the data is very routine, and in fact is almost too routine sometimes. The data is being collected whether we like it or not. You look at some server web logs, the data is just being collected, it just is. And so now the analysis actually has become much more complicated and much more difficult to do, because of the volume and the complexity and the heterogeneity of all the data that’s being generated automatically.
So the difficulties and the skills that are required have really flipped. Whereas before you had to be really careful about optimizing your study design — you still have to worry about that — now the skills for data analysis are really necessary. And there are a lot of fields that didn’t emphasize the data analysis part and are realizing now, “oh, actually we really got to train people in this area,” whereas in the past we did not have to. So data science in many ways is taking over every area of either science or business, because everywhere there’s data, and so the skills to analyze those data are just becoming increasingly valuable.
Len: I imagine the presence of this data is unlocking new areas of study, right? In the past people weren’t all wearing Fitbits and clocking their steps every day. Now that things are being tracked that weren’t being tracked before, it must open up new areas for study.
Roger: Yeah, there’s new areas of study being created, things like wearable computing that didn’t exist a couple years ago. But also there’s just new kinds of data that we’ve never seen before, and so we don’t even know how to characterize them. If you have an accelerometer on that you’re wearing, how do we even get any information from that data? How do we know what you’re doing from the accelerometer? So that’s where statisticians like me and many other people that I work with earn our money, because we have to figure out ways to look at that data, to characterize it, to understand what’s happening.
Len: You say on your website that you have a special interest in reproducible research. Can you explain what reproducible research means and why it’s so important to you and to your field?
Roger: Yeah, so reproducible research is the scientific analog of open source software. There’s a lot of confusion sometimes about the terminology. The idea is that you want your data and your software code to be available to others to look at. So I can take your data and I can take the software that you used to analyze it, and I can reproduce the numbers that you’ve published, or the plots that you made, or whatever it is that the result was. It’s not that I’m going to redo your whole study, I’m just going to take your data and produce what you produced.
And the funny thing is that this was not that important many years ago, because the data was so small, there was no software, there was nothing to provide. If you really wanted to know whether an experiment was valid or not, you would just do it again yourself. But now the problem is a lot of studies are so big and they involve such large quantities of data that the collection of the data is not really the challenging part. It’s really the analysis of how they analyzed the data to come to a conclusion about nature or whatever it is they’re studying. That’s really where all the difficulty is. The problem is that the publishing infrastructure is not really designed to let people know what those details are. The bottom line way to know what those details are is to see the code, to see the data. But because a lot of this happened very quickly, there isn’t the infrastructure for giving people access to data and software code. So a lot of that has to be built. I was interested early on in getting this idea across to people and convincing them that it had to happen in order for science to move forward.
Len: In the popular science media there’ve been articles over the last year or so about how the interests of scientists aren’t necessarily aligned with actually reproducing research, right? Because you get the headline or the promotion or the patent for doing the original research, and there’s often a very low proportion of studies that are actually reproduced at all. Is that true in your specialty as well?
Roger: Yeah, I think that’s a general phenomenon and it’s a general aspect of our culture. The emphasis is on discovery. And analyzing a published data set and coming to the same result is not what might be considered discovery, right? On the other hand, analyzing someone else’s data set and finding out that something was wrong, well, that is discovery. So some people are interested in doing that, but in general, just reproducing another finding is sometimes difficult to get funding for or to get published in a high-profile journal.
However, when it comes to something that’s really high impact, something that’s really interesting to that field, it will get reproduced, because if it’s something that’s really surprising or something that could have an impact on the entire field, people are going to want to know whether it’s true or not. And the only way you determine whether it’s true or not is to have multiple people do the same experiment independently. But if no one cares about it, then it’s hard to justify reproducing it. There’s a lot of scientific publications out there, and it’s not like every single one of them is going to be reproduced, it’s just not physically possible. But there are many examples in the recent popular press of things that were faked or things that didn’t reproduce, and you realize that that’s how the system is supposed to work. There’s this example with stem cells, and it was a very surprising result. So what happened? Immediately 10 labs went to reproduce it, and none of them could do it, so they knew it was wrong. So there is an interest in reproducing things, but probably weighted more on the things that are surprising or really exciting.
Len: Speaking of original research, I read in the preface to your book that your first experience with R involved an analysis of word frequencies in classic texts like Shakespeare and Milton to see if you could identify authorship based on word frequency. Can you explain how you got into that and what your results were, if you can remember that far back?
Roger: To be honest, I can’t remember how I got into it. I needed a senior project when I was in college, and I think my advisor pointed me to this paper. It was published in the 60s, about two statisticians who had analyzed the Federalist Papers, because there was some controversy over who wrote which of the Federalist Papers. So they did a little statistical analysis, and I adopted the same approach that they took, which is, can you identify certain written works based on the rate at which they use what are called function words? Words like the, and, he, she — you probably don’t spend a lot of thought on how frequently you’re going to use that word, and so the idea is that it reflects your natural personal style.
The analysis basically involves taking these texts that we downloaded off of Project Gutenberg, and you use a Perl script to divide up the text into words, and count how often they use a certain subset of these function words. And then, I don’t know how technical you want to get, but we used basic linear discriminant analysis to see if we could separate one author from another. It was surprising how well authors separate. Granted, we picked a group of people who were pretty different from each other, but you could see that authors that wrote in the same time period were closer to each other than authors writing in very different time periods. So there was a logic to what we found, that a lot of the books or plays from these famous writers were identifiable from these patterns of how frequently they use these meaningless words.
Len: And did you have any kind of response from people in the humanities end of things?
Roger: I would be surprised if anyone in the humanities actually read that paper. It was published in a statistics journal, so I’m not sure how often they’re pulling that off the shelf.
Len: Well, it’s interesting because there are some pretty big controversies about authorship specifically around Shakespeare, right? Did Shakespeare write the plays, or was it a group of people, or was it in fact someone else? I was just curious if anyone had gone, “aha, here’s another tool for me to make my argument that it was actually not Shakespeare who wrote the plays.”
Roger: No, I had not gotten any emails or issues along those lines. But I think you’re right, authorship is always a very interesting topic to people, and not just in literature, but in many different areas. And it is interesting to think about how you would characterize numerically something like a piece of music, and then be able to separate it between two different people. But no, I’ve not been enlisted in that.
Len: To talk about your book more specifically — you explain in the book that the R programming language has become the de facto programming language for data science. Can you explain a little bit about what R is and why that’s happened?
Roger: Yeah, sure, I’ll try. So R is a language that started in the early 90s. It was created by two statisticians from New Zealand. Originally they wanted to create a statistical language that was free to them and that could run on very lightweight computers. I think they were using old Macintoshes, and they wanted to use it to teach statistics. That was their goal. They didn’t have any grand aspirations at that time.
But back then, open source software was still in some sense controversial. There were really no statistical packages of any quality that were free or open source. You had to pay a lot of money to use these statistical packages to analyze any data. Unless you were at a big company or at a university, you didn’t really have access to this kind of stuff.
So they put R up on the web in the later 90s, and it was one of the first open source statistical packages out there that you could really use to do serious data analysis. And I found it just because I didn’t want to pay the money for all these expensive packages. So I started using it pretty early on. It’s a clone of an earlier language called S-PLUS, which was one of the ones that cost a lot of money. A lot of people, including myself, had been trained on S-PLUS, and so it was easy to go over to R, it had similar syntax.
And then, as with many successful open source projects, very quickly a big community developed around it, all over the world, in Europe and the US and Latin America, Central America. A lot of people gathered around it, initially because it was free, but eventually because the community itself becomes a reason to use the package. And people started building add-on packages that you could load up. At some point R was better at some things than a lot of the commercial packages, and then there was no turning back. I got involved somewhat early on in the history of the language and saw it develop and become popular. Now it’s hard for me to comprehend sometimes how popular it’s become, because I always thought it would be this niche academic thing. But now it’s in business everywhere.
There are companies developed around selling and consulting on R. There are a lot of data science companies using it for analysis. One of the things that makes it great is that it has this ability to be ultimately very customizable. Anyone can implement a procedure that they want to use to analyze their data. It has a very flexible and powerful programming language, and it has a great community behind it, an enormous community now, as support and as a way to learn new things.
Len: Speaking about size of community, I noticed from the description of your book that your Coursera course that it’s partially based on has 1.5 million people who participated in it. Have I got that right?
Roger: The 1.5 million is not for that one course. We have a sequence of courses that they call a specialization on Coursera, and the sequence has nine courses. That’s our data science specialization, and it follows the pipeline from how do you get data, to how do you clean it, how do you analyze it, and then how do you make data products. So R programming is just one of the nine courses, and it runs every month. It’s a month-long course, and it typically gets on the order of 40 to 45,000 students enrolled per month. The other eight courses are not quite as popular as that, but across the nine courses, which all run every month, we get about 170,000 people enrolled per month. So we do have a lot of students, a lot of interest obviously in this area.
Len: Do you know if your students are coming from all around the world, or are they concentrated in certain areas?
Roger: They are coming from all over, for sure. Something like 30 to 40 percent come from the U.S., and then the rest come from all over. We get a lot of people from China, Brazil, India, the UK. So it’s all over the map.
Len: That’s amazing. Are they mostly people who are studying in a university somewhere?
Roger: The people studying in university are a big group, but they’re not the majority. A lot of the people we get are working full time and are looking to upgrade their skills, to learn something new and to maybe look to change careers or change positions. Our sequence is structured nicely for those kinds of people because it’s a month long. It runs very frequently, so you can take it whenever you’re ready. So it’s a lot of working professional type of people.
Len: And is having accompanying books a conventional thing for Coursera, or is that something that you and your colleagues are innovators on?
Roger: That’s a good question. It’s hard to say what’s conventional for a phenomenon that’s like three years old. I don’t think it’s that common unless you are someone who already had a textbook. But we felt like it was a natural thing to do. And I think we would have done it sooner had we learned about Leanpub sooner, because we couldn’t quite find the right mechanism. We didn’t want to use a regular publisher. The nature of the courses that we teach is very low cost. You can take it for free. So it’s hopefully accessible to as many people as possible. And so we wanted to layer on something like a textbook using a similar kind of model, and the traditional publisher really was not the way to do that.
Len: And what were some of the reasons you didn’t want to go with a traditional publisher?
Roger: Well, I’ve done it before. I have another book through a traditional academic publisher. And the bottom line is that they don’t really hit the right audiences, in my opinion. And also, you have to charge a lot of money to make it worth your while from an author’s point of view. And it’s a very slow process. The publisher really doesn’t do anything for you, you have to do all the formatting, everything.
Len: You have to do the formatting as well?
Roger: Yeah, for an academic book. Unless you’re writing something that’s guaranteed to be a bestseller, you have to do everything. They do a little bit of marketing for you, and they go to the conferences and stand at the exhibit booth for you, but there’s not much else that happens. They do a little editing. But it’s a lot of work to go through, and then they have to sell it at such a high price. The number of people who are going to see this book is very limited from the get-go, and I had that experience already with one of my other books. So I was looking for something different, something that we could price low but still make it worth our while. And I think Leanpub just hit all those points. In addition, I found the authoring process really attractive, writing in Markdown but still being able to do all the mathematics and the code and everything. It hit the right balance.
Len: So you were familiar with Markdown before you came to Leanpub?
Roger: Yeah, in fact we teach it in one of our courses.
Len: Can you tell us how you found out about Leanpub?
Roger: I actually heard about it from one of my colleagues. My colleague Brian Caffo, who teaches the specialization with me, he’s one of these guys whose brain is kind of connected to the internet, so he’s always aware of what the latest things are. He published a book, it’s called Statistical Inference, and he just raved about it, to the point where I said, “okay, if I don’t do this myself, I’m just going to have to keep listening to him talk about it.” So I signed up and started the book, and once I got going I realized — it feels like Leanpub has hit every pain point that I had about publishing simultaneously. Maybe you guys are living in my bedroom or something, but you figured out every problem that I had with the publishing process, you just solved it. So it was a weird coincidence.
Len: Well, that’s very nice to say. Customer development has been really important to us, so a lot of what you’re seeing in Leanpub is other people like you who’ve been kicking the tires for quite some time and giving us feedback. If you find something in Leanpub that you’re like, “oh my god, I can’t believe that was there, but that’s exactly what I needed,” that’s probably because someone just like you was there at some point when it didn’t exist. On that note, is there anything you think we could do to improve? If you could have your one wish feature built for you, what would that be?
Roger: There probably is something, but it’s one of those things where when someone asks you, you don’t remember. But right now it’s really quite good for me, and I think it’s quite good for academic publishing. For people like me, doing academic publishing, I think it’s just the right tool and the right model for that kind of style. But I really am serious when I say that you really hit all the major points. So I think you’re at least 90% of the way there. If there’s another 10%, we’ll figure it out.
Len: Thanks very much for that. I do have just one more question about academic publishing specifically. For people who are tenure track but don’t have tenure yet, there are often very specific, in fact calculated, methods for saying what the value is of getting a publication in a certain journal. I don’t know how much it’s like this in the States, but definitely in the UK they have this thing called the Research Assessment Exercise, which quantifies your contribution to the field, and often this is based on rankings of journals or university presses. So getting a monograph published with the Oxford University Press is worth more than one from somewhere else. Do you think this is something that’s going to change? If you published an academic book on Leanpub, it’s hard to know how it would fit in with that ranking.
Roger: Yeah, I think that’s a short term issue. Today it may be a problem, because we’re in transition and e-books are still kind of new. But I think in a couple of years it won’t even come up. And the idea that you’re self publishing in a way is not such a big deal, because with books in particular, the publishing process is not like when you’re writing a journal article which is peer-reviewed. With books there are peer reviewers, but you have much more control, and it’s much more your thing, so it’s much more of a personal statement when you write a book than if you write a research article. With books, when it comes down to it, it’s not so much like, oh, is this publisher good or not, it’s more about, wow, it’s a really big commitment of time to write a good book. And if you’re a junior professor and you’re looking to get promoted, you’re going to think, “oh, what’s the trade-off here? I could spend this amount of time to write this book, or I could spend the same amount of time to write two research articles.” Because there’s a huge commitment of time, and that trade-off, I’ve got to do one or the other, it can’t be both.
One thing that’s nice about something like Leanpub, and a lot of these other tools out there, is that it really decreases the amount of time that’s not spent just directly producing content. Because time is the most important resource, and if you can minimize the amount of time that’s doing things that are really not that important, like emailing back and forth with a publisher, and just focus on writing content and writing your book — that’s one of the beauties of Markdown, it’s just focused on writing the content. I think that is a major plus, and that’s what I tell people now too. The tools are developed such that you don’t have to waste time figuring out how to format things correctly, you just focus on writing. So in terms of the time trade-off for writing a book versus not writing a book, I think it’s not so much an issue of, oh, should I go with this publisher or that publisher.