correction typo
[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 require(mvtnorm)
20 X = rmvnorm(n, mean = rep(0,p), sigma = covX)
21
22 require(MASS) #simulate from a multivariate normal distribution
23 for (i in 1:n)
24 {
25
26 for (r in 1:k)
27 {
28 BXir = rep(0,m)
29 for (mm in 1:m)
30 BXir[mm] = X[i,] %*% beta[,mm,r]
31 Y[i,] = Y[i,] + pi[r] * mvrnorm(1,BXir, covY[,,r])
32 }
33 }
34
35 return (list(X=X,Y=Y))
36 }