% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/bayes_enrich.R
\name{bayes_enrich}
\alias{bayes_enrich}
\title{Bayesian term selection for enrichment results}
\usage{
bayes_enrich(
  x,
  candidate = c("top", "significant", "all"),
  n_terms = 200,
  by = "p.adjust",
  prior = 0.1,
  false_positive = 0.01,
  false_negative = 0.1,
  n_iter = 5000,
  burnin = 1000,
  thin = 1,
  posterior_cutoff = 0.5,
  seed = NULL,
  verbose = FALSE
)
}
\arguments{
\item{x}{An \code{enrichResult} object, typically from \code{ora_gson()} or a package
that builds on enrichit, such as clusterProfiler.}

\item{candidate}{Candidate terms to include. \code{"significant"} uses
\code{as.data.frame(x)}, \code{"all"} uses \code{x@result}, \code{"top"} uses the top
\code{n_terms} rows from \code{x@result} ordered by \code{by}; or provide a character
vector of term IDs.}

\item{n_terms}{Maximum number of candidate terms when \code{candidate = "top"} or
when more candidates are supplied than this value. Use \code{Inf} to disable.}

\item{by}{Column used to order candidate terms.}

\item{prior}{Prior probability that a term is active.}

\item{false_positive}{Probability of observing a gene not covered by active
terms.}

\item{false_negative}{Probability of missing a gene covered by active terms.}

\item{n_iter}{Total number of MCMC iterations.}

\item{burnin}{Number of initial iterations discarded.}

\item{thin}{Keep one sample every \code{thin} iterations after burn-in.}

\item{posterior_cutoff}{Terms with posterior greater than or equal to this
value are marked active.}

\item{seed}{Optional random seed.}

\item{verbose}{Print sampler progress.}
}
\value{
The input \code{enrichResult} object with additional columns in
\verb{@result}: \code{posterior}, \code{posterior_odds}, \code{bayes_rank},
\code{bayes_active}, \code{bayes_covered_gene}, and \code{bayes_covered_count}.
}
\description{
\code{bayes_enrich()} adds a model-based selection layer on top of ORA results.
It estimates the posterior probability that each candidate term is an
active biological program explaining the observed input genes.
}
\details{
The implementation uses a lightweight Metropolis-Hastings sampler over
binary latent term states. Given active terms, each gene is modeled as
observed with probability \code{1 - false_negative} if covered by at least one
active term, and with probability \code{false_positive} otherwise. The prior
probability that a candidate term is active is \code{prior}.

This is intended as a result-compression and interpretation layer, not as a
replacement for ORA p-values.
}
