\name{fit_inter_sae}
\alias{fit_inter_sae}
\alias{inter_estimates}
\alias{margin_diagnostics}
\alias{print.inter_sae}
\alias{summary.inter_sae}
\alias{print.summary_inter_sae}
\alias{plot.inter_sae}
\title{Fit and Inspect Intersectional Small Area Estimates}
\usage{
fit_inter_sae(formula, design, margins,
  family = c("gaussian", "binomial"), domain = NULL, prior = 0.5,
  max_iter = 1000L, tol = 1e-8, residual_correction = TRUE,
  max_cells = 1e6, model_args = list())

inter_estimates(object, statistic = c("mean", "total", "both"))

margin_diagnostics(object)

\method{print}{inter_sae}(x, ...)

\method{summary}{inter_sae}(object, ...)

\method{print}{summary_inter_sae}(x, ...)

\method{plot}{inter_sae}(x, y = NULL, compare_direct = TRUE, ...)
}
\arguments{
\item{formula}{Outcome model formula. Every predictor must occur among the
census-margin dimensions.}
\item{design}{An object returned by \code{inter_design()}.}
\item{margins}{An object returned by \code{census_margins()}.}
\item{family}{Gaussian or binomial response family.}
\item{domain}{Character vector of output-domain dimensions.}
\item{prior}{Positive seed added to every feasible latent population cell.}
\item{max_iter}{Maximum generalized iterative-proportional-fitting iterations.}
\item{tol}{Relative convergence tolerance.}
\item{residual_correction}{Add a calibrated survey-residual correction.}
\item{max_cells}{Maximum permitted latent-table size.}
\item{model_args}{Optional arguments passed to \code{stats::glm()}.}
\item{object,x}{A fitted \code{inter_sae} object.}
\item{statistic}{Extract means/proportions, totals, or both.}
\item{y}{Ignored.}
\item{compare_direct}{Overlay direct survey estimates in the plot.}
\item{...}{Additional printing or plotting arguments.}
}
\value{
\code{fit_inter_sae()} returns an \code{inter_sae} object.
\code{inter_estimates()} and \code{margin_diagnostics()} return data frames.
The summary method returns a \code{summary_inter_sae} object. The plot method
returns the plotted data invisibly.
}
\description{
Reconstruct a coherent latent joint population table, fit a survey-weighted
outcome model, and calculate augmented model-assisted estimates.
}
\details{
For binomial outcomes the working model uses a quasibinomial likelihood so
non-integer survey weights are interpreted as analytic weights. Returned
estimates remain proportions on the response scale.
}
\examples{
example_data <- inter_example()
design <- inter_design(example_data$survey, "weight", "area",
  "strata", "psu")
margins <- census_margins(example_data$margins)
fit <- fit_inter_sae(unemployed ~ sex + age + residence + area,
  design, margins, family = "binomial", domain = c("area", "sex"))
head(inter_estimates(fit))
max(margin_diagnostics(fit)$relative_error)
summary(fit)
}
