1 vec_bin = function(X,r)
16 return (list(Z=Z,indice=indice))
19 initSmallEM = function(k,X,Y,tau)
25 betaInit1 = array(0, dim=c(p,m,k,20))
26 sigmaInit1 = array(0, dim = c(m,m,k,20))
27 phiInit1 = array(0, dim = c(p,m,k,20))
28 rhoInit1 = array(0, dim = c(m,m,k,20))
29 piInit1 = matrix(0,20,k)
30 gamInit1 = array(0, dim=c(n,k,20))
33 require(MASS) #Moore-Penrose generalized inverse of matrix
36 clusters = hclust(dist(y)) #default distance : euclidean
37 #cutree retourne les indices (à quel cluster indiv_i appartient) d'un clustering hierarchique
38 clusterCut = cutree(clusters,k)
39 Zinit1[,repet] = clusterCut
45 Z_vec = Z_bin$Z #vecteur 0 et 1 aux endroits où Z==r
46 Z_indice = Z_bin$indice #renvoit les indices où Z==r
48 betaInit1[,,r,repet] =
49 ginv(t(x[Z_indice,])%*%x[Z_indice,])%*%t(x[Z_indice,])%*%y[Z_indice,]
50 sigmaInit1[,,r,repet] = diag(m)
51 phiInit1[,,r,repet] = betaInit1[,,r,repet]/sigmaInit1[,,r,repet]
52 rhoInit1[,,r,repet] = solve(sigmaInit1[,,r,repet])
53 piInit1[repet,r] = sum(Z_vec)/n
60 dotProduct = (y[i,]%*%rhoInit1[,,r,repet]-x[i,]%*%phiInit1[,,r,repet]) %*%
61 (y[i,]%*%rhoInit1[,,r,repet]-x[i,]%*%phiInit1[,,r,repet])
62 Gam[i,r] = piInit1[repet,r]*det(rhoInit1[,,r,repet])*exp(-0.5*dotProduct)
64 sumGamI = sum(gam[i,])
65 gamInit1[i,,repet]= Gam[i,] / sumGamI
71 new_EMG = .Call("EMGLLF",phiInit1[,,,repet],rhoInit1[,,,repet],piInit1[repet,],
72 gamInit1[,,repet],miniInit,maxiInit,1,0,x,y,tau)
73 LLFEessai = new_EMG$LLF
74 LLFinit1[repet] = LLFEessai[length(LLFEessai)]
77 b = which.max(LLFinit1)
78 phiInit = phiInit1[,,,b]
79 rhoInit = rhoInit1[,,,b]
81 gamInit = gamInit1[,,b]
83 return (list(phiInit=phiInit, rhoInit=rhoInit, piInit=piInit, gamInit=gamInit))