small fix + attempt for a correct 'tableauRecap'
[valse.git] / test / generate_test_data / helper.R
CommitLineData
ef67d338
BA
1#' Generate a sample of (X,Y) of size n with default values
2#' @param n sample size
3#' @param p number of covariates
4#' @param m size of the response
5#' @param k number of clusters
6#' @return list with X and Y
7#' @export
8generateXYdefault = function(n, p, m, k)
9{
39062512
BA
10 meanX = rep(0, p)
11 covX = diag(p)
12 covY = array(dim=c(m,m,k))
13 for(r in 1:k)
39062512 14 covY[,,r] = diag(m)
39062512
BA
15 pi = rep(1./k,k)
16 #initialize beta to a random number of non-zero random value
17 beta = array(0, dim=c(p,m,k))
18 for (j in 1:p)
19 {
20 nonZeroCount = sample(1:m, 1)
21 beta[j,1:nonZeroCount,] = matrix(runif(nonZeroCount*k), ncol=k)
22 }
23
24 sample_IO = generateXY(meanX, covX, covY, pi, beta, n)
25 return (list(X=sample_IO$X,Y=sample_IO$Y))
ef67d338
BA
26}
27
28#' Initialize the parameters in a basic way (zero for the conditional mean, uniform for weights,
29#' identity for covariance matrices, and uniformly distributed for the clustering)
30#' @param n sample size
31#' @param p number of covariates
32#' @param m size of the response
33#' @param k number of clusters
34#' @return list with phiInit, rhoInit,piInit,gamInit
35#' @export
36basicInitParameters = function(n,p,m,k)
37{
39062512
BA
38 phiInit = array(0, dim=c(p,m,k))
39
40 piInit = (1./k)*rep(1,k)
41
42 rhoInit = array(dim=c(m,m,k))
43 for (i in 1:k)
44 rhoInit[,,i] = diag(m)
45
46 gamInit = 0.1 * matrix(1, nrow=n, ncol=k)
47 R = sample(1:k, n, replace=TRUE)
48 for (i in 1:n)
49 gamInit[i,R[i]] = 0.9
50 gamInit = gamInit/sum(gamInit[1,])
51
52 return (list("phiInit" = phiInit, "rhoInit" = rhoInit, "piInit" = piInit, "gamInit" = gamInit))
ef67d338 53}