revert src/test/utils.c
[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)
e166ed4e 4#' @param pi proportion for each cluster
d1531659 5#' @param beta regression matrix
e166ed4e 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{
e166ed4e
BA
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))
39046da6 36}