Where R Shines Over Python: Statistical Models

Image result for python

Python is the language of choice for many data scientists and researchers who analyze data, and it has far superior libraries for deep learning compared to R, and deep learning is all the rage.  However, if you want to apply some more sophisticated models from statistics, Python is sorely lacking and you should use R.

To give an example, say you’re interested in applying survival analysis, where you’re trying to model the time to some first event: could be death, some machine breaking, etc.  In the death case, often risk is some function of both static covariates that either don’t change or change slowly, like one’s height or race, and time-varying covariates like pollution levels and weight.  The main package for this in Python is lifelines: when I checked late last year it didn’t support time-varying covariates.  On the other hand R has a wide range of libraries for survival analysis, including joint models, which properly treat internal time-varying covariates like health measurements (as opposed to external ones like the weather).

This is similar for a range of techniques: if you want mixed models, which are often used in longitudinal data, there are tons of R packages supporting them, and even if there is code out there for Python, it’s far less likely to support recent techniques and papers in the literature.

The statistics community also has a decent habit of releasing well-documented software: they have the Journal of Statistical Software: in general, these papers have an R package associated with them, describe the math behind the package and the high level idea and give a tutorial of how to use it, and then the package documentation itself details each individual function.  A nice example of this is [1].  I won’t link to it directly because it auto-downloads instead of opening in the browser.

So if you think you’ll be using recent ML techniques in your project, then use Python, but if the techniques you’re using come more from statistics, use R.  It’s worth knowing both.

[1] Rizopoulos, Dimitris. “JM: An R package for the joint modelling of longitudinal and time-to-event data.” Journal of Statistical Software (Online) 35, no. 9 (2010): 1-33.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.