R/obtain_prediction.R

Defines functions obtain_prediction

obtain_prediction <- function(Priorprobs) {
  depth <- (ncol(Priorprobs) - 2) / 2
  prediction <- rep(NA, depth)
  prediction_names <- rep(NA, depth)

  for (i in 1:length(prediction)) {
    if (i == 1) {
      df <- Priorprobs
    } else {
      df <- Priorprobs[Priorprobs[, i - 1] == best, ]
    }
    prob <- tapply(df$predicted_probs, df[, i], sum)
    best <- names(which.max(prob))
    prediction[i] <- prob[which.max(prob)]
    prediction_names[i] <- best
  }
  out <- c(unname(prediction_names), unname(prediction))
  return(out)
}
alessandrozito/BayesANT documentation built on April 5, 2025, 6:22 a.m.