fix for m==1
[valse.git] / pkg / R / computeGridLambda.R
CommitLineData
ffdf9447 1#' computeGridLambda
086ca318 2#'
d1531659 3#' Construct the data-driven grid for the regularization parameters used for the Lasso estimator
086ca318 4#'
d1531659 5#' @param phiInit value for phi
ffdf9447
BA
6#' @param rhoInit\tvalue for rho
7#' @param piInit\tvalue for pi
d1531659 8#' @param gamInit value for gamma
e3f2fe8a 9#' @param X matrix of covariates (of size n*p)
10#' @param Y matrix of responses (of size n*m)
11#' @param gamma power of weights in the penalty
086ca318
BA
12#' @param mini minimum number of iterations in EM algorithm
13#' @param maxi maximum number of iterations in EM algorithm
14#' @param tau threshold to stop EM algorithm
15#'
d1531659 16#' @return the grid of regularization parameters
086ca318 17#'
d1531659 18#' @export
ffdf9447 19computeGridLambda <- function(phiInit, rhoInit, piInit, gamInit, X, Y, gamma, mini,
a3cbbaea 20 maxi, tau, fast)
1b698c16 21{
ffdf9447 22 n <- nrow(X)
ea5860f1
BA
23 p <- ncol(X)
24 m <- ncol(Y)
25 k <- length(piInit)
1b698c16 26
ffdf9447
BA
27 list_EMG <- EMGLLF(phiInit, rhoInit, piInit, gamInit, mini, maxi, gamma, lambda = 0,
28 X, Y, tau, fast)
29 grid <- array(0, dim = c(p, m, k))
30 for (i in 1:p)
31 {
1b698c16
BA
32 for (j in 1:m)
33 grid[i, j, ] <- abs(list_EMG$S[i, j, ])/(n * list_EMG$pi^gamma)
ffdf9447
BA
34 }
35 sort(unique(grid))
39046da6 36}