简体   繁体   中英

How to draw Poisson density curve in R?

I need to show that the amount of events in Poisson process are distributed by Poisson distribution with parameter lambda * t. Here is the Poisson process generator:

 ppGen <- function(lambda, maxTime){
      taos <- taosGen(lambda, maxTime)
      pp <- NULL
      for(i in 1:maxTime){
        pp[i] <- sum(taos <= i)
      }
      return(pp)
    }

Here I try to replicate the process 1000 times and vectorisee the total occurrences in each realisation:

 d <- ppGen(0.5,100)
    tail(d,n=1)
    reps <- 1000
    x1 <- replicate(reps, tail(ppGen(0.5,100), n=1))
    hist(x1)

Here is the histogram:

在此处输入图像描述

Here I am trying to draw a theoretical Poisson density curve with parameter lambda * t:

xfit<-seq(1,100,length=100)
yfit<-dpois(xfit,lambda = 0.5*100)

lines(xfit,yfit)

But the curve doesn't appear anywhere near the histogram. Can anyone suggest on the right way to do this?

Maybe you can try curve like below

x <- rpois(1000, 0.5 * 100)
dp <- function(x, lbd = 0.5 * 100) dpois(x, lambda = lbd)
curve(dp, 0, 100)
hist(x, freq = FALSE, add = TRUE)

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM