如何模拟双峰分布? [英] How to simulate bimodal distribution?
本文介绍了如何模拟双峰分布?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下代码来生成双峰分布,但是当我绘制直方图时。我看不到这两种模式。我想知道我的代码是否有问题。
I have the following code to generate bimodal distribution but when I graph the histogram. I don't see the 2 modes. I am wondering if there's something wrong with my code.
mu1 <- log(1)
mu2 <- log(10)
sig1 <- log(3)
sig2 <- log(3)
cpct <- 0.4
bimodalDistFunc <- function (n,cpct, mu1, mu2, sig1, sig2) {
y0 <- rlnorm(n,mean=mu1, sd = sig1)
y1 <- rlnorm(n,mean=mu2, sd = sig2)
flag <- rbinom(n,size=1,prob=cpct)
y <- y0*(1 - flag) + y1*flag
}
bimodalData <- bimodalDistFunc(n=100,cpct,mu1,mu2, sig1,sig2)
hist(log(bimodalData))
推荐答案
问题似乎太小了 n
并且 mu1
和 mu2
之间的差异太小,取 mu1 = log(1)
, mu2 = log(50)
和 n = 10000
给出了这一点:
The problem seems to be just too small n
and too small difference between mu1
and mu2
, taking mu1=log(1)
, mu2=log(50)
and n=10000
gives this:
这篇关于如何模拟双峰分布?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文