% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/analysis-totals.R
\name{get_totals}
\alias{get_totals}
\title{Weighted Total for a Survey Design}
\usage{
get_totals(
  design,
  x = NULL,
  group = NULL,
  variance = "ci",
  conf_level = 0.95,
  n_weighted = FALSE,
  decimals = NULL,
  min_cell_n = 30L,
  na.rm = TRUE,
  label_values = TRUE,
  label_vars = TRUE,
  name_style = "surveycore",
  ...,
  .id = NULL,
  .if_missing_var = NULL
)
}
\arguments{
\item{design}{A survey design object: \code{survey_taylor}, \code{survey_replicate},
\code{survey_twophase}, or \code{survey_nonprob}.}

\item{x}{<\code{\link[tidyselect:language]{tidy-select}}> Optional single unquoted
numeric variable name. When \code{NULL} (default), estimates the population
size (sum of weights). When supplied, estimates the weighted sum
(sum of w_i * x_i).}

\item{group}{<\code{\link[tidyselect:language]{tidy-select}}> Optional grouping
variable(s). Default \code{NULL}.}

\item{variance}{\code{NULL} or a character vector from \code{"se"}, \code{"ci"}, \code{"var"},
\code{"cv"}, \code{"moe"}, \code{"deff"}. Default \code{"ci"}.}

\item{conf_level}{Numeric scalar in (0, 1). Default \code{0.95}.}

\item{n_weighted}{Logical. For \code{get_totals(d)} (no variable), equals the
\code{total} column and is included for API uniformity. For variable mode,
adds the sum of weights for non-NA observations. Default \code{FALSE}.}

\item{decimals}{Integer or \code{NULL}. If an integer, rounds all numeric output
columns (e.g., \code{total}, \code{se}, \code{ci_low}, \code{ci_high}) to this many decimal
places. Default \code{NULL} (no rounding).}

\item{min_cell_n}{Integer. Default \code{30L}.}

\item{na.rm}{Logical. If \code{TRUE} (default), \code{NA} values are excluded from
analysis: observations where the analysis variable is \code{NA} are dropped
from calculations, and observations where any group variable is \code{NA} are
excluded from the output. If \code{FALSE}, \code{NA} observations in the analysis
variable are included in calculations, and observations where a group
variable is \code{NA} are collected into their own group row in the output
(appearing after all non-\code{NA} group rows).}

\item{label_values}{Logical. Accepted for API uniformity. Default \code{TRUE}.}

\item{label_vars}{Logical. Accepted for API uniformity. Default \code{TRUE}.}

\item{name_style}{\code{"surveycore"} (default) or \code{"broom"}.}

\item{...}{Unused. Reserved so that \code{.id} and \code{.if_missing_var} remain
named-only when a \code{survey_collection} is passed as \code{design}.}

\item{.id}{Character(1) or \code{NULL}. Column name used to identify each
survey when \code{design} is a \code{\link{survey_collection}}. For collection inputs,
\code{NULL} (the default) resolves to the collection's stored \verb{@id} property.
Pass a non-\code{NULL} value to override. Ignored when \code{design} is a single
survey.}

\item{.if_missing_var}{\code{"error"}, \code{"skip"}, or \code{NULL}. How to handle
surveys in a collection that lack one of the requested NSE variables.
For collection inputs, \code{NULL} (the default) resolves to the collection's
stored \verb{@if_missing_var} property. Pass a non-\code{NULL} value to override.
Ignored when \code{design} is a single survey.}
}
\value{
A \code{survey_totals} tibble (also inheriting \code{survey_result}). Columns:
\itemize{
\item \verb{[group_cols...]} — group variable columns (when active), first.
\item \code{total} — the weighted sum estimate.
\item Variance columns — only those requested via \code{variance}.
\item \code{n} — unweighted count (omitted in no-variable mode).
\item \code{n_weighted} — sum of weights (only when requested).
}
The variable name (or \code{NULL} for no-variable mode) is in
\code{meta(result)$variable}. Use \code{meta(result)} for additional metadata.
}
\description{
Compute the estimated population total of a numeric variable in a survey
design, or the estimated population size when no variable is supplied.
Supports optional grouping, uncertainty quantification, and metadata-driven
labelling.
}
\examples{
d <- as_survey_replicate(acs_pums_wy, weights = pwgtp,
                   repweights = pwgtp1:pwgtp80,
                   type = "successive-difference")

# Population size
get_totals(d)

# Total for a variable
get_totals(d, agep)

# Grouped
get_totals(d, agep, group = sex)

}
\seealso{
Other analysis: 
\code{\link{clean}()},
\code{\link{get_anova}()},
\code{\link{get_corr}()},
\code{\link{get_covariance}()},
\code{\link{get_diffs}()},
\code{\link{get_freqs}()},
\code{\link{get_means}()},
\code{\link{get_pairwise}()},
\code{\link{get_quantiles}()},
\code{\link{get_ratios}()},
\code{\link{get_t_test}()},
\code{\link{get_variance}()},
\code{\link{meta}()}
}
\concept{analysis}
