3 #' It is a function which plots relevant parameters
6 #' @return several plots
12 plot_valse = function(){
17 ## regression matrices
20 Melt = melt(t((model$phi[,,r])))
21 gReg[[r]] = ggplot(data = Melt, aes(x=Var1, y=Var2, fill=value)) + geom_tile() +
22 scale_fill_gradient2(low = "blue", high = "red", mid = "white", midpoint = 0, space = "Lab") +
23 ggtitle(paste("Regression matrices in cluster",r))
27 ## Differences between two clusters
30 Melt = melt(t(model$phi[,,k1]-model$phi[,,k2]))
31 gDiff = ggplot(data = Melt, aes(x=Var1, y=Var2, fill=value)) + geom_tile() +
32 scale_fill_gradient2(low = "blue", high = "red", mid = "white", midpoint = 0, space = "Lab") +
33 ggtitle(paste("Difference between regression matrices in cluster",k1, "and", k2))
36 ### Covariance matrices
37 matCov = matrix(NA, nrow = dim(model$rho[,,1])[1], ncol = K)
39 matCov[,r] = diag(model$rho[,,r])
41 MeltCov = melt(matCov)
42 gCov = ggplot(data =MeltCov, aes(x=Var1, y=Var2, fill=value)) + geom_tile() +
43 scale_fill_gradient2(low = "blue", high = "red", mid = "white", midpoint = 0, space = "Lab") +
44 ggtitle("Covariance matrices")
48 Gam = matrix(0, ncol = K, nrow = n)
52 sqNorm2 = sum( (Y[i,]%*%model$rho[,,r]-X[i,]%*%model$phi[,,r])^2 )
53 Gam[i,r] = model$pi[r] * exp(-0.5*sqNorm2)* det(model$rho[,,r])
55 gam[i,] = Gam[i,] / sum(Gam[i,])
57 affec = apply(gam, 1,which.max)
58 gam2 = matrix(NA, ncol = K, nrow = n)
60 gam2[i, ] = c(gam[i, affec[i]], affec[i])
62 bp <- ggplot(data.frame(gam2), aes(x=X2, y=X1, color=X2, group = X2)) +
63 geom_boxplot() + theme(legend.position = "none")
64 print(bp + background_grid(major = "xy", minor = "none"))
66 ### Mean in each cluster
69 meanPerClass= matrix(0, ncol = K, nrow = dim(XY)[2])
71 XY_class[[r]] = XY[affec == r, ]
72 meanPerClass[,r] = apply(XY_class[[r]], 2, mean)
74 data = data.frame(mean = as.vector(meanPerClass), cluster = as.character(rep(1:K, each = dim(XY)[2])), time = rep(1:dim(XY)[2],K))
75 g = ggplot(data, aes(x=time, y = mean, group = cluster, color = cluster))
76 print(g + geom_line(aes(linetype=cluster, color=cluster))+ geom_point(aes(color=cluster)) + ggtitle('Mean per cluster'))