泊松分布太窄,负二项式分布太宽

时间:2019-09-27 19:47:21

标签: r distribution

我试图用R中使用optim的分布拟合一些钓鱼者购买的鱼的数量数据(图像中为灰色)。我同时拟合了泊松(红色)和负二项分布(蓝色) ),但正如您所见,两者似乎都不对。我接下来要采取什么措施才能更好地适应健康?

我的图表:

enter image description here

HTTP Error 500.31 - ANCM Failed to Find Native Dependencies

Common solutions to this issue:
The specified version of Microsoft.NetCore.App or Microsoft.AspNetCore.App was not found.
Specific error detected by ANCM:
It was not possible to find any compatible framework version The specified framework 'Microsoft.AspNetCore.App', version '3.0.0' was not found. - The following frameworks were found: 2.1.12 at [D:\Program Files (x86)\dotnet\shared\Microsoft.AspNetCore.App] 2.1.13 at [D:\Program Files (x86)\dotnet\shared\Microsoft.AspNetCore.App] 2.2.6 at [D:\Program Files (x86)\dotnet\shared\Microsoft.AspNetCore.App] 2.2.7 at [D:\Program Files (x86)\dotnet\shared\Microsoft.AspNetCore.App] You can resolve the problem by installing the specified framework and/or SDK. The .NET Core frameworks can be found at: - https://aka.ms/dotnet-download

负二项式拟合的输出:

#fit poisson curve to data using optim
minus.logL.s<-function(lambda, dat){
  -sum(dpois(dat,lambda, log=TRUE))}

mle<-optim(par=45,fn=minus.logL.s, method="BFGS",hessian=T,dat=survey.responses.baitusers$fish.per.trip)
mle

#simulate data coming from a poisson distribution of mean 38
simspois<-as.data.frame(rpois(1000, 38)) 
colnames(simspois)<-("simulated_values")

#fit negative binomial curve
minus.logL.nb<-function(pars, dat){
  mu<-pars[1]
  size<-pars[2]
  -sum(dnbinom(dat, mu=mu, size=size,log=TRUE))}

mlenb<-optim(par=c(mu=38,size=1),fn=minus.logL.nb, method="BFGS",hessian=T,dat=survey.responses.baitusers$fish.per.trip)
mlenb

simsnegbin<-as.data.frame(rnbinom(1000,size=4, mu=38))
colnames(simsnegbin)<-("simulated_valuesnb")

#graph both
graph<-ggplot(survey.responses.baitusers)+aes(fish.per.trip)+geom_histogram()+geom_smooth(data=simspois, aes(simulated_values), stat = "count",color="red")+geom_smooth(data=simsnegbin, aes(simulated_valuesnb), stat="count", color="blue")
graph

泊松拟合的输出:

$par
       mu      size 
38.333338  4.107287 

我的数据:

$par
[1] 38.33333

0 个答案:

没有答案