2 #' It is a function which construct, for a given lambda, the sets of relevant variables.
4 #' @param phiInit an initial estimator for phi (size: p*m*k)
5 #' @param rhoInit an initial estimator for rho (size: m*m*k)
6 #' @param piInit an initial estimator for pi (size : k)
7 #' @param gamInit an initial estimator for gamma
8 #' @param mini minimum number of iterations in EM algorithm
9 #' @param maxi maximum number of iterations in EM algorithm
10 #' @param gamma power in the penalty
11 #' @param glambda grid of regularization parameters
12 #' @param X matrix of regressors
13 #' @param Y matrix of responses
14 #' @param thres threshold to consider a coefficient to be equal to 0
15 #' @param tau threshold to say that EM algorithm has converged
17 #' @return a list of outputs, for each lambda in grid: selected,Rho,Pi
22 selectVariables = function(phiInit,rhoInit,piInit,gamInit,mini,maxi,gamma,glambda,X,Y,seuil,tau)
24 cl = parallel::makeCluster( parallel::detectCores() / 4 )
25 parallel::clusterExport(cl=cl,
26 varlist=c("phiInit","rhoInit","gamInit","mini","maxi","glambda","X","Y","seuil","tau"),
28 #Pour chaque lambda de la grille, on calcule les coefficients
29 out = parLapply( 1:L, function(lambdaindex)
31 params = EMGLLF(phiInit,rhoInit,piInit,gamInit,mini,maxi,gamma,glambda[lambdaIndex],X,Y,tau)
35 #selectedVariables: list where element j contains vector of selected variables in [1,m]
36 selectedVariables = lapply(1:p, function(j) {
37 #from boolean matrix mxk of selected variables obtain the corresponding boolean m-vector,
38 #and finally return the corresponding indices
39 seq_len(m)[ apply( abs(params$phi[j,,]) > seuil, 1, any ) ]
42 list("selected"=selectedVariables,"Rho"=params$Rho,"Pi"=params$Pi)
44 parallel::stopCluster(cl)