forked from higgi13425/rmrwr-book
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathio42a-blockrand_CAPTURE.Rmd
executable file
·97 lines (77 loc) · 2.38 KB
/
io42a-blockrand_CAPTURE.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
---
title: "R Notebook"
output: html_notebook
---
This is an example of use of the blockrand package to create a randomization of two assignments with 5 strata in a randomized permuted block design.
```{r setup}
library(blockrand)
library(knitr)
library(kableExtra)
library(tidyverse, quietly = T)
```
Our goal is to have 500 assignments available across 5 strata of risk.
To make this reproducible, I will set a distinct seed for each stratum.
```{r}
set.seed(1234)
stratum1 <- blockrand(n = 100,
block.prefix = "B_", # this is for block.id
stratum = "Stratum_1",
num.levels = 2, # 2 distinct treatments
levels = c("Patient Navigator", "Control")
) %>% filter(id <101) # often will come out uneven
# based on block size, so will trim to 100
stratum1
```
Now stratum 2
```{r}
set.seed(0714)
stratum2 <- blockrand(n = 100,
block.prefix = "B_",
stratum = "Stratum_2",
num.levels = 2,
levels = c("Patient Navigator", "Control")
) %>% filter(id <101)
stratum2
```
Now stratum 3
```{r}
set.seed(1965)
stratum3 <- blockrand(n = 100,
block.prefix = "B_",
stratum = "Stratum_3",
num.levels = 2,
levels = c("Patient Navigator", "Control")
) %>% filter(id <101)
stratum3
```
Now stratum 4
```{r}
set.seed(314159)
stratum4 <- blockrand(n = 100,
block.prefix = "B_",
stratum = "Stratum_4",
num.levels = 2,
levels = c("Patient Navigator", "Control")
) %>% filter(id <101)
stratum4
```
Now Stratum 5
```{r}
set.seed(2718)
stratum5 <- blockrand(n = 100,
block.prefix = "B_",
stratum = "Stratum_5",
num.levels = 2,
levels = c("Patient Navigator", "Control")
) %>% filter(id <101)
stratum5
```
now bind these together in one assignment sheet
```{r}
assign500 <- rbind(stratum1, stratum2, stratum3, stratum4, stratum5)
assign500 %>%
rename(num = id) %>%
select(stratum, num, treatment, block.id, block.size) %>%
knitr::kable() %>%
kable_styling()
```