as_survey_rep: Create a tbl_svy survey object using replicate weights

View source: R/as_survey_rep.r

as_survey_repR Documentation

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", "successive-difference", "ACS",
    "other"),
  combined_weights = TRUE,
  rho = NULL,
  bootstrap_average = NULL,
  scale = NULL,
  rscales = NULL,
  fpc = NULL,
  fpctype = c("fraction", "correction"),
  mse = getOption("survey.replicates.mse"),
  degf = NULL,
  ...
)

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

## 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")
)

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 variables

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 for weights 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

Variables specifying a finite population correction, see svrepdesign for more details.

fpctype

Finite population correction information

mse

if TRUE, compute variances based on sum of squares around the point estimate, rather than the mean of the replicates

degf

Design degrees of freedom: a single number, or NULL, in which case a value will be computed automatically, which can be slow for very large data sets. See svrepdesign for more details.

compress

if TRUE, store replicate weights in compressed form (if converting from design)

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.

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.

Value

An object of class tbl_svy

Examples

# 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)

# dplyr 0.7 introduced new style of NSE called quosures
# See `vignette("programming", package = "dplyr")` for details
repwts <- quo(starts_with("rep"))
scdrep <- scd %>%
  as_survey_rep(type = "BRR", repweights = !!repwts,
                combined_weights = FALSE)


srvyr documentation built on Sept. 11, 2024, 8:43 p.m.