X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=pkg%2FR%2FselectVariables.R;h=39e54d2792083d315f02c10cad82942368a2e65a;hb=228ee602a972fcac6177db0d539bf9d0c5fa477f;hp=cdc0ec00f672d534d65c8a9b5dfb951b79a5e468;hpb=ca277ac5ab51fef149014eb5e4610403fdb3227b;p=valse.git diff --git a/pkg/R/selectVariables.R b/pkg/R/selectVariables.R index cdc0ec0..39e54d2 100644 --- a/pkg/R/selectVariables.R +++ b/pkg/R/selectVariables.R @@ -37,15 +37,22 @@ selectVariables <- function(phiInit, rhoInit, piInit, gamInit, mini, maxi, gamma params <- EMGLLF(phiInit, rhoInit, piInit, gamInit, mini, maxi, gamma, lambda, X, Y, eps, fast) - p <- dim(phiInit)[1] - m <- dim(phiInit)[2] + p <- ncol(X) + m <- ncol(Y) # selectedVariables: list where element j contains vector of selected variables # in [1,m] selectedVariables <- lapply(1:p, function(j) { # from boolean matrix mxk of selected variables obtain the corresponding boolean # m-vector, and finally return the corresponding indices - seq_len(m)[apply(abs(params$phi[j, , ]) > thresh, 1, any)] + if (m>1) { + seq_len(m)[apply(abs(params$phi[j, , ]) > thresh, 1, any)] + } else { + if (any(params$phi[j, , ] > thresh)) + 1 + else + numeric(0) + } }) list(selected = selectedVariables, Rho = params$rho, Pi = params$pi)