utilisation de k-means au lieu de hierarchique dans initSmallEM - PB de dimensions...
[valse.git] / R / generateIO.R
CommitLineData
d1531659 1#' Generate a sample of (X,Y) of size n
f2a91208 2#' @param covX covariance for covariates (of size p*p*K)
3#' @param covY covariance for the response vector (of size m*m*K)
d1531659 4#' @param pi proportion for each cluster
5#' @param beta regression matrix
6#' @param n sample size
f2a91208 7#'
d1531659 8#' @return list with X and Y
9#' @export
10#-----------------------------------------------------------------------
39046da6
BA
11generateIO = function(covX, covY, pi, beta, n)
12{
f2a91208 13 p = dim(covX)[1]
d1531659 14
f2a91208 15 m = dim(covY)[1]
16 k = dim(covY)[3]
d1531659 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))
39046da6 34}