I have to generate Poisson regression, for that I want to use inverse CDF method. I am following this post to generate data. But it isn't based on inverse cdf method. The post has following code
> #sample size
> n <- 10
> #regression coefficients
> beta0 <- 1
> beta1 <- 0.2
> #generate covariate values
> x <- runif(n=n, min=0, max=1.5)
> #compute mu's
> mu <- exp(beta0 + beta1 * x)
> #generate Y-values
> y <- rpois(n=n, lambda=mu)
> #data set
> data <- data.frame(y=y, x=x)
> data
I do not want to use the r built in function rpois. I have found this post which does utilize the method only for one lambda. Now, how can I generate Poisson distribution with inverse cdf method for a variety of lambda?
N.B. This useful post provides code for variety of sample sizes, I do not want that.
The answer here is elegant and fast, but if you don't care about efficiency then
should work to implement the inverse-CDF method. (
lambdacan be a vector)