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    55.1      11.3 
#>  2 Cascades             37         9.75
#>  3 Centre              121.        6.77
#>  4 Centre-Est           74.2      11.5 
#>  5 Centre-Nord          79.5       9.93
#>  6 Centre-Ouest         71.4      13.2 
#>  7 Centre-Sud           88.6      16.7 
#>  8 Est                  46         9.94
#>  9 Hauts-Bassins       100.       18.2 
#> 10 Nord                 58.7       9.92
#> 11 Plateau-Central      93.5      14.2 
#> 12 Sahel                58.6      14.8 
#> 13 Sud-Ouest            67.3      13.6