3 #' It is a function which plots relevant parameters
5 #' @param X matrix of covariates (of size n*p)
6 #' @param Y matrix of responses (of size n*m)
7 #' @param model the model constructed by valse procedure
8 #' @param comp TRUE to enable pairwise clusters comparison
9 #' @param k1 index of the first cluster to be compared
10 #' @param k2 index of the second cluster to be compared
12 #' @importFrom ggplot2 ggplot aes ggtitle geom_tile geom_line geom_point scale_fill_gradient2 geom_boxplot theme
13 #' @importFrom cowplot background_grid
14 #' @importFrom reshape2 melt
17 plot_valse <- function(X, Y, model, comp = FALSE, k1 = NA, k2 = NA)
21 ## regression matrices
25 Melt <- melt(t((model$phi[, , r])))
26 gReg[[r]] <- ggplot(data = Melt, aes(x = Var1, y = Var2, fill = value)) +
27 geom_tile() + scale_fill_gradient2(low = "blue", high = "red", mid = "white",
28 midpoint = 0, space = "Lab") + ggtitle(paste("Regression matrices in cluster", r))
32 ## Differences between two clusters
35 if (is.na(k1) || is.na(k2))
36 print("k1 and k2 must be integers, representing the clusters you want to compare")
37 Melt <- melt(t(model$phi[, , k1] - model$phi[, , k2]))
38 gDiff <- ggplot(data = Melt, aes(x = Var1, y = Var2, fill = value)) +
39 geom_tile() + scale_fill_gradient2(low = "blue", high = "red", mid = "white", midpoint = 0,
40 space = "Lab") + ggtitle(paste("Difference between regression matrices in cluster",
45 ### Covariance matrices
46 matCov <- matrix(NA, nrow = dim(model$rho[, , 1])[1], ncol = K)
48 matCov[, r] <- diag(model$rho[, , r])
49 MeltCov <- melt(matCov)
50 gCov <- ggplot(data = MeltCov, aes(x = Var1, y = Var2, fill = value)) + geom_tile() +
51 scale_fill_gradient2(low = "blue", high = "red", mid = "white", midpoint = 0,
52 space = "Lab") + ggtitle("Covariance matrices (diag., one row per cluster)")
56 gam2 <- matrix(NA, ncol = K, nrow = n)
58 gam2[i, ] <- c(model$proba[i, model$affec[i]], model$affec[i])
60 bp <- ggplot(data.frame(gam2), aes(x = X2, y = X1, color = X2, group = X2)) + geom_boxplot() +
61 theme(legend.position = "none") + background_grid(major = "xy", minor = "none") +
62 ggtitle("Assignment boxplot per cluster")