Among Matlab and Python, which language is good for general statistical data analysis? What are the pros and cons, other than accessibility, for each?
As a diehard Matlab user for the last 10+ years, I recommend you learn Python. Once you are sufficiently skilled in a language, when you work in a language you are learning, it will seem like you are not being productive enough, and you will fall back to using your default best language. At the very least, I would suggest you try to become equally proficient in a number of languages (I would suggest R as well).
What I like about Matlab:
- I am proficient in it.
- It is the lingua franca among numerical analysts.
- the profiling tool is very good. This is the only reason I use Matlab instead of octave.
- There is a freeware clone, octave, which has good compliance with the reference implementation.
What I do not like about Matlab:
- There is not a good system to manage third party (free or otherwise) packages and scripts. Mathworks controls the 'central file exchange', and installation of add-on packages seems very clunky, nothing like the excellent system that R has. Furthermore, Mathworks has no incentive to improve this situation, because they make money on selling toolboxes, which compete with freeware packages;
- Licenses for parallel computation in Matlab are insanely expensive;
- Much of the m-code, including many of the toolbox functions, and some builtins, were designed to be obviously correct, at the expense of efficiency and/or usability. The most glaring example of this is Matlab's
medianfunction, which performs a sort of the data, then takes the middle value. This has been the wrong algorithm since the 70's.
- saving graphs to file is dodgy at best in Matlab.
- I have not found my user experience to have improved over the last 5 years (when I started using Matlab instead of octave), even though Mathworks continues to add bells and whistles. This indicates that I am not their target customer, rather they are looking to expand market share by making things worse for power users.
- There are now 2 ways to do object-oriented programming in Matlab, which is confusing at best. Legacy code using the old style will persist for some time.
- The Matlab UI is written in Java, which has unpleasant ideas about memory management.
Lets break it down into three areas (off the top of my head) where programming meets statistics: data crunching, numerical routines (optimization and such) and statistical libraries (modeling, etc).
On the first, the biggest difference is that Python is a general purpose programming language. Matlab is great as long as your world is roughly isomorphic to a fortran numeric array. Once you start dealing with data munging and related issues, Python outshines Matlab. For example, see Greg Wilson's book: Data Crunching: Solve Everyday Problems Using Java, Python, and more.
On the second, Matlab really does shine with numeric work. A lot of the research community uses it and if you're looking for say, some algorithm related to a paper in compressed sensing, you're far more likely to find an implementation in Matlab. On the other hand, Matlab is kind of the PHP of scientific computing -- it strives to have a function for everything under the sun. The resulting aesthetics and architecture are maddening if you're a programming language geek, but in utilitarian terms, it gets the job done. A lot of this has become less relvant with the rise of Numpy/Scipy, you're just as likely to find optimization and machine learning libraries available for Python. Interfacing with C is about as easy in either language.
On the availability of statistical libraries for modeling and such, both are somewhat lacking when compared to something like R. (Though I suspect both will meet the needs for 80% of people doing statistical work.) For the Python side of things see this question: Python as a statistics workbench. For the Matlab side, I know there's a statistics toolbox, but I'll let someone more knowledgeable fill in the blanks (my experience with Matlab is limited to numerical work unrelated to statistics).
I also have been an avid Matlab user for 10+ years. For many of those years I had no reason to work beyond the toolbox I had created for my job. Although many functions were created for a toolbox, I often needed to create algorithms for quick turnaround analysis. Since these algorithms often utilize matrix math, Matlab was an ideal candidate for my job. In addition to my Matlab toolbox of code, others in my group worked extensively in Java since there was clear interoperability between the languages. For years I was completely happy with Matlab, but about 3 years ago I decided to start the slow transition away from Matlab and happy to say I haven't opened it in about a year now. Here are the reason for my move:
- I work with online and offline computing systems, the licensing system was always a headache. It always seemed to happen that when we most needed Matlab, the license would expire or suddenly have issues. This was always a headache. Also, if we ever needed to share code, and the other party did not have licenses for the same toolboxes, this created a headache. It's not free
- I often need to create presentations. Even though Matlab provides extensive tools for creating figures, which makes it very powerful for algorithm design, but saving the figure such that it could be inserted into a presentation and look nice is no simple task. I often had to insert an EPS file into Adobe illustrator to remove all the garbage, fix the fonts, and clean up the lines. There are some tools to help with this on the file exchange though (export_fig.m).
- I often get Matlab code from others. When this happens, I almost always rewrite it because: their API is not compatible with my data, their code doesn't make sense, it's slow, it doesn't output what I need,... Basically people who develop in Matlab are not software engineers and Matlab does not encourage any type of design principle.
- I'm a power user. I like terminals. I hate the GUI--hate it. And when they added the "windows" style ribbon, I hated it some more. Basically their tweaks to the GUI and terrible memory management pushed my last button and I decided to leave. Using the
-nodesktopoption is good most of the time, but has it's issues.
- Many possibilities to design of functions (using OO, or functional design), but none feel right, most feel adhoc. I do not get satisfaction from designing good functions in Matlab
- The community is big, but isn't easy to share and find good code. The file exchange isn't that great.
- Clojure: beautiful functional language. My reason for using Clojure was its ability to script Java. A lot of our "big" code base is in Java, so this made a lot of sense. At the time a lot of scientific processing was not readily available, and not a lot with visualization either. But I think this is changing.
- Python: Python has an amazing community and has lots of great projects going on. The IPython Notebook is amazing for many reason (one of them being simple copy/past of figures into powerpoint). Projects like NumPy/SciPy/Scikit-Learn/Pandas have really made Python fun and easy to use. It's so easy to use on multiple cores or clusters. I've been really happy for the switch.
- Julia: Julia is amazing. Especially for Matlab users. It's in it's infancy though, so lots of changes going on. One of the major drawbacks to Python is it does not have all the built-in functionality that Matlab has. Sure NumPy/SciPy bring that functionality, but it's not built-in and you have to make decisions on whether to be pure python objects or numpy objects. Julia basically has everything you wish Python had coming from Matlab. I'd wait, but this is the best option for Matlab users in the future.