What does it mean to sample a value x* from f(x)? - MathOverflow most recent 30 from http://mathoverflow.net 2013-05-19T09:56:16Z http://mathoverflow.net/feeds/question/92589 http://www.creativecommons.org/licenses/by-nc/2.5/rdf http://mathoverflow.net/questions/92589/what-does-it-mean-to-sample-a-value-x-from-fx What does it mean to sample a value x* from f(x)? ysl 2012-03-29T17:27:51Z 2012-03-29T23:21:09Z <p>This might be a really elementary question, but I'm not sure what it means. I have a density function f(x). How do I sample a value from f? For known distributions there are functions in R which do it for you (e.g. runif, rnorm, etc.) but how do I generate a random number using my own density?</p> http://mathoverflow.net/questions/92589/what-does-it-mean-to-sample-a-value-x-from-fx/92592#92592 Answer by Igor Rivin for What does it mean to sample a value x* from f(x)? Igor Rivin 2012-03-29T17:41:59Z 2012-03-29T17:41:59Z <p>I am not going to answer the philosophical question of "what does it mean", but for the practical question, there is the Ziggurat method of Marsaglia to generate a sample from your favorite distribution. <a href="http://www.jstatsoft.org/v05/i08/paper" rel="nofollow">Read all about it.</a></p> http://mathoverflow.net/questions/92589/what-does-it-mean-to-sample-a-value-x-from-fx/92625#92625 Answer by R Hahn for What does it mean to sample a value x* from f(x)? R Hahn 2012-03-29T23:05:41Z 2012-03-29T23:05:41Z <p>In the simple case that $X$ is a real valued random variable, the first thing I would reach for is the <a href="http://en.wikipedia.org/wiki/Inverse_transform_sampling" rel="nofollow">inverse-cdf method</a>, especially since you have mentioned "runif" which gives draws from a uniform distribution. </p> <p>There is a pretty extensive literature on ways to sample from a variety of distributions, with names like Gibbs sampling, Metropolis-Hastings, slice samplers, perfect samplers, etc. A Google search of any of these should bring up a wealth of info. Did you want something more specific?</p> http://mathoverflow.net/questions/92589/what-does-it-mean-to-sample-a-value-x-from-fx/92627#92627 Answer by anonymous_poster for What does it mean to sample a value x* from f(x)? anonymous_poster 2012-03-29T23:21:09Z 2012-03-29T23:21:09Z <p>I suppose a definition of a random sample would be a sequence of numbers {$a_{n}$} such that, for any measurable set S we have $\sum_{1}^{n}\chi_{S}(a_{i})/n\rightarrow\mu(S)$ as $n\rightarrow\infty$, where $\mu(S):=\int_{S}f(y)dy$, with $f(y)$ your density.</p> <p>How to generate such a sequence is another, much more involved question; there's the inverse CDF technique, various algorithms like Metropolis Hastings or Gibbs sampling (for higher dimensional densities), etc. etc.</p>