ourMELONS/R/computePopulationLogml.R
Waldir Leoncio fca9caa731 Restyled files
Ran through styler::style_dir() in the R and tests directories in preparation for #23.
2021-11-10 14:25:50 +01:00

36 lines
1.2 KiB
R

computePopulationLogml <- function(pops, adjprior, priorTerm) {
# Palauttaa length(pops)*1 taulukon, jossa on laskettu korikohtaiset
# ======================================================== #
# Limiting COUNTS size #
# ======================================================== #
COUNTS <- COUNTS[seq_len(nrow(adjprior)), seq_len(ncol(adjprior)), pops, drop = FALSE]
x <- size(COUNTS, 1)
y <- size(COUNTS, 2)
z <- length(pops)
# ======================================================== #
# Computation #
# ======================================================== #
isarray <- length(dim(repmat(adjprior, c(1, 1, length(pops))))) > 2
# FIXME: 3rd dimension of COUNTS getting dropped
term1 <- squeeze(
sum(
sum(
reshape(
lgamma(
repmat(adjprior, c(1, 1, length(pops))) +
COUNTS[seq_len(nrow(adjprior)), seq_len(ncol(adjprior)), pops, drop = !isarray]
),
c(x, y, z)
),
1
),
2
)
)
if (is.null(priorTerm)) priorTerm <- 0
popLogml <- term1 - sum(lgamma(1 + SUMCOUNTS[pops, ]), 2) - priorTerm
return(popLogml)
}