好奇,基本上,我正在尝试将我的函数x(Poisson Monte Carlo)实现为1000 * 50矩阵,会是这样的吗?
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 in as.vector(x, mode) :
cannot coerce type 'closure' to vector of type 'any'
或者我应该简单地为lambda构成一个函数,例如
y <- function(z) z
x <- rpois(n,rate=y)
data.sim<- matrix(x, nrow=nsim, ncol=n)