nobs<-scan("bimix.dat",n=1)
x<-matrix(scan("bimix.dat",skip=1),nrow=nobs,ncol=2,byrow=TRUE)
pcoff<-rep(.5,2)
C1<-rep(1,3)
C2<-rep(1,3)
C1[2]<-0
C2[2]<-0
p<-rep(0,2)
mu1<-rep(0,2)
mu1[1]<--1
mu2<-rep(0,2)
mu2[1]<-2
S1<-matrix(0,nrow=2,ncol=2)
S2<-matrix(0,nrow=2,ncol=2)
dyn.load("bimix.so",symbol="bimix")
ans<-.C("bimix",nobs=as.integer(nobs),as.double(x),pcoff=as.double(pcoff),
C1=as.double(C1),C2=as.double(C2),mu1=as.double(mu1),mu2=as.double(mu2),
S1=as.double(S1),S2=as.double(S2),p=as.double(p)," -sp -nohess ")
#
# call it again
#
ans<-.C("bimix",nobs=as.integer(nobs),as.double(x),pcoff=as.double(pcoff),
C1=as.double(C1),C2=as.double(C2),mu1=as.double(mu1),mu2=as.double(mu2),
S1=as.double(S1),S2=as.double(S2),p=as.double(p)," -sp -nohess ")
#
dyn.unload("bimix.so")
S1<-matrix(ans$S1,nrow=2)
S2<-matrix(ans$S2,nrow=2)
mu1<-ans$mu1
mu2<-ans$mu2
p<-ans$p
print ("Estimated proportions")
print(p)
print ("Estimated mean for component 1")
print(mu1)
print ("Estimated mean for component 2")
print(mu2)
print ("Estimated covariance matrix for component 1")
print(S1)
print ("Estimated covariance matrix for component 2")
print(S2)

