2 #' It is a function which construct, for a given lambda, the sets of
3 #' relevant variables and irrelevant variables.
5 #' @param phiInit an initial estimator for phi (size: p*m*k)
6 #' @param rhoInit an initial estimator for rho (size: m*m*k)
7 #' @param piInit an initial estimator for pi (size : k)
8 #' @param gamInit an initial estimator for gamma
9 #' @param mini minimum number of iterations in EM algorithm
10 #' @param maxi maximum number of iterations in EM algorithm
11 #' @param gamma power in the penalty
12 #' @param glambda grid of regularization parameters
13 #' @param X matrix of regressors
14 #' @param Y matrix of responses
15 #' @param thres threshold to consider a coefficient to be equal to 0
16 #' @param tau threshold to say that EM algorithm has converged
23 selectVariables <- function(phiInit,rhoInit,piInit,gamInit,
24 mini,maxi,gamma,glambda,X,Y,thres,tau)
26 dimphi <- dim(phiInit)
31 A1 <- array(0, dim <- c(p,m+1,L))
32 A2 <- array(0, dim <- c(p,m+1,L))
33 Rho <- array(0, dim <- c(m,m,k,L))
34 Pi <- array(0, dim <- c(k,L));
36 # For every lambda in gridLambda, comutation of the coefficients
37 for (lambdaIndex in c(1:L))
39 Res <- EMGLLF(phiInit,rhoInit,piInit,gamInit,mini,maxi,
40 gamma,glambda[lambdaIndex],X,Y,tau);
45 # If a coefficient is larger than the threshold, we keep it
46 selectedVariables <- array(0, dim = c(p,m))
47 discardedVariables <- array(0, dim = c(p,m))
48 atLeastOneSelectedVariable <- false
55 if (max(abs(phi[j,mm,])) > thres)
57 selectedVariables[j,cpt] <- mm
59 atLeastOneSelectedVariable <- true
62 discardedVariables[j,cpt2] <- mm
68 # If no coefficients have been selected, we provide the zero matrix
69 # We delete zero coefficients: vec = indices of zero values
70 if (atLeastOneSelectedVariable)
75 if (selectedVariables(j,1) != 0)
77 # Else ( NOTE: [auder] else ?! TODO: explain? )
78 # we provide the indices of relevant coefficients
79 A1[,1,lambdaIndex] <- c(vec,rep(0,p-length(vec)))
80 A1[1:length(vec),2:(m+1),lambdaIndex] <- selectedVariables[vec,]
81 A2[,1,lambdaIndex] <- 1:p
82 A2[,2:(m+1),lambdaIndex] <- discardedVariables
83 Rho[,,,lambdaIndex] <- rho
84 Pi[,lambdaIndex] <- pi
89 return(res = list(A1 = A1, A2 = A2 , Rho = Rho, Pi = Pi))