简体   繁体   中英

How to estimate lambdas of poisson distributed samples in R and to draw Kernel estimation of the density function of the estimator basing on that?

So I have 500 poisson distributed simulated samples with n=100 each.

1) How can I estimate the lambdas for each of these samples separately in R ?

2) How can I draw Kernel Estimation of the density function of the estimator for lambda based on the 500 estimated lambdas? (my guess is somehow with "Kernsmooth" package and function "bkfe" but i fail to programm it normally anyway

taskpois <- function(size, leng){
  +     taskmlepois <- NULL
  +     for (i in 1:leng){
    +         randompois <- rpois(size, 6)
    +         taskmlepois[i] <- mean(randompois)
    +     }
  +     return(taskmlepois)
  + }

tasksample <- taskpois(size=100, leng=500)  

As the comments suggest, it seems you're pretty close already.

ltarget <- 2
set.seed(101)    
lambdavec <- replicate(500,mean(rpois(100,lambda=ltarget)))
dd <- density(lambdavec)
plot(dd,main="",las=1,bty="l")

We might as well add the expected result based on asymptotic theory:

curve(dnorm(x,mean=2,sd=sqrt(2/100)),add=TRUE,col=2)

We can add another line that shows that the variation among the densities of different experiments is pretty large relative to the difference between the theoretical and observed density from the first experiment:

lambdavec2 <- replicate(500,mean(rpois(100,lambda=ltarget)))
lines(density(lambdavec2),col=4)

在此处输入图片说明

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