本文介绍了在 R 中编写双峰正态分布函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何在 R 中绘制正态分布的联合分布.例如,如果正态分布 f(x) 由两个函数组成:

I am wondering how to plot a joint distribution in R for a normal distribution. For example, if the normal distribution f(x) is comprised of two functions:

f_1(x) ~ Normal(0, 1)
f_2(x) ~ Normal(2, 1)

那么我如何在 R 中添加一个参数来描述这个?我正在 beta 分布中寻找类似shape1"类型的参数,但无法弄清楚如何扩展常规 dnorm 参数以使其成为联合分布.有什么建议?

then how can I add an argument in R to portray this? I'm looking for an argument like the "shape1" type in the beta distribution, but can't figure out how to expand the regular dnorm argument to make it a joint distribution. Any suggestions?

谢谢!

推荐答案

您似乎想要创建一个混合了 2 个法线的分布.混合物的密度只是成分密度的(加权)总和,因此您可以执行以下操作.

It looks like you want to create a distribution that is the mixture of 2 normals. The density of the mixture is just the (weighted) sum of the component densities, so you can do the following.

f <- function(x, p1 = 0.5, p2 = 1 - p1, m1, m2)
p1 * dnorm(x, m1) + p2 * dnorm(x, m2)

x <- seq(-2, 4, len=101)
dens <- f(x, p1 = 0.5, m1=0, m2=2)
plot(x, dens, type = "l")

这篇关于在 R 中编写双峰正态分布函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-18 04:26