Here EM algorithm manually implemented, there's a question of the implementation in R of the EM algorithm for 2 mixed gaussians. The answer has a supposedly correct implementation.
However, don't the lines
sigma1 <- sum(tau1*(x-mu1)^2)/sum(tau1)
sigma2 <- sum(tau2*(x-mu2)^2)/sum(tau2)
estimate the variance? In the next iteration of the loop, they use these values to create normal random variables:
dnorm(dat,mean=mu1,sd=sigma1)
dnorm(dat,mean=mu2,sd=sigma2)
so they are assuming that the variables represent the standard deviation. I don't understand why the algorithm works. Should it? Why?