+++ /dev/null
-#' Plot
-#'
-#' It is a function which plots relevant parameters
-#'
-#'
-#' @return several plots
-#'
-#' @examples TODO
-#'
-#' @export
-#'
-plot_valse = function(){
- require("gridExtra")
- require("ggplot2")
- require("reshape2")
-
- ## regression matrices
- gReg = list()
- for (r in 1:K){
- Melt = melt(t((model$phi[,,r])))
- gReg[[r]] = ggplot(data = Melt, aes(x=Var1, y=Var2, fill=value)) + geom_tile() +
- scale_fill_gradient2(low = "blue", high = "red", mid = "white", midpoint = 0, space = "Lab") +
- ggtitle(paste("Regression matrices in cluster",r))
- }
- gReg
-
- ## Differences between two clusters
- k1 = 1
- k2 = 2
- Melt = melt(t(model$phi[,,k1]-model$phi[,,k2]))
- gDiff = ggplot(data = Melt, aes(x=Var1, y=Var2, fill=value)) + geom_tile() +
- scale_fill_gradient2(low = "blue", high = "red", mid = "white", midpoint = 0, space = "Lab") +
- ggtitle(paste("Difference between regression matrices in cluster",k1, "and", k2))
- gDiff
-
- ### Covariance matrices
- matCov = matrix(NA, nrow = dim(model$rho[,,1])[1], ncol = K)
- for (r in 1:K){
- matCov[,r] = diag(model$rho[,,r])
- }
- MeltCov = melt(matCov)
- gCov = ggplot(data =MeltCov, aes(x=Var1, y=Var2, fill=value)) + geom_tile() +
- scale_fill_gradient2(low = "blue", high = "red", mid = "white", midpoint = 0, space = "Lab") +
- ggtitle(paste("Regression matrices in cluster",r))
- gCov
-
- ### proportions
- Gam = matrix(0, ncol = K, nrow = n)
- gam = Gam
- for (i in 1:n){
- for (r in 1:K){
- sqNorm2 = sum( (Y[i,]%*%model$rho[,,r]-X[i,]%*%model$phi[,,r])^2 )
- Gam[i,r] = model$pi[r] * exp(-0.5*sqNorm2)* det(model$rho[,,r])
- }
- gam[i,] = Gam[i,] / sum(Gam[i,])
- }
- affec = apply(gam, 1,which.max)
- gam2 = matrix(NA, ncol = K, nrow = n)
- for (i in 1:n){
- gam2[i, ] = c(gam[i, affec[i]], affec[i])
- }
- bp <- ggplot(data.frame(gam2), aes(x=X2, y=X1, color=X2, group = X2)) +
- geom_boxplot() + theme(legend.position = "none")
- bp + background_grid(major = "xy", minor = "none")
-
- ### Mean in each cluster
- XY = cbind(X,Y)
- XY_class= list()
- meanPerClass= matrix(0, ncol = K, nrow = dim(XY)[2])
- for (r in 1:K){
- XY_class[[r]] = XY[affec == r, ]
- meanPerClass[,r] = apply(XY_class[[r]], 2, mean)
- }
- data = data.frame(mean = as.vector(meanPerClass), cluster = as.character(rep(1:K, each = dim(XY)[2])), time = rep(1:dim(XY)[2],K))
- g = ggplot(data, aes(x=time, y = mean, group = cluster, color = cluster))
- g + geom_line(aes(linetype=cluster, color=cluster))+ geom_point(aes(color=cluster))
-
-}
\ No newline at end of file
beta = list()
p1= 0.5
beta[[1]] =diag(c(rep(p1,5),rep(1,5), rep(p1,5), rep(1, p-15)))
- p2 = 1
+ p2 = 2
beta[[2]] = diag(c(rep(p2,5),rep(1,5), rep(p2,5), rep(1, p-15)))
ARI1 = ARI2 = ARI3 = 0
XYproj[,i] = c(Ax,Dx,Ay,Dy)
}
- res_valse = valse(x,y, kmax=2, verbose=TRUE, plot=FALSE, size_coll_mod = 200)
- res_valse_proj = valse(XYproj[1:p,],XYproj[(p+1):(2*p),], kmax=2, verbose=TRUE, plot=FALSE, size_coll_mod = 200)
+ res_valse = valse(t(x),t(y), kmax=2, verbose=TRUE, plot=FALSE, size_coll_mod = 1000)
+ res_valse_proj = valse(t(XYproj[1:p,]),t(XYproj[(p+1):(2*p),]), kmax=2, verbose=TRUE, plot=FALSE, size_coll_mod = 1000)
save(res_valse,file=paste("Res_",ite, ".RData",sep=""))
save(res_valse_proj,file=paste("ResProj_",ite, ".RData",sep=""))