I have the same feeling. This is as closest as I've come:
http://www.cs.cmu.edu/~kbe/dp_tutorial.pdf
The algorithm explained starting at page 37 is understandable, however I still wish to see a very simple example written out step by step so I'm more confident of which each term means.
I attempted to implement the algorithm in R, below is my code, not efficient and not sure if it is all correct!
#Dirichlet mixture of normals
#flat prior on mu - posterior normal
#flat prior on precision - posterior gamma
###generate data
library(mixtools)
n=100
x=rnormmix(n,lambda=c(.5,.5),mu=c(-4,2),sigma=c(1,1))
###get probs for each component
cProbs=function(x,c,etamu,etavar,alpha,i,n){
c1=c[-i]
cProb=rep(NA,length(unique(c1)))
for(j in 1:length(cProb))
cProb[j]=length(which(c1==unique(c1)[j]))/(n-1+alpha)*dnorm(x[i],etamu[j],sqrt(etavar[j]))
return(cProb)
}
###get probs for new component
newProb=function(x,alpha,i,n){
s=sqrt(sum((x-mean(x))^2)/(n-1))
#predictive distribution is t
newProb1=alpha/(n-1+alpha)*dt((x[i]-mean(x))/(s*sqrt(1+1/n)),n-1)
return(newProb1)
}
#parms
alpha=.01
nsim=100
#initialize
etamu=mean(x)
etavar=var(x)
c=rep(1,n)
idx=0
#loop
repeat{
idx=idx+1
for(i in 1:n){
####if c_i singleton remove
if(sum(c==c[i])==1){
etamu=etamu[-c[i]]
etavar=etavar[-c[i]]
c[c>c[i]]=c[c>c[i]]-1
c[i]=1
}
####draw new c_i
#get probabilities for components
probsExisting=cProbs(x,c,etamu,etavar,alpha,i,n)
newP=newProb(x,alpha,i,n)
#sample
temp=sample(1:(length(unique(c))+1),size=1,prob=c(probsExisting,newP))
newC=ifelse(temp==length(unique(c))+1,1,0)
c[i]=temp
####if new c_i draw new eta
if(newC==1){
#var: posterior is inverse gamma
newVar1=1/rgamma(1,(n-1)/2,(n-1)/2*sum((x-mean(x))^2)/(n-1))
etavar=c(etavar,newVar1)
#mean: posterior is normal
newMean1=rnorm(1,x[i],sqrt(newVar1/n))
etamu=c(etamu,newMean1)
}
} #end loop over observations
#updata etas
for(i in 1:length(unique(c))){
n1=sum(c==i)
if(n1>1){
temp=x[which(c==i)]
etavar[i]=1/rgamma(1,(n1-1)/2,(n1-1)/2*sum((temp-mean(temp))^2)/(n1-1))
etamu[i]=rnorm(1,mean(temp),sqrt(etavar[i]/n1))
}
} #end update etas
if(idx==nsim) break
} #end repeat
###plot results
probs=rep(NA,length(etamu))
for(i in 1:length(probs))
probs[i]=sum(c==i)/n
grid=seq(min(x)-1,max(x)+1,length=500)
dens=rep(NA,length=length(grid))
for(i in 1:length(grid))
dens[i]=sum(probs*dnorm(grid[i],etamu,sqrt(etavar)))
hist(x,freq=FALSE)
lines(grid,dens,col='red',lwd=2)