X-Git-Url: https://git.auder.net/?p=valse.git;a=blobdiff_plain;f=test%2Fgenerate_test_data%2Fhelper.R;h=8ec122bd368f49e5127db6ffc2b5ac9bb8582353;hp=49cd1b5743e66448d6b39fda03474991d3850190;hb=321e13a991a5a0e6c97225fdca436870e5e805d1;hpb=2e813ad23c796bbed3d5ba685b8fa002bdc6689d diff --git a/test/generate_test_data/helper.R b/test/generate_test_data/helper.R index 49cd1b5..8ec122b 100644 --- a/test/generate_test_data/helper.R +++ b/test/generate_test_data/helper.R @@ -1,10 +1,12 @@ #' Generate a sample of (X,Y) of size n with default values +#' #' @param n sample size #' @param p number of covariates #' @param m size of the response #' @param k number of clusters +#' #' @return list with X and Y -#' @export +#' generateXYdefault = function(n, p, m, k) { meanX = rep(0, p) @@ -12,27 +14,30 @@ generateXYdefault = function(n, p, m, k) covY = array(dim=c(m,m,k)) for(r in 1:k) covY[,,r] = diag(m) - pi = rep(1./k,k) + π = rep(1./k,k) #initialize beta to a random number of non-zero random value - beta = array(0, dim=c(p,m,k)) + β = array(0, dim=c(p,m,k)) for (j in 1:p) { nonZeroCount = sample(1:m, 1) - beta[j,1:nonZeroCount,] = matrix(runif(nonZeroCount*k), ncol=k) + β[j,1:nonZeroCount,] = matrix(runif(nonZeroCount*k), ncol=k) } - sample_IO = generateXY(meanX, covX, covY, pi, beta, n) + sample_IO = generateXY(n, π, meanX, β, covX, covY) return (list(X=sample_IO$X,Y=sample_IO$Y)) } -#' Initialize the parameters in a basic way (zero for the conditional mean, uniform for weights, -#' identity for covariance matrices, and uniformly distributed for the clustering) +#' Initialize the parameters in a basic way (zero for the conditional mean, uniform for +#' weights, identity for covariance matrices, and uniformly distributed for the +#' clustering) +#' #' @param n sample size #' @param p number of covariates #' @param m size of the response #' @param k number of clusters +#' #' @return list with phiInit, rhoInit,piInit,gamInit -#' @export +#' basicInitParameters = function(n,p,m,k) { phiInit = array(0, dim=c(p,m,k)) @@ -49,5 +54,5 @@ basicInitParameters = function(n,p,m,k) gamInit[i,R[i]] = 0.9 gamInit = gamInit/sum(gamInit[1,]) - return (list("phiInit" = phiInit, "rhoInit" = rhoInit, "piInit" = piInit, "gamInit" = gamInit)) + return (list("phiInit"=phiInit, "rhoInit"=rhoInit, "piInit"=piInit, "gamInit"=gamInit)) }