This function adds measured data columns that can be functions of unmeasured data columns.
declare_measurement(..., handler = measurement_handler, label = NULL)
measurement_handler(data, ...)
arguments to be captured, and later passed to the handler
a tidy-in, tidy-out function
a string describing the step
A data.frame.
A function that returns a data.frame.
It is also possible to include measured variables in your declare_model call or to add variables using declare_step. However, putting latent variables in declare_model and variables-as-measured in declare_measurement helps communicate which parts of your research design are in M and which parts are in D.
design <-
declare_model(N = 6,
U = rnorm(N),
potential_outcomes(Y ~ Z + U)) +
declare_assignment(Z = complete_ra(N)) +
declare_measurement(Y = reveal_outcomes(Y ~ Z))
draw_data(design)
#> ID U Y_Z_0 Y_Z_1 Z Y
#> 1 1 1.0070450 1.0070450 2.0070450 1 2.0070450
#> 2 2 -2.5196465 -2.5196465 -1.5196465 1 -1.5196465
#> 3 3 0.6660172 0.6660172 1.6660172 1 1.6660172
#> 4 4 0.3002052 0.3002052 1.3002052 0 0.3002052
#> 5 5 -0.5857465 -0.5857465 0.4142535 0 -0.5857465
#> 6 6 -0.1269108 -0.1269108 0.8730892 0 -0.1269108
design <-
declare_model(
N = 6,
U = rnorm(N),
potential_outcomes(Y ~ Z1 + Z2 + U,
conditions = list(Z1 = c(0, 1), Z2 = c(0, 1)))) +
declare_assignment(Z1 = complete_ra(N),
Z2 = block_ra(blocks = Z1),
legacy = FALSE) +
declare_measurement(Y = reveal_outcomes(Y ~ Z1 + Z2))
draw_data(design)
#> ID U Y_Z1_0_Z2_0 Y_Z1_1_Z2_0 Y_Z1_0_Z2_1 Y_Z1_1_Z2_1 Z1 Z2
#> 1 1 -0.4777625 -0.4777625 0.5222375 0.5222375 1.522237 0 0
#> 2 2 0.2357932 0.2357932 1.2357932 1.2357932 2.235793 1 1
#> 3 3 -0.6025449 -0.6025449 0.3974551 0.3974551 1.397455 1 1
#> 4 4 -0.4962203 -0.4962203 0.5037797 0.5037797 1.503780 0 0
#> 5 5 -0.3105494 -0.3105494 0.6894506 0.6894506 1.689451 1 0
#> 6 6 0.7060852 0.7060852 1.7060852 1.7060852 2.706085 0 1
#> Y
#> 1 -0.4777625
#> 2 2.2357932
#> 3 1.3974551
#> 4 -0.4962203
#> 5 0.6894506
#> 6 1.7060852