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