ourMELONS/R/computePopulationLogml.R

22 lines
938 B
R
Raw Permalink Normal View History

2021-02-15 09:49:21 +01:00
computePopulationLogml <- function(pops, adjprior, priorTerm) {
# Palauttaa length(pops)*1 taulukon, jossa on laskettu korikohtaiset
2020-10-19 14:08:25 +02:00
nr <- seq_len(nrow(adjprior))
nc <- seq_len(ncol(adjprior))
2021-02-01 09:22:58 +01:00
x <- size(globals$COUNTS, 1)
y <- size(globals$COUNTS, 2)
z <- length(pops)
2020-10-19 14:08:25 +02:00
# ======================================================== #
# Computation #
# ======================================================== #
rep_adj <- repmat(adjprior, c(1, 1, z))
gamma_rep_counts <- matlab2r::gammaln(rep_adj + globals$COUNTS[, , pops])
gamma_sum_counts <- rowSums(matlab2r::gammaln(1 + globals$SUMCOUNTS[pops, , drop = FALSE]))
gamma_rep_counts_sum <- colSums(colSums(reshape(gamma_rep_counts, c(x, y, z))))
gamma_rep_counts_reshaped <- squeeze(gamma_rep_counts_sum)
popLogml <- gamma_rep_counts_reshaped - gamma_sum_counts - priorTerm
return(popLogml[, , drop = FALSE])
}