Category Archives: Uncategorized

R Markdown to WordPress Demo

This is an R Markdown document that will end up as a wordpress post, describing the process of publishing to WordPress directly from an R Markdown document in RStudio. You need a few things in order to get started, but they are easy to install. The biggest thing needed is the RWordPress package, which is not included in the standard repositories, and it is no longer available from the omegahat website. Don't worry, it can still be accessed from GITHUB. So we need two things:

1- The dependencies for RWordPress (namely RCurl, XML and XMLRPC)
2- A way to install packages directly from GITHUB (namely, devtools)

(Thanks to Koehlern at “Scripts and Statistics” for this workaround).

Let's get cracking. Simply run this to get the required packages:

install.packages("devtools")
install.packages("RCurl")
devtools:::install_github("duncantl/XMLRPC")
devtools:::install_github("duncantl/RWordPress")

Great. Now run the following, replacing with your values for 'user', 'password', 'wordpressurl', 'yourmarkdownfile', and 'desired post title':

library(RWordPress)
options(WordPressLogin=c(user='password'),WordpressURL='https://user.wordpress.com/xmlrpc.php')
library(knitr)
knit2wp('yourmarkdownfile.Rmd',title="desired post title")

If you get errors, check carefully for typos. Commands can be case-sensitive. If all went well, the RMarkdown document you described should be posted to your wordpress blog! I'll check mine right now. Code can be found on Github

.

coin_toss_date_idea-576x193

Penney's Game

I’ve been thinking a bit about coin flips recently and reading some work that was done attempting to establish if coin flips are as unbiased as we think they are (more on that soon). Along the way, I learned about something neat called Penney’s game.

Penney’s game can be played with a single coin and it involves two players betting on which triplet of results (such as heads-tails-heads or heads-heads-tails) will appear first if the coin is continuously flipped and all results are recorded.

E.g. Suppose player 1 chooses HHH (heads-heads-heads) and player 2 chooses TTT (tails-tails-tails) and the flip results are as follows:
HHTHTTHTTT

Then player 2 wins, as the triplet TTT has appeared first.

Now, if both players conceal their choices, this game is fair. However, if player 2 is allowed to choose their triplet after player 1 has declared theirs, it turns out that player 2 can actually gain a significant advantage.

Suppose player 1 chooses HHH again and tells player 2, who then chooses THH.
first three flip results are as follows:
HHT.. (if that last flip would have been heads, player 1 would have won)

Now let’s continue (including the first three flips):

HHT HTHH (there, since the last three flips were THH, player 2 has won. In fact, we can see that if the first three flips aren’t HHH, then player 1 can never win, as the second a tails pops up, two more H will make THH, making the HHH impossible to come before THH).

In fact, the general rule for player 2 to always have the edge is to pick the opposite of the middle result from player 1, then the first and middle.
e.g. If player 1 chooses HTH, then player 2 should choose H (opposite of the middle from player 1) and then HT(the first two from player 1) making HHT in total.

The take-home message here is that the game played this way is a bit like rock-paper-scissors, in that the game is “intransitive” (meaning that every choice by one player can be countered by the second player under optimal play).
So while you cannot win Penney’s game 100% of the time (different triplets give different edges), you can always gain a substantial advantage, and most people wouldn’t suspect that at first glance.

P-Value Extravaganza

Here’s an interesting find. It’s a fun introduction to p-values. In general, P-values as a concept can be a tricky topic even for people who think they understand them, so maybe I’ll try discussing that in some shape or form eventually. This is a pretty festive start. Also, it’s hilarious and of course, somewhat inappropriate.