Displaying 1 result from an estimated 1 matches for "generateenv".
2008 Aug 25
8
Two envelopes problem
...envelop and r*x
is the
# amount of money in the second envelope
# rdist: a random distribution for the amount x
# n: number of envelope pairs to generate
# ...: additional parameters for the random distribution
# The function returns a 2xn matrix containing the (randomized) pairs
# of envelopes
generateenv <- function (r, rdist, n, ...)
{
env <- matrix(0, ncol=2, nrow=n)
env[,1] <- rdist(n, ...) # first envelope has `x'
env[,2] <- r*env[,1] # second envelope has `r*x'
# randomize de envelopes, so we don't know which one from
# the pair has `x' or `r*x'...