View source: R/get_max_coupling.R
get_max_coupling | R Documentation |
Takes two univariate continuous distributions (specified by random number generator and log-pdf function), and returns a function to sample from a maximal coupling of these two distributions.
get_max_coupling(rp, dp, rq, dq)
rp |
A function taking n as an argument and returning n samples from the distribution p |
dp |
A function taking x as an argument and returning log-pdf of p evaluated at x |
rq |
A function taking n as an argument and returning n samples from the distribution q |
dq |
A function taking x as an argument and returning log-pdf of q evaluated at x |
Returns a list with
"xy": the pair of samples (x,y)
"identical": TRUE if x = y, FALSE otherwise
mu1 <- 0; mu2 <- 1; sigma1 <- 0.5; sigma2 <- 1.2 f <- get_max_coupling(function(n) rnorm(n, mu1, sigma1), function(x) dnorm(x, mu1, sigma1, log = TRUE), function(n) rnorm(n, mu2, sigma2), function(x) dnorm(x, mu2, sigma2, log = TRUE)) f()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.