% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/core-constructors.R
\name{as_survey_replicate}
\alias{as_survey_replicate}
\title{Create a Replicate Weights Survey Design}
\usage{
as_survey_replicate(
  data,
  weights,
  repweights,
  type = c("JK1", "JK2", "JKn", "BRR", "Fay", "bootstrap", "ACS",
    "successive-difference", "other"),
  scale = NULL,
  rscales = NULL,
  fpc = NULL,
  fpctype = c("fraction", "correction"),
  mse = TRUE
)
}
\arguments{
\item{data}{A \code{data.frame} containing the survey responses. Must have at
least one row and unique column names.}

\item{weights}{<\code{\link[tidyselect:language]{tidy-select}}> Sampling weight
column (a single column, values strictly > 0). Required.}

\item{repweights}{<\code{\link[tidyselect:language]{tidy-select}}> Replicate weight
columns. Must select at least one column. Supports tidy-select helpers
(e.g., \code{starts_with("repwt")}). Required.}

\item{type}{Character. Replicate weight method. One of \code{"JK1"} (delete-1
jackknife), \code{"JK2"} (delete-1 jackknife, stratified), \code{"JKn"} (delete-1
jackknife with varying replication counts), \code{"BRR"} (balanced repeated
replication), \code{"Fay"} (Fay's method, a modified BRR), \code{"bootstrap"},
\code{"ACS"} (used in American Community Survey), \code{"successive-difference"},
or \code{"other"} (user-specified scale). Case-sensitive.}

\item{scale}{Numeric. Scaling factor applied to the replicate variance
formula. If \code{NULL} (default), computed automatically from \code{type} and
the number of replicates: \code{(R-1)/R} for jackknife methods, \code{1/4} for
BRR/Fay, \code{1/R} for bootstrap/ACS, \code{2/R} for successive-difference,
\code{1} for other.}

\item{rscales}{Numeric vector of replicate-specific scaling factors, or
\code{NULL}. If provided, must have the same length as the number of
replicate weight columns selected by \code{repweights}.}

\item{fpc}{<\code{\link[tidyselect:language]{tidy-select}}> Finite population
correction column (a single column). Used by some replicate methods to
adjust the variance estimator. \code{NULL} means no FPC correction.}

\item{fpctype}{Character. How \code{fpc} is interpreted: \code{"fraction"} (sampling
fraction, 0–1) or \code{"correction"} (multiplier for the replicate variance).
Default \code{"fraction"}. Case-sensitive.}

\item{mse}{Logical. If \code{TRUE} (default), use mean-squared-error estimates
(subtract the full-sample estimate rather than the mean replicate estimate
when computing variance). Recommended for most designs.}
}
\value{
A \code{survey_replicate} object.
}
\description{
Creates a survey design object using replicate weights for variance
estimation. Supports all common replicate methods: jackknife (JK1, JK2,
JKn), balanced repeated replication (BRR, Fay), bootstrap, ACS,
successive-difference, and user-defined types. Uses a tidy-select
interface for weight and replicate-weight columns.
}
\section{Tidy-select}{

Both \code{weights} and \code{repweights} support tidy-select syntax:

\if{html}{\out{<div class="sourceCode r">}}\preformatted{# Bare name for weights
as_survey_replicate(
  df, weights = wt, repweights = starts_with("repwt"), type = "BRR"
)
# c() for explicit replicate columns
as_survey_replicate(
  df, weights = wt, repweights = c(rep1, rep2, rep3), type = "JK1"
)
}\if{html}{\out{</div>}}
}

\section{Replicate weight matrix}{

The replicate weight matrix is \strong{not stored} in the object. Only the
column names are stored in \verb{@variables$repweights}. Variance estimation
computes the matrix on demand:
\code{as.matrix(design@data[, design@variables$repweights])}.
}

\section{Memory usage}{

Each call to an estimation function (e.g., \code{\link[=get_means]{get_means()}}, \code{\link[=get_totals]{get_totals()}})
materialises the full replicate weight matrix from the data frame. For large
designs (e.g., ACS PUMS with 500k+ rows × 80 replicates), this is roughly
\code{nrow * n_replicates * 8} bytes per call (~363 MB for ACS Wyoming × 80).
If you are estimating many variables, this is repeated for each call.
This behaviour matches the \code{survey} package reference implementation.
}

\examples{
# ACS PUMS Wyoming: 80 successive-difference replicate weights
d_acs <- as_survey_replicate(
  acs_pums_wy,
  weights    = pwgtp,
  repweights = pwgtp1:pwgtp80,
  type       = "successive-difference"
)

# Explicit replicate columns using c()
d_sub <- as_survey_replicate(
  acs_pums_wy,
  weights    = pwgtp,
  repweights = c(pwgtp1, pwgtp2, pwgtp3, pwgtp4),
  type       = "JK1"
)

}
\references{
Judkins, D.R. (1990) Fay's method for variance estimation.
\emph{Journal of the American Statistical Association}
\bold{85}(410), 895--904.

Canty, A.J. and Davison, A.C. (1999) Resampling-based variance estimation
for labour force surveys. \emph{The Statistician} \bold{48}(3), 379--391.

Shao, J. and Tu, D. (1995) \emph{The Jackknife and Bootstrap}. Springer.
}
\seealso{
\code{\link[=as_survey]{as_survey()}} for Taylor series designs,
\code{\link[=as_survey_twophase]{as_survey_twophase()}} for two-phase designs,
\code{\link[=set_var_label]{set_var_label()}} to add variable labels

Other constructors: 
\code{\link{as_survey}()},
\code{\link{as_survey_nonprob}()},
\code{\link{as_survey_twophase}()},
\code{\link{survey_data}()},
\code{\link{survey_glm}()},
\code{\link{survey_glm_fit}()},
\code{\link{survey_nonprob}()},
\code{\link{survey_replicate}()},
\code{\link{survey_taylor}()},
\code{\link{survey_twophase}()}
}
\concept{constructors}
