I want to generate Poisson distributed random vectors of length n. For testing purposes I have defined an intensity vector lambda as lambda <- c(1:12)
. Originally I thought that generating the random vectors is an easy process with the lapply function, as we can simply write
vec <- as.matrix(lapply(lambda, function(s) rpois(1, s)))
However with any matrix of proper size, e.g. B <- matrix(data = rep(1, 84), nrow = 7, ncol = 12)
we get in matrix multiplication that
B%*%vec
gives
Error in B %*% vec : requires numeric/complex matrix/vector arguments
I thought that I might have done something wrong with the lapply, but creating an empty 12x1 vector and inserting the Poisson distributed values to its components yielded the same error.
So firstly, what is causing this error? Secondly, is there a convenient way to create random vectors of length n from an arbitrary p.r. distribution?
str(vec)
returns. VTC as simple typo. – Rui Barradas