Description Usage Arguments Details Value Examples
View source: R/as_survey_design.r
Create a survey object with a survey design.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16  as_survey_design(.data, ...)
## S3 method for class 'data.frame'
as_survey_design(.data, ids = NULL, probs = NULL,
strata = NULL, variables = NULL, fpc = NULL, nest = FALSE,
check_strata = !nest, weights = NULL, pps = FALSE, variance = c("HT",
"YG"), ...)
## S3 method for class 'survey.design2'
as_survey_design(.data, ...)
## S3 method for class 'tbl_lazy'
as_survey_design(.data, ids = NULL, probs = NULL,
strata = NULL, variables = NULL, fpc = NULL, nest = FALSE,
check_strata = !nest, weights = NULL, pps = FALSE, variance = c("HT",
"YG"), ...)

.data 
A data frame (which contains the variables specified below) 
... 
ignored 
ids 
Variables specifying cluster ids from largest level to smallest level (leaving the argument empty, NULL, 1, or 0 indicate no clusters). 
probs 
Variables specifying cluster sampling probabilities. 
strata 
Variables specifying strata. 
variables 
Variables specifying variables to be included in survey. Defaults to all variables in .data 
fpc 
Variables specifying a finite population correct, see

nest 
If 
check_strata 
If 
weights 
Variables specifying weights (inverse of probability). 
pps 
"brewer" to use Brewer's approximation for PPS sampling without replacement. "overton" to use Overton's approximation. An object of class HR to use the HartleyRao approximation. An object of class ppsmat to use the HorvitzThompson estimator. 
variance 
For pps without replacement, use variance="YG" for the YatesGrundy estimator instead of the HorvitzThompson estimator 
If provided a data.frame, it is a wrapper
around svydesign
. 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 survey.design2
object from the survey package,
it will turn it into a srvyr object, so that srvyr functions will work with it
An object of class tbl_svy
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42  # Examples from ?survey::svydesign
library(survey)
data(api)
# stratified sample
dstrata < apistrat %>%
as_survey_design(strata = stype, weights = pw)
# onestage cluster sample
dclus1 < apiclus1 %>%
as_survey_design(dnum, weights = pw, fpc = fpc)
# twostage cluster sample: weights computed from population sizes.
dclus2 < apiclus2 %>%
as_survey_design(c(dnum, snum), fpc = c(fpc1, fpc2))
## multistage sampling has no effect when fpc is not given, so
## these are equivalent.
dclus2wr < apiclus2 %>%
dplyr::mutate(weights = weights(dclus2)) %>%
as_survey_design(c(dnum, snum), weights = weights)
dclus2wr2 < apiclus2 %>%
dplyr::mutate(weights = weights(dclus2)) %>%
as_survey_design(c(dnum), weights = weights)
## syntax for stratified cluster sample
## (though the data weren't really sampled this way)
apistrat %>% as_survey_design(dnum, strata = stype, weights = pw,
nest = TRUE)
## PPS sampling without replacement
data(election)
dpps < election_pps %>%
as_survey_design(fpc = p, pps = "brewer")
# dplyr 0.7 introduced new style of NSE called quosures
# See `vignette("programming", package = "dplyr")` for details
st < quo(stype)
wt < quo(pw)
dstrata < apistrat %>%
as_survey_design(strata = !!st, weights = !!wt)

Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.