matlab画直方图并拟合泊松分布,将泊松分布拟合为数据(直方图+直线)

我需要做的是@interstellar在这里问Fit poisson distribution to data,但在R环境中(而不是matlab)。

所以,我用我的观察值创建了一个barplot,我只需要在它上面拟合一个泊松分布。

在这里我的数据:

df = read.table(text = 'Var1 Freq

6 1

7 2

8 5

9 7

10 9

11 6

12 4

13 3

14 2

15 1', header = TRUE)创建的barplot如下所示:

t = barplot(df$Freq, ylim = c(0,10))

axis(1, at=t, labels=df$Var1)我对R还是个新手,所以我如何使用fitdist函数或其他方法在我的barplot上方创建一条线?

任何帮助将非常感激。

UPDATE

我已经制定了一些东西,但如果它是正确的,我不确定100%:

#create barplot

t = barplot(df$Freq, ylim = c(0,10))

axis(1, at=t, labels=df$Var1)

#find lambda value from my data

pois = fitdist(df$Freq, 'pois', method = 'mle')

print(pois)

#result

Fitting of the distribution ' pois ' by maximum likelihood

Parameters:

estimate Std. Error

lambda 4 0.6324555

#create 10 values from a real poisson distribution

dist = dpois(1:10, lambda = 4)

#multiply them by `sum(df$Freq)` in order to scale them to the barplot

dist = dist * sum(df$Freq)

#add the line plot to the original barplot

lines(dist, lwd = 2)result

但曲线并不平坦..

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值