% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/analysis-t-test.R
\name{get_t_test}
\alias{get_t_test}
\title{Design-Based Two-Sample T-Test for Survey Designs}
\usage{
get_t_test(
  design,
  x,
  by,
  group = NULL,
  conf_level = 0.95,
  variance = "ci",
  na.rm = TRUE,
  min_cell_n = 30L,
  decimals = NULL,
  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}}> A single unquoted
numeric variable name for the outcome variable. Must resolve to exactly
one numeric column.}

\item{by}{<\code{\link[tidyselect:language]{tidy-select}}> A single unquoted
variable name for the grouping variable. Must produce a model matrix
with exactly 2 columns after fitting (intercept + one binary indicator).
Character, integer, and logical columns are coerced to factor with a
warning. Ordered factors are accepted as-is.}

\item{group}{<\code{\link[tidyselect:language]{tidy-select}}> Optional subgroup
variable(s). When supplied, the t-test is run separately within each
unique combination of group values. Combined with any grouping set by
\code{group_by()}. Default \code{NULL}.}

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

\item{variance}{Character. Which uncertainty columns to include.
Valid values: \code{"se"}, \code{"ci"}. Default \code{"ci"}. Both may be requested:
\code{c("se", "ci")}.}

\item{na.rm}{Logical(1). Accepted for API uniformity with other
\verb{get_*()} functions. NA rows in \code{x} or \code{by} are always excluded
(the GLM requires complete cases). Default \code{TRUE}.}

\item{min_cell_n}{Integer(1). Warn when either group has fewer than
this many unweighted observations. Default \code{30L}. Use \code{0L} to
suppress.}

\item{decimals}{Integer(1) or \code{NULL}. Round all double output columns
to this many decimal places. \code{NULL} = no rounding. Default \code{NULL}.}

\item{label_values}{Logical(1). When \code{TRUE} (default), convert \code{by}
and \code{group} factor codes to their value labels in the output.}

\item{label_vars}{Logical(1). Accepted for API uniformity; has no
visible effect because column names are fixed. Default \code{TRUE}.}

\item{name_style}{Character(1). Output column naming style.
\code{"surveycore"} (default) or \code{"broom"} (renames \code{se} to \code{std.error},
\code{ci_low} to \code{conf.low}, \code{ci_high} to \code{conf.high}, \code{p_value} to
\code{p.value}, \code{df} to \code{parameter}). \code{t_stat} is not renamed.}

\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_t_test} tibble (also inheriting \code{survey_result}).
Columns: group columns (when active), \code{level_a}, \code{level_b},
\code{estimate}, \code{mean_a}, \code{mean_b}, \code{n_a}, \code{n_b}, \code{se} (optional),
\code{ci_low} (optional), \code{ci_high} (optional), \code{t_stat}, \code{df},
\code{p_value}, \code{stars}. Use \code{\link[=meta]{meta()}} to access design type, conf_level,
and variable metadata.
}
\description{
Compares the weighted means of two groups using a design-based t-test.
Follows the mathematical model of \code{survey::svyttest()} but uses
surveycore's own variance machinery (\code{survey_glm()}). Supports all four
survey design classes and optional subgroup analysis via \code{group}.
}
\examples{
gss_sub <- gss_2024[gss_2024$sex \%in\% c(1L, 2L) & !is.na(gss_2024$age), ]
gss_sub$sex <- factor(gss_sub$sex, levels = c(1, 2), labels = c("Male", "Female"))
gss_design <- as_survey(gss_sub,
  ids = vpsu, weights = wtssps, strata = vstrat, nest = TRUE)
get_t_test(gss_design, age, by = 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_totals}()},
\code{\link{get_variance}()},
\code{\link{meta}()}
}
\concept{analysis}
