Description Usage Arguments Value Examples
Gibbs sampling for two-component Gaussian Mixture
1 | Gibbs_mix(mu1, mu2, sigma1, sigma2, p, N, rv)
|
mu1 |
the mean of Y1 |
mu2 |
the mean of Y2 |
sigma1 |
the EM-estimated variance of Y1 |
sigma2 |
the EM-estimated variance of Y2 |
p |
the probability of the mixture distribution |
N |
the number of samples |
rv |
the random number from mixed normal distribution |
the maximum likelihood estimation of the mean, variance and the mixed probablity
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | ## Not run:
rv_mix<-function(N,p){
u1<-rnorm(N,0,1)
u2<-rnorm(N,2,1)
j<-runif(N)
k<-as.integer(j>p)
u<-k*u1+(1-k)u2
return (u)
}
p<-0.6
N<-1000
set.seed(2335)
rv<-rv_mix(N,p)
p_0<-0.5
mu1<-0.5
mu2<-1.5
sigma1<-sigma2<-sd(rv)
EM<-EM_mix(mu1,sigma1,mu2,sigma2,p_0,N,rv)
sigma1<-EM[2]
sigma2<-EM[4]
p_hat<-EM[5]
Gibbs_mix(mu1,mu2,sigma1,sigma2,p_hat,N,rv)
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.