Generate permuted block treatment assignments

car_pb(z, trt_label, trt_alc, blocksize = 4L)

Arguments

z

The car_strata design matrix, as a data frame with factor variables

trt_label

Treatment label

trt_alc

Treatment allocation vector

blocksize

Permuted block blocksize

Value

A vector of treatment assignments with labels from the `trt_label` argument, based on stratified permuted block randomization.

Examples

# Create car_strata variables
library(fastDummies)
#> Thank you for using fastDummies!
#> To acknowledge our work, please cite the package:
#> Kaplan, J. & Schlegel, B. (2023). fastDummies: Fast Creation of Dummy (Binary) Columns and Rows from Categorical Variables. Version 1.7.1. URL: https://github.com/jacobkap/fastDummies, https://jacobkap.github.io/fastDummies/.
library(dplyr)
#> 
#> Attaching package: ‘dplyr’
#> The following objects are masked from ‘package:stats’:
#> 
#>     filter, lag
#> The following objects are masked from ‘package:base’:
#> 
#>     intersect, setdiff, setequal, union

x <- runif(100)
z <- cut(x, breaks=c(0, 0.25, 0.5, 0.75, 1.0))
z <- dummy_cols(z) %>%
     mutate(across(where(is.numeric), as.factor))

car_pb(z[, 2:5], c(0, 1, 2), trt_alc=c(1/4, 1/2, 1/4), blocksize=4L)
#>   [1] 1 1 2 1 2 1 1 2 0 2 0 0 1 0 2 2 0 1 1 1 1 1 1 0 1 0 0 1 2 1 1 1 0 1 1 2 0
#>  [38] 2 2 1 1 1 2 1 1 1 0 1 2 0 1 2 2 0 1 1 0 1 0 1 0 1 2 2 0 2 0 2 1 0 1 1 1 2
#>  [75] 0 1 0 1 2 1 0 1 1 2 1 1 0 0 2 1 1 1 1 0 1 2 1 2 0 2