Yeah Sure, Maybe, Well … Okay

[This article was first published on Milk Trader, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Whoever wrote the book on statistics, probably avoided getting a proper education in literature. At least that’s my null hypothesis. The cryptic and awkward presentation of probabilities common amongst the Frequentists (no, not the Latin American Socialist faction you’re thinking of) is legend. They speak of the null hypothesis and having a 95% confidence level that you can accept it. Some aren’t happy with that obfuscation and insist that it’s not proper to accept a null hypothesis, but only to reject or fail to reject the null hypothesis. Hmm, well okay I guess. There is another way though. It’s called Bayesian inference. Give it a look. It’s probably the only way known to mankind that you can be a nerd and cool at the same time.

Not that the Bayesian approach is easy to understand at first glance. It’s not difficult, but it’s also easy to get it wrong. My approach to learning was to write a program in R, which I appropriately named the “quote” — bayes_a_nator. This is a simple program and it’s assumptions are ridiculously naive, but you don’t build a killer algo without getting some basic machinery running first.

The following function takes two stocks from Yahoo Finance and calculates how often they have positive returns. It starts with the first stock’s positive return probability, and then gets the second stock’s positive return probability given that the first stock returned positive. Then it solves the riddle to the question: What is the probability that first stock is up, given that second stock is up? The algorithm does not calculate this implicitly, so the probability has to be inferred.

This program has five parts, and instead of pontificating about it, I’ll just let the comments speak for themselves. Enjoy the ASCII art.

bayes_a_nator 

To leave a comment for the author, please follow the link and comment on their blog: Milk Trader.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)