% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/char_thresh_global.R
\name{char_thresh_global}
\alias{char_thresh_global}
\title{Calculate a global threshold value for charcoal peak identification}
\usage{
char_thresh_global(
  charcoal,
  pretreatment,
  peak_analysis,
  site = NULL,
  results = NULL,
  plot_data = 0L,
  bkg_sens_in = 0L
)
}
\arguments{
\item{charcoal}{Named list containing \code{peak} (C_peak series) and
\code{ybpI}.}

\item{pretreatment}{Named list with \code{zoneDiv}.}

\item{peak_analysis}{Named list with \code{cPeak}, \code{threshMethod},
\code{threshValues}.}

\item{site}{Character string (site name; unused in R, kept for API
symmetry).}

\item{results}{Named list (unused in R, kept for API symmetry).}

\item{plot_data}{0/1 flag; ignored in R.}

\item{bkg_sens_in}{0/1 flag; ignored in R (no sensitivity loop).}
}
\value{
Named list \code{char_thresh} with elements:
  \describe{
    \item{possible}{Numeric vector of 251 candidate threshold bins.}
    \item{pos}{Numeric matrix [N x 4]: positive threshold for each of the
      four \code{threshValues}.}
    \item{neg}{Numeric matrix [N x 4] (method 1) or [N x 1] (methods 2-3):
      negative threshold.}
    \item{noise_pdf}{Estimated noise PDF evaluated at \code{possible}
      (methods 2-3), or scalar \code{-99} (method 1).}
    \item{mu_hat}{Fitted noise-component mean.}
    \item{sigma_hat}{Fitted noise-component standard deviation.}
    \item{SNI}{Signal-to-noise index (scalar).}
    \item{GOF}{Sentinel vector (\code{-999}, length N).}
  }
}
\description{
Determines a single threshold applied uniformly across the entire record.
The noise component of C_peak is modelled as a zero-mean Gaussian
(residuals), a one-mean Gaussian (ratios), or via a Gaussian mixture
model (GMM).  Mirrors \code{CharThreshGlobal.m} from the MATLAB v2.0
codebase.
}
\details{
## Gaussian assumption (threshMethod = 2)
  For residuals (\code{cPeak = 1}): noise is zero-mean; sigma is estimated
  from the negative half of C_peak, mirrored and pooled.
  For ratios (\code{cPeak = 2}): noise is one-mean; values are shifted to
  zero, mirrored, shifted back, and sigma estimated from the pooled set.

  ## GMM (threshMethod = 3)
  MATLAB's \code{GaussianMixture(X, 2, 2, false)} is replicated by
  \code{gaussian_mixture_em(X)} from \code{utils_gaussian_mixture.R}, using
  the same first/last-point initialisation and loose convergence criterion as
  the original Bowman CLUSTER EM.  The noise component is identified as the
  Gaussian with the smaller mean (matching MATLAB's
  \code{noiseIdx = find(mu == min(mu), 1)}).

  ## Bin-lookup for threshold values
  Percentile thresholds are mapped to the nearest bin in
  \code{possible} (251 equally-spaced values spanning C_peak range).
  The v2.0 bug fix is preserved: both sides of the \code{abs()} comparison
  use the CHAR-unit threshold value \code{thresh[i]}, not the raw percentile.
}
\seealso{
[char_thresh_local()], [char_smooth()], [CharAnalysis()]
}
