双峰分布
2007-09-28 | R

平均の異なる正規分布を2つ重ねた双峰分布の作図。たとえば男と女の身長の分布を合わせたような分布。
bimodal <- function(d)
{
x <- seq(-4, 4, 0.05)
plot(x,dnorm(x, mean=0, sd=0.8), type="n")
curve(dnorm(x, mean=-d, sd=0.8)+dnorm(x, mean=d, sd=0.8), type="l",add=T)
}
> bimodal(2)
bimodal <- function(d)
{
x <- seq(-4, 4, 0.05)
plot(x,dnorm(x, mean=0, sd=0.8), type="n")
curve(dnorm(x, mean=-d, sd=0.8)+dnorm(x, mean=d, sd=0.8), type="l",add=T)
}
> bimodal(2)