View source: R/add_inactive_replicates.R
add_inactive_replicates | R Documentation |
Adds inactive replicates to a survey design object. An inactive replicate is a replicate that does not contribute to variance estimates but adds to the matrix of replicate weights so that the matrix has the desired number of columns. The new replicates' values are simply equal to the full-sample weights.
add_inactive_replicates(design, n_total, n_to_add, location = "last")
design |
A survey design object, created with either the |
n_total |
The total number of replicates
that the result should contain. If the design already contains |
n_to_add |
The number of additional replicates to add.
Can only use the |
location |
Either |
An updated survey design object, where the number of columns
of replicate weights has potentially increased. The increase only happens
if the user specifies the n_to_add
argument instead of n_total
,
of if the user specifies n_total
and n_total
is less than the number
of columns of replicate weights that the design already had.
Inactive replicates are also sometimes referred to as "dead replicates", for example in Ash (2014). The purpose of adding inactive replicates is to increase the number of columns of replicate weights without impacting variance estimates. This can be useful, for example, when combining data from a survey across multiple years, where different years use different number of replicates, but a consistent number of replicates is desired in the combined data file.
Suppose the initial replicate design has L
replicates, with
respective constants c_k
for k=1,\dots,L
used to estimate variance
with the formula
v_{R} = \sum_{k=1}^L c_k\left(\hat{T}_y^{(k)}-\hat{T}_y\right)^2
where \hat{T}_y
is the estimate produced using the full-sample weights
and \hat{T}_y^{(k)}
is the estimate from replicate k
.
Inactive replicates are simply replicates that are exactly equal to the full sample:
that is, the replicate k
is called "inactive" if its vector of replicate
weights exactly equals the full-sample weights. In this case, when using the formula
above to estimate variances, these replicates contribute nothing to the variance estimate.
If the analyst uses the variant of the formula above where the full-sample estimate
\hat{T}_y
is replaced by the average replicate estimate (i.e., L^{-1}\sum_{k=1}^{L}\hat{T}_y^{(k)}
),
then variance estimates will differ before vs. after adding the inactive replicates.
For this reason, it is strongly recommend to explicitly specify mse=TRUE
when creating a replicate design object in R with functions such as svrepdesign()
,
as_bootstrap_design()
, etc. If working with an already existing replicate design,
you can update the mse
option to TRUE
simply by using code such as
my_design$mse <- TRUE
.
Ash, S. (2014). "Using successive difference replication for estimating variances." Survey Methodology, Statistics Canada, 40(1), 47–59.
library(survey)
set.seed(2023)
# Create an example survey design object
sample_data <- data.frame(
PSU = c(1,2,3)
)
survey_design <- svydesign(
data = sample_data,
ids = ~ PSU,
weights = ~ 1
)
rep_design <- survey_design |>
as.svrepdesign(type = "JK1", mse = TRUE)
# Inspect replicates before subsampling
rep_design |> weights(type = "analysis")
# Inspect replicates after adding inactive replicates
rep_design |>
add_inactive_replicates(n_total = 5, location = "first") |>
weights(type = "analysis")
rep_design |>
add_inactive_replicates(n_to_add = 2, location = "last") |>
weights(type = "analysis")
rep_design |>
add_inactive_replicates(n_to_add = 5, location = "random") |>
weights(type = "analysis")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.