-
Notifications
You must be signed in to change notification settings - Fork 3
/
randomization.Rmd
84 lines (62 loc) · 1.82 KB
/
randomization.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
---
title: How to block and randomize
author:
- name: Nathaniel Higgins
affiliation: SBST
- name: Jake Bowers
affiliation: SBST and University of Illinois
date: '`r format(Sys.Date(), "%B %d, %Y")`'
bibliography: references.bib
output:
html_document:
theme: cosmo
toc: yes
pdf_document:
keep_tex: true
number_sections: true
fig_width: 5
fig_height: 5
fig_caption: true
template: bowersarticletemplate.latex
...
```{r include=FALSE, cache=FALSE}
# Some customization. You can alter or delete as desired (if you know what you are doing).
# knitr settings to control how R chunks work.
## To make the html file do
## render("thefile.Rmd",output_format=html_document(fig_retina=FALSE))
## To make the pdf file do
## render("thefile.Rmd",output_format=pdf_document())
require(knitr)
opts_chunk$set(tidy=TRUE,echo=TRUE,results='markup',strip.white=TRUE,cache=FALSE,highlight=TRUE,width.cutoff=60,size='footnotesize',out.width='.5\\textwidth',message=FALSE,comment=NA,fig.env="figure", fig.align="center",fig.lp="fig:",fig.pos="H")
```
Before you randomize, you need to know how you want to organize the randomization, and how you plan to evaluate a better or worse randomization.
# Blocking
```{r}
library(blockTools)
```
Evaluating blockings
```{r}
library(RItools)
```
# Randomizing
First, we show how to do this by hand.
## Complete Randomization
This is the most common type of randomization because it guarantees the same numbers of observations in each treatment arm.
```{r}
N <- 20
numtrts <- 2
stopifnot( N %% numtrts == 0)
set.seed(180046)
Z1 <- sample(rep(seq(1,numtrts),N/numtrts))
Z1[1:10]
table(Z1)
```
Currently proposing to use the `randomizr` package
```{r}
library(randomizr)
set.seed(180046)
Z2 <- complete_ra(N=N,num_arms=numtrts)
Z2[1:10]
table(Z2)
```
# References