Learn R Programming

srvyr (version 0.1.1)

as_survey_rep: Create a tbl_svy survey object using replicate weights

Description

Create a survey object with replicate weights.

Usage

as_survey_rep(.data, ...)

## S3 method for class 'data.frame': as_survey_rep(.data, variables = NULL, repweights = NULL, weights = NULL, type = c("BRR", "Fay", "JK1", "JKn", "bootstrap", "other"), combined_weights = TRUE, rho = NULL, bootstrap_average = NULL, scale = NULL, rscales = NULL, fpc = NULL, fpctype = c("fraction", "correction"), mse = getOption("survey.replicates.mse"), ...)

## S3 method for class 'svyrep.design': as_survey_rep(.data, ...)

## S3 method for class 'survey.design2': as_survey_rep(.data, type = c("auto", "JK1", "JKn", "BRR", "bootstrap", "subbootstrap", "mrbbootstrap", "Fay"), rho = 0, fpc = NULL, fpctype = NULL, ..., compress = TRUE, mse = getOption("survey.replicates.mse"))

## S3 method for class 'tbl_svy': as_survey_rep(.data, type = c("auto", "JK1", "JKn", "BRR", "bootstrap", "subbootstrap", "mrbbootstrap", "Fay"), rho = 0, fpc = NULL, fpctype = NULL, ..., compress = TRUE, mse = getOption("survey.replicates.mse"))

as_survey_rep_(.data, variables = NULL, repweights = NULL, weights = NULL, type = c("BRR", "Fay", "JK1", "JKn", "bootstrap", "other"), combined_weights = TRUE, rho = NULL, bootstrap_average = NULL, scale = NULL, rscales = NULL, fpc = NULL, fpctype = c("fraction", "correction"), mse = getOption("survey.replicates.mse"))

Arguments

.data
A data frame (which contains the variables specified below)
...
ignored
variables
Variables to include in the design (default is all)
repweights
Variables specifying the replication weight varibles
weights
Variables specifying sampling weights
type
Type of replication weights
combined_weights
TRUE if the repweights already include the sampling weights. This is usually the case.
rho
Shrinkage factor fo rweights in Fay's method
bootstrap_average
For type = "bootstrap", if the bootstrap weights have been averaged, gives the number of iterations averaged over.
scale, rscales
Scaling constant for variance, see svrepdesign for more information.
fpc, fpctype
Finite population correction information
mse
if TRUE, compute varainces based on sum of squares around the point estimate, rather than the mean of the replicates
compress
if TRUE, store replicate weights in compressed form (if converting from design)

Value

  • An object of class tbl_svy

Details

If provided a data.frame, it is a wrapper around svrepdesign. All survey variables must be included in the data.frame itself. Variables are selected by using bare column names, or convenience functions described in select. as_survey_rep_ is the standard evaluation counterpart to as_survey_rep.

If provided a svyrep.design object from the survey package, it will turn it into a srvyr object, so that srvyr functions will work with it

If provided a survey design (survey.design2 or tbl_svy), it is a wrapper around as.svrepdesign, and will convert from a survey design to replicate weights.

Examples

Run this code
# Examples from ?survey::svrepdesign()
library(survey)
library(dplyr)
data(scd)
# use BRR replicate weights from Levy and Lemeshow
scd <- scd %>%
  mutate(rep1 = 2 * c(1, 0, 1, 0, 1, 0),
         rep2 = 2 * c(1, 0, 0, 1, 0, 1),
         rep3 = 2 * c(0, 1, 1, 0, 0, 1),
         rep4 = 2 * c(0, 1, 0, 1, 1, 0))

scdrep <- scd %>%
  as_survey_rep(type = "BRR", repweights = starts_with("rep"),
                combined_weights = FALSE)

# as_survey_rep_ uses standard evaluation
repwts <- names(scd)[grep("^rep", names(scd))]
scdrep <- scd %>%
  as_survey_rep_(type = "BRR", repweights = repwts,
                combined_weights = FALSE)

Run the code above in your browser using DataLab