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 n sample size
9 #' @return several plots
15 plot_valse <- function(X, Y, model, n, comp = FALSE, k1 = NA, k2 = NA)
23 ## regression matrices
27 Melt <- melt(t((model$phi[, , r])))
28 gReg[[r]] <- ggplot(data = Melt, aes(x = Var1, y = Var2, fill = value)) +
29 geom_tile() + scale_fill_gradient2(low = "blue", high = "red", mid = "white",
30 midpoint = 0, space = "Lab") + ggtitle(paste("Regression matrices in cluster", r))
34 ## Differences between two clusters
37 if (is.na(k1) || is.na(k))
38 print("k1 and k2 must be integers, representing the clusters you want to compare")
39 Melt <- melt(t(model$phi[, , k1] - model$phi[, , k2]))
40 gDiff <- ggplot(data = Melt, aes(x = Var1, y = Var2, fill = value))
42 + scale_fill_gradient2(low = "blue", high = "red", mid = "white", midpoint = 0,
44 + ggtitle(paste("Difference between regression matrices in cluster",
49 ### Covariance matrices
50 matCov <- matrix(NA, nrow = dim(model$rho[, , 1])[1], ncol = K)
52 matCov[, r] <- diag(model$rho[, , r])
53 MeltCov <- melt(matCov)
54 gCov <- ggplot(data = MeltCov, aes(x = Var1, y = Var2, fill = value)) + geom_tile()
55 + scale_fill_gradient2(low = "blue", high = "red", mid = "white", midpoint = 0,
57 + ggtitle("Covariance matrices")
61 gam2 <- matrix(NA, ncol = K, nrow = n)
63 gam2[i, ] <- c(model$proba[i, model$affec[i]], model$affec[i])
65 bp <- ggplot(data.frame(gam2), aes(x = X2, y = X1, color = X2, group = X2))
67 + theme(legend.position = "none")
68 + background_grid(major = "xy", minor = "none")
71 ### Mean in each cluster
74 meanPerClass <- matrix(0, ncol = K, nrow = dim(XY)[2])
77 XY_class[[r]] <- XY[model$affec == r, ]
78 if (sum(model$affec == r) == 1) {
79 meanPerClass[, r] <- XY_class[[r]]
81 meanPerClass[, r] <- apply(XY_class[[r]], 2, mean)
84 data <- data.frame(mean = as.vector(meanPerClass),
85 cluster = as.character(rep(1:K, each = dim(XY)[2])), time = rep(1:dim(XY)[2], K))
86 g <- ggplot(data, aes(x = time, y = mean, group = cluster, color = cluster))
87 print(g + geom_line(aes(linetype = cluster, color = cluster))
88 + geom_point(aes(color = cluster)) + ggtitle("Mean per cluster"))