I have the following list and vectors of parameters:
myList <- list(c(3, 0, 1), c(2, 2, 2))
vPar1 <- c(1, 5, 100)
vPar2 <- c(100, 5, 1)
and I'm trying to draw samples from 3 Beta
distributions with shape parameters shape1 = vPar1
and shape2 = vPar2
(element-wise).
The expected result would be a list with two elements: the first element would consist of 4 random numbers (3 from a Beta(1, 100)
and 1 from a Beta(100, 1)
distribution) whereas the second list element would consist of a total of 6 random numbers (2 random numbers of a Beta(1, 100)
, Beta(5, 5)
and Beta(100, 1)
distributions each).
I tried to produce the required result using mapply
i.e. cycling through the elements of the 3 arguments, but I can't figure how it should be used exactly:
mapply(function(x, shape1, shape2) {unlist(rbeta(x, shape1, shape2))},
myList,
MoreArgs = list(shape1 = vPar1, shape2 = vPar2),
SIMPLIFY = FALSE)
This results in a list of two elements but with 3 random numbers each, insetad of the expected 4 and 6 numbers respectively. I'd be grateful for any suggestions! Thanks.
n number of observations. If length(n) > 1, the length is taken to be the number required.
So the actual values in your myList vectors are being ignored. Their length , 3, is being used – Pigpen