utilisation de k-means au lieu de hierarchique dans initSmallEM - PB de dimensions...
[valse.git] / R / generateIO.R
1 #' Generate a sample of (X,Y) of size n
2 #' @param covX covariance for covariates (of size p*p*K)
3 #' @param covY covariance for the response vector (of size m*m*K)
4 #' @param pi proportion for each cluster
5 #' @param beta regression matrix
6 #' @param n sample size
7 #'
8 #' @return list with X and Y
9 #' @export
10 #-----------------------------------------------------------------------
11 generateIO = function(covX, covY, pi, beta, n)
12 {
13 p = dim(covX)[1]
14
15 m = dim(covY)[1]
16 k = dim(covY)[3]
17
18 Y = matrix(0,n,m)
19 BX = array(0, dim=c(n,m,k))
20
21 require(MASS) #simulate from a multivariate normal distribution
22 for (i in 1:n)
23 {
24 for (r in 1:k)
25 {
26 BXir = rep(0,m)
27 for (mm in 1:m)
28 Bxir[[mm]] = X[i,] %*% beta[,mm,r]
29 Y[i,] = Y[i,] + pi[r] * mvrnorm(1,BXir, covY[,,r])
30 }
31 }
32
33 return (list(X=X,Y=Y))
34 }