% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/plotting_helpers.R
\name{plot_BRRAT_population}
\alias{plot_BRRAT_population}
\title{Population-level line and credible band}
\usage{
plot_BRRAT_population(fit_obj, n_grid = 200, level = 0.95)
}
\arguments{
\item{fit_obj}{A fitted object returned by \code{\link[=BRRAT]{BRRAT()}}, of class \code{BRRAT}.}

\item{n_grid}{Integer; number of x points for the prediction grid (default \code{200}).}

\item{level}{Credible interval level for the band (default \code{0.95}).}
}
\value{
A \code{ggplot2} object showing the population regression line and credible band.
}
\description{
Plots the \strong{population-level} regression line \eqn{\alpha + \beta x} and its
equal-tail credible band by transforming the x-grid to the centered/scaled space
used during fitting. The plot overlays a (potentially downsampled) scatter of the
original observations for context.
}
\details{
Plot population-level regression Qe ~ P with uncertainty band

The function extracts posterior draws of \code{alpha} and \code{beta} from the Stan fit and
evaluates \eqn{\mu(x) = \alpha + \beta x} along a grid of x values on the original
scale, internally converting to the centered/scaled space via
\eqn{x_{\mathrm{std}} = (x - x_{\mathrm{center}}) / x_{\mathrm{scale}}}.
}
\examples{
\donttest{
set.seed(1)
samples <- 30
Clim <- sort(pmax(0, rnorm(samples, 600, 100)))
observed <- pmax(0, (Clim - 150) - 450 * tanh((Clim - 150) / 450))
Obs <- data.frame(P = Clim, Q = observed, year = 1:samples)
Sim <- data.frame(Q = observed * rnorm(samples, 1, 0.05), year = 1:samples)
res <- BRRAT(Sim, Obs, chains = 1, iter = 500)
p_pop <- plot_BRRAT_population(res, n_grid = 200, level = 0.95)
print(p_pop)
}

}
