11.07.2015 Views

statisticalrethinkin..

statisticalrethinkin..

statisticalrethinkin..

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

72 3. SAMPLING THE IMAGINARYR code3.20R code3.21R code3.22R code3.23likelihood defines a distribution of possible observations that we can sample from, to simulateobservation. In this way, Bayesian models are always generative, capable of simulatingpredictions. Many non-Bayesian models are also generative, but many are not.We will call such simulated data DUMMY DATA, to indicate that it is a stand in for actualdata, like a crash test dummy. With the globe tossing model, the dummy data arises from abinomial likelihood:n!Pr(w|p, n) =w!(n − w)! pw (1 − p) n−w ,where w is an observed count of “water” and n is the number of tosses. Suppose n = 2, twotosses of the globe. en there are only three possible observations: 0 water, 1 water, 2 water.You can quickly compute the likelihood of each, for any given value of p. Let’s use p = 0.7,which is just about the true proportion of water on the Earth:dbinom( 0:2 , size=2 , prob=0.7 )[1] 0.09 0.42 0.49is means that there’s a 9% chance of observing w = 0, a 42% chance of w = 1, and a 49%chance of w = 2. If you change the value of p, you’ll get a different distribution of impliedobservations.Now we’re going to simulate observations, using these likelihoods. is is done by samplingfrom the distribution just described above. You could use sample to do this, but Rprovides convenient sampling functions for all the ordinary probability distributions, likethe binomial. So a single dummy data observation of w can be sampled with:rbinom( 1 , size=2 , prob=0.7 )[1] 1e “r” in rbinom stands for “random.” It can also generate more than one simulation at atime. A set of 10 simulations can be made by:rbinom( 10 , size=2 , prob=0.7 )[1] 2 2 2 1 2 1 1 1 0 2Let’s generate 100-thousand dummy observations, just to verify that each value (0, 1, or 2)appears in proportion to its likelihood:dummy_w

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!