# R

Blogs on the R software.

## flea circus

December 7, 2016
By

An old riddle found on X validated asking for Monte Carlo resolution  but originally given on Project Euler: A 30×30 grid of squares contains 30² fleas, initially one flea per square. When a bell is rung, each flea jumps to an adjacent square at random. What is the expected number of unoccupied squares after 50 […]

## the incredible accuracy of Stirling’s approximation

December 6, 2016
By
$the incredible accuracy of Stirling’s approximation$

The last riddle from the Riddler [last before The Election] summed up to find the probability of a Binomial B(2N,½) draw ending up at the very middle, N. Which is If one uses the standard Stirling approximation to the factorial function, log(N!)≈Nlog(N) – N + ½log(2πN) the approximation to ℘ is 1/√πN, which is not […]

## Optimization matchup: R’s glpkAPI vs Julia’s JuMP

December 6, 2016
By

tl;dr: although I use R every day and love it, doing mathematical programming using Julia is much simpler and more flexible than anything I know that is currently available in R.Recently I have learned that Iain Dunning and Joey Huchette and Miles Lubi...

## ratio-of-uniforms [#4]

December 1, 2016
By

Possibly the last post on random number generation by Kinderman and Monahan’s (1977) ratio-of-uniform method. After fiddling with the Gamma(a,1) distribution when a<1 for a while, I indeed figured out a way to produce a bounded set with this method: considering an arbitrary cdf Φ with corresponding pdf φ, the uniform distribution on the set […]

## RStudio in the cloud with Amazon Lightsail and docker

December 1, 2016
By

About two years ago we published a quick and easy guide to setting up your own RStudio server in the cloud using the Docker service and Digital Ocean. The process is incredibly easy-- about the only cumbersome part is retyping a random password. Toda...

## asymptotically exact inference in likelihood-free models [a reply from the authors]

November 30, 2016
By

[Following my post of lastTuesday, Matt Graham commented on the paper with force détails. Here are those comments. A nicer HTML version of the Markdown reply below is also available on Github.] Thanks for the comments on the paper! A few additional replies to augment what Amos wrote: This however sounds somewhat intense in that […]

## BERT: a newcomer in the R Excel connection

November 30, 2016
By

A few months ago a reader point me out this new way of connecting R and Excel. I don’t know for how long this has been around, but I never came across it and I’ve never seen any blog post or article about it. So I decided to write a post as the tool is really […]

## The Effective Number of Parties in the Electorate by Year and Region

November 27, 2016
By

Tasks: Compute the Effective Number of Parties by year and region Using the American National Election Studies, compute the Effective Number of Parties in the electorate across regions and years/waves. The data The data come from The American National Election Studies (ANES). The ANES is a survey that covers voting behavior, public opinion, and political participation. Many other countries have their own version of this survey, for instance see here.…

## sampling by exhaustion

November 24, 2016
By

The riddle set by The Riddler of last week sums up as follows: Within a population of size N, each individual in the population independently selects another individual. All individuals selected at least once are removed and the process iterates until one or zero individual is left. What is the probability that there is zero […]

## Monty Python generator

November 22, 2016
By

By some piece of luck I came across a paper by the late George Marsaglia, genial contributor to the field of simulation, and Wai Wan Tang, entitled The Monty Python method for generating random variables. As shown by the below illustration, the concept is to flip the piece H outside the rectangle back inside the […]