% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/sensitivity-analysis.R
\name{classification_robustness}
\alias{classification_robustness}
\title{Robustness of classification under input perturbation}
\usage{
classification_robustness(
  pedon,
  system = c("wrb2022", "sibcs", "usda"),
  level = c("order", "name"),
  n = 50L,
  perturbations = NULL,
  seed = 42L
)
}
\arguments{
\item{pedon}{A \code{\link{PedonRecord}}.}

\item{system}{One of \code{"wrb2022"}, \code{"sibcs"}, \code{"usda"}.}

\item{level}{Either \code{"order"} (compare \code{$rsg_or_order})
or \code{"name"} (compare full classification name).}

\item{n}{Number of Monte-Carlo perturbed runs (default 50).}

\item{perturbations}{Named list. Each name is a horizon column;
each element is a function taking the original value and
returning a perturbed value. NA-tolerant.}

\item{seed}{Integer applied through \code{\link[withr]{with_seed}}
so the Monte-Carlo draws are reproducible \emph{without}
mutating the caller's global RNG state. Pass \code{NULL} to
leave the RNG stream untouched. Default \code{42L} preserves
the bit-for-bit-identical output earlier soilKey releases
produced (CRAN policy: never call \code{set.seed()} on the
caller's RNG).}
}
\value{
A list with elements \code{baseline} (the unperturbed
        classification name), \code{n} (number of MC runs),
        \code{robustness} (fraction of perturbed runs matching
        baseline), \code{flipped_to} (table of alternative
        classifications when the perturbation flipped the result).
}
\description{
For a given \code{\link{PedonRecord}}, perturb a chosen list of
horizon attributes by a configured fractional amount, re-classify
under the requested system, and report how often the classification
\code{$rsg_or_order} (or full \code{$name}) matches the unperturbed
baseline.
}
\details{
Default perturbation panel:
\itemize{
  \item \code{clay_pct}: ±5 % of value
  \item \code{sand_pct}: ±5 % of value
  \item \code{silt_pct}: ±5 % of value
  \item \code{ph_h2o}: ±0.2 absolute
  \item \code{oc_pct}: ±10 % of value
}
}
\examples{
\donttest{
p <- make_ferralsol_canonical()
classification_robustness(p, system = "wrb2022", n = 50)
#> $baseline    : "Ferralsols"
#> $robustness  : 0.96  (48 / 50 perturbed runs landed on Ferralsols)
#> $flipped_to  : table(c("Cambisols" = 1, "Acrisols" = 1))
}
}
