# Simulation of Poisson using exponential

I have shown using the inverse method that if $$U\sim U(0,1)$$ then $$X=-1/\lambda \cdot \log(U) \sim\exp(\lambda)$$. Using that, how do I write a code in R that generates $$n$$ samples from the $$\operatorname{Poisson}(\lambda)$$?

To generate one sample, you would use rpois() as follows:

sample <- rpois(10000,lambda)

To generate more than one sample, you would use this in a loop:

for(i in 1:1000) {
sample <- rpois(10000,lambda)
\\do something
}

Both of these are generating 10000 random observations from a Poisson$$(\lambda)$$ distribution.

See the documentation here

R code according to your IP

#set lamda
lemda<-1

#set sample size
n<-25

#generate uniform random numbers
uni<-runif(n,0,1)

#take log
u<-log(uni)

#Poisson numbers
x<-(1/lemda)*u

x


or you can generate Poisson random numbers by using rpois(n, lambda).

NOTE: set "n" and "lemda" before using any of them.