by jdreaver · 4y ago · 0 comments
Even if you aren't a data scientist or a statistician (I'm an infrastructure/software engineer, but I've dabbled as the "data person" in different startups), learning basic statistics will open your eyes to how easy it is to misinterpret data. My favorite part of this course, besides helping me understand Bayesian statistics, is the few chapters on causal relationships. I use that knowledge quite often at work and in my day-to-day life when reading the news; instead of crying "correlation is not causation!", you are armed with a more nuanced understanding of confounding variables, post-treatment bias, collider bias, etc.
Lastly, don't be turned off by the use of R in this book. R is the programming language of statistics, and is quite easy to learn if you are already a software engineer and know a scripting language. It really is a powerful domain specific language for statistics, if not for the language then for all of the statisticians that have contributed to it.
https://github.com/StatisticalRethinkingJulia https://github.com/pymc-devs/resources/tree/master/Rethinkin... https://bookdown.org/content/4857/
I would say statistical rethinking is a great way to compare and contrast different ppl impls and languages, I've been using it with Turing, which is pretty great.
- Lots of high quality statistical libraries, for one thing.
- RStudio's RMarkown is great; I prefer it to Jupyter Notebook.
- I personally found the syntax more intuitive, easier to pick up. I don't usually find myself confused about the structure of the objects I'm looking at. For whatever reason, the "syntax" of pandas doesn't square well (in my opinion) with python generally. I certainly want to just use python. But, shrug.
- The tidyverse package, especially the pipe operator %>%, which afaik doesn't have an equivalent in Python. E.g.
with_six_visits <- task_df %>%
group_by(turker_id, visit) %>%
summarise(n_trials = n_distinct(trial_num)) %>%
mutate(completed_visit = n_trials>40) %>%
filter(completed_visit) %>%
summarise(n_visits = n_distinct(visit)) %>%
mutate(six_visits = n_visits >= 6) %>%
filter(six_visits) %>%
ungroup()
Here I'm filtering participants in an mturk study by those who have completed more than 40 trials at least six times across multiple sessions. It's not that I couldn't do the same transformation in pandas, but it feels very intuitive to me doing it this way.- ggplot2 for plotting; its really powerful data visualization package.
Truthfully, I often do my data text parsing in Python, and then switch over to R for analysis, E.g. python's JSON parsing works really well.
(The below is off topic, but I don't use R so I'd love to know whether I'm reading the code correctly)
"Here I'm filtering participants in an mturk study by those who have completed more than 40 trials at least six times across multiple sessions."
A user with this pattern of trials seems like they would fit the above definition:
Session 1: 82 trials Session 2: 82 trials Session 3: 82 trials
But the code seems to want 6 distinct sessions with >40 trials each. Have I misunderstood?
Also, is 'mutate' necessary before 'filter' or is that just to make the intent of the code clearer to your future self?
%>% is now simply >|
R is a language by and for statisticians. Python is a programming language that can do some statistics.
In Python, there is statsmodels. Here, you'll find a lot of GLM stuff, which is sort of an older approach. Modern inferential statistics, if not just Bayesian, is usually in the flavor of semi-parametric models that rely on asymptotics.
As R is used by professional researchers, it is simply more on the edge of things. Python has most of the "statistics course" schoolbook methods, but not much beyond that.
For example, it has become very common to have dynamic panel data which require dynamic models. Now if you want to do a Blundell-Bond type model in PYthon you have to... code it yourself using GMM, if it exists even.
For statistics, that's pretty much like saying you have a Deep Learning package that maybe has GRU but no transformer modules at all. So yeah, you can code it yourself. Or you use the other one.
Hence my question:
What's the advantage of Python if you already know R?
I've heard they have similarities. Is there anything Python does better than R in terms of statistical analysis, charting, etc.?
AFAIK in statistical modelling Python is better only in neural networks, so if you do not need to do fancy things with images, text, etc. you do not need Python. R is still the king.
In terms of charting and dashboards, I would say that if you work high level R and Python are both pleasant. R has ggplot, but Python has Plotly Express. R has Shiny, but Python has Dash and Streamlit. You can do great with both.