3

R で、重なった 2 つの正規分布を分離できる関数/パッケージ名を探しています。分布は次のようになります。

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

2 に答える 2

9

私は過去にベクトル一般化線形モデルを使用して良い結果を出しました。VGAMパッケージはそのために役立ちます。

このmix2normal1関数を使用すると、2つの単変量正規分布の混合のパラメーターを推定できます。

小さな例

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

バイモーダル分布に適合

于 2012-11-21T19:18:46.867 に答える
3

nls非線形回帰ツール (または他の非線形回帰ツール)を使用することをお勧めします。重ね合わせた分布を表すデータのベクトルがあると思います。次に、おおまかに nls(y~I(a*exp(-(x-meana)^2/siga) + b*exp(-(x-meanb)^2/sigb) ),{initial guess values required for all constants} )yはディストリビューションで、xはドメインです。私はこれについてまったく考えていないので、どの収束方法が失敗する可能性が低いかわかりません。

于 2012-11-21T18:54:09.847 に答える