View source: R/as_survey_rep.r
as_survey_rep | R Documentation |
Create a survey object with replicate weights.
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"), ... ) ## 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"), ... ) ## 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") )
.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 |
|
rho |
Shrinkage factor for weights in Fay's method |
bootstrap_average |
For |
scale, rscales |
Scaling constant for variance, see
|
fpc |
Variables specifying a finite population correction, see
|
fpctype |
Finite population correction information |
mse |
if |
compress |
if |
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.
An object of class tbl_svy
# 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.