declare_sampling: Declare sampling procedure

Description Usage Arguments Value Examples

Description

Declare sampling procedure

Usage

1
2
3

Arguments

...

arguments to be captured, and later passed to the handler

handler

a tidy-in, tidy-out function

label

a string describing the step

data

A data.frame.

legacy

Use the legacy randomizr functionality. This will be disabled in future; please use legacy = FALSE.

Value

A sampling declaration, which is a function that takes a data.frame as an argument and returns a data.frame subsetted to sampled observations and (optionally) augmented with inclusion probabilities and other quantities.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
design <- declare_model(

  classrooms = add_level(10),
  individuals = add_level(20, female = rbinom(N, 1, 0.5))

) + NULL

# Complete random sampling

design + declare_sampling(
  S = complete_rs(N = N, n = 50), 
  filter = S == 1, legacy = FALSE)

# equivalently, by default filter is set to S == 1
design + declare_sampling(S = complete_rs(N = N, n = 50), 
                          legacy = FALSE)

# Stratified random sampling

design + declare_sampling(S = strata_rs(strata = female), 
                          legacy = FALSE)

DeclareDesign documentation built on Feb. 15, 2021, 1:07 a.m.