0

Just curious, essentially, i'm trying to implement my function x which is a Poisson Monte Carlo into a 1000*50 matrix, Would be something like this?

 n <-50         # sample size=50 for each simulated data set
 nsim <-1000    # 1000 simulation runs

 x <- function(lambda) rpois(n,rate=lambda) 
 data.sim<- matrix(x, nrow=nsim, ncol=n) 

error code:

 Error in as.vector(x, mode) : 
 cannot coerce type 'closure' to vector of type 'any'

or should i simply make up a function for lambda such as

 y <- function(z) z
 x <- rpois(n,rate=y) 
 data.sim<- matrix(x, nrow=nsim, ncol=n)
ddc
  • 1
  • 2
  • Is lambda supposed to be constant through the entire 1000*50 matrix? – Marat Talipov Feb 16 '15 at 05:01
  • @MaratTalipov Yes. But i guess it requires us manually input as a parameter. – ddc Feb 16 '15 at 05:03
  • Then, you can simply do `data.sim <- matrix(rpois(nsim*n,lambda=lambda_value),nrow=nsim,ncol=n)`. Here, `rpois` will return a vector of needed length, and `matrix(...,nrow,ncol)` will convert that vector into a matrix – Marat Talipov Feb 16 '15 at 05:04
  • @MaratTalipov so just define lambda_value before it? ug.... – ddc Feb 16 '15 at 05:06

0 Answers0