简体   繁体   English

如何估计R中的泊松分布样本的Lambda,并以此为基础得出估计量密度函数的核估计?

[英]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. 因此,我有500个泊松分布的模拟样本,每个样本n = 100。

1) How can I estimate the lambdas for each of these samples separately in R ? 1)如何在R中分别估计每个样本的Lambda?

2) How can I draw Kernel Estimation of the density function of the estimator for lambda based on the 500 estimated lambdas? 2)如何基于500个估计的lambda得出lambda的估计量的密度函数的核估计? (my guess is somehow with "Kernsmooth" package and function "bkfe" but i fail to programm it normally anyway (我的猜测是使用“ Kernsmooth”软件包和函数“ bkfe”进行的,但是无论如何我都无法正常编程

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)

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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