X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=pkg%2FR%2FEMGLLF.R;h=bf4476b63d839fc1f260ff7b005309f32e80d4af;hb=228ee602a972fcac6177db0d539bf9d0c5fa477f;hp=f944f98e38ca48fcac75c73cd3ac2074551d06e9;hpb=ca277ac5ab51fef149014eb5e4610403fdb3227b;p=valse.git diff --git a/pkg/R/EMGLLF.R b/pkg/R/EMGLLF.R index f944f98..bf4476b 100644 --- a/pkg/R/EMGLLF.R +++ b/pkg/R/EMGLLF.R @@ -47,15 +47,20 @@ EMGLLF <- function(phiInit, rhoInit, piInit, gamInit, mini, maxi, gamma, lambda, .EMGLLF_R <- function(phiInit, rhoInit, piInit, gamInit, mini, maxi, gamma, lambda, X, Y, eps) { - # Matrix dimensions: NOTE: phiInit *must* be an array (even if p==1) - n <- dim(Y)[1] - p <- dim(phiInit)[1] - m <- dim(phiInit)[2] - k <- dim(phiInit)[3] + # Matrix dimensions + n <- nrow(X) + p <- ncol(X) + m <- ncol(Y) + k <- length(piInit) + + # Adjustments required when p==1 or m==1 (var.sel. or output dim 1) + if (p==1 || m==1) + phiInit <- array(phiInit, dim=c(p,m,k)) + if (m==1) + rhoInit <- array(rhoInit, dim=c(m,m,k)) # Outputs - phi <- array(NA, dim = c(p, m, k)) - phi[1:p, , ] <- phiInit + phi <- phiInit rho <- rhoInit pi <- piInit llh <- -Inf @@ -155,7 +160,7 @@ EMGLLF <- function(phiInit, rhoInit, piInit, gamInit, mini, maxi, gamma, lambda, ## E step # Precompute det(rho[,,r]) for r in 1...k - detRho <- sapply(1:k, function(r) det(rho[, , r])) + detRho <- sapply(1:k, function(r) gdet(rho[, , r])) sumLogLLH <- 0 for (i in 1:n) {