【问题标题】:Separating two superimposed normal distributions in R [closed]在 R 中分离两个叠加的正态分布
【发布时间】:2012-11-10 02:24:10
【问题描述】:

我正在 R 中搜索一个函数/包名称,它允许一个人分离两个叠加的正态分布。分布如下所示:

x<-c(3.95, 3.99, 4.0, 4.04, 4.1, 10.9, 11.5, 11.9, 11.7, 12.3)

【问题讨论】:

  • 为什么这个话题被关闭了?
  • 鉴于良好的答案,我将投票重新开放,但我坚持我最初的投票。没有足够的细节来说明他们想要实现什么方法来使这成为一个纯粹的编程问题,而且迁移到 CV 的质量太低。
  • @AriB.Friedman: ... 鉴于当前的 CV 政策,这个问题会被认为与 CV 编程相关。

标签: r statistics probability


【解决方案1】:

过去我使用向量广义线性模型取得了不错的成绩。 VGAM package 对此很有用。

mix2normal1 函数允许估计两个单变量正态分布的混合参数。

小例子

require(VGAM)
set.seed(12345)

# Create a binormal distribution with means 10 and 20
data <- c(rnorm(100, 10, 1.5), rnorm(200, 20, 3))

# Initial parameters for minimization algorithm
# You may want to create some logic to estimate this a priori... not always easy but possible
# m, m2: Means - s, s2: SDs - w: relative weight of the first distribution (the second is 1-w)
init.params <- list(m=5, m2=8, s=1, s2=1, w=0.5)

fit <<- vglm(data ~ 1, mix2normal1(equalsd=FALSE), 
                iphi=init.params$w, imu=init.params$m, imu2=init.params$m2, 
                isd1=init.params$s, isd2=init.params$s2)

# Calculated parameters
pars = as.vector(coef(fit))
w = logit(pars[1], inverse=TRUE)
m1 = pars[2]
sd1 = exp(pars[3])
m2 = pars[4]
sd2 = exp(pars[5])

# Plot an histogram of the data
hist(data, 30, col="black", freq=F)
# Superimpose the fitted distribution
x <- seq(0, 30, 0.1)
points(x, w*dnorm(x, m1, sd1)+(1-w)*dnorm(x,m2,sd2), "l", col="red", lwd=2)

这正确地给出了(“真”参数 - 10、20、1.5、3)

> m1
[1] 10.49236
> m2
[1] 20.06296
> sd1
[1] 1.792519
> sd2
[1] 2.877999

【讨论】:

    【解决方案2】:

    您可能想要使用 nls ,非线性回归工具(或其他 nonlin 回归器)。我猜你有一个代表叠加分布的数据向量。然后,粗略地说,nls(y~I(a*exp(-(x-meana)^2/siga) + b*exp(-(x-meanb)^2/sigb) ),{initial guess values required for all constants} ),其中y 是您的发行版,x 是域。 我根本没有考虑这个,所以我不确定哪种收敛方法不太可能失败。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-12-09
      • 1970-01-01
      • 2011-11-11
      • 1970-01-01
      • 1970-01-01
      • 2014-02-03
      • 2015-09-05
      相关资源
      最近更新 更多