Skip to contents

Creates a srvyr::tbl_svy object from a tbl_sample by first converting to a survey::svydesign() object via as_svydesign(), then wrapping with srvyr::as_survey_design().

Usage

# S3 method for class 'tbl_sample'
as_survey_design(.data, ...)

Arguments

.data

A tbl_sample object produced by execute().

...

Additional arguments passed to as_svydesign().

Value

A tbl_svy object from the srvyr package.

Details

This method is registered on the srvyr::as_survey_design() generic, so it is available when srvyr is loaded.

See also

as_svydesign() for converting to a survey.design2 object

Examples

library(srvyr)
#> 
#> Attaching package: ‘srvyr’
#> The following object is masked from ‘package:stats’:
#> 
#>     filter

sample <- sampling_design() |>
  stratify_by(region, alloc = "proportional") |>
  draw(n = 300) |>
  execute(bfa_eas, seed = 42)

# Returns a tbl_svy for use with srvyr verbs
svy <- as_survey_design(sample)
svy |>
  group_by(region) |>
  summarise(mean_hh = survey_mean(households))
#> # A tibble: 13 × 3
#>    region            mean_hh mean_hh_se
#>    <fct>               <dbl>      <dbl>
#>  1 Boucle du Mouhoun    169.      16.8 
#>  2 Cascades             163.      11.3 
#>  3 Centre               305.      13.5 
#>  4 Centre-Est           210.      13.0 
#>  5 Centre-Nord          189.      17.0 
#>  6 Centre-Ouest         221.      17.7 
#>  7 Centre-Sud           198.      17.5 
#>  8 Est                  150.       8.17
#>  9 Hauts-Bassins        218.      19.3 
#> 10 Nord                 168.      17.3 
#> 11 Plateau-Central      194.      13.4 
#> 12 Sahel                193.      14.0 
#> 13 Sud-Ouest            181.      13.3