-
Notifications
You must be signed in to change notification settings - Fork 9
/
README.Rmd
103 lines (73 loc) · 4.2 KB
/
README.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
95
96
97
98
99
100
101
102
103
---
output: github_document
---
```{r, echo = FALSE}
set.seed(17760701)
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "README-"
)
options(digits = 2)
```
# randomizr: Easy to use tools for common forms of random assignment and sampling
[![CRAN Status](http://www.r-pkg.org/badges/version/randomizr)](https://cran.r-project.org/package=randomizr)
[![Travis-CI Build Status](https://travis-ci.org/DeclareDesign/randomizr.svg?branch=master)](https://travis-ci.org/DeclareDesign/randomizr)
[![AppVeyor Build Status](https://ci.appveyor.com/api/projects/status/github/DeclareDesign/randomizr?branch=master&svg=true)](https://ci.appveyor.com/project/DeclareDesign/randomizr)
[![Coverage Status](https://coveralls.io/repos/github/DeclareDesign/randomizr/badge.svg?branch=master)](https://coveralls.io/github/DeclareDesign/randomizr?branch=master)
![CRAN downloads](http://cranlogs.r-pkg.org/badges/grand-total/randomizr)
**randomizr** is designed to make conducting field, lab, survey, or online experiments easier by automating the random assignment process. Social and lab scientists conducting experiments need a process to assign individuals or units of observation to treatment or control wings. Common designs include simple random assignment, complete randomization, block randomization, cluster randomization, and blocked cluster randomization. **randomizr** automates all of these processes and assists scientists in doing transparent, replicable science. We offer **randomizr** for both `R` and `Stata`.
## randomizr for R
### Installing randomizr for R
Installing the latest stable version of **randomizr** in `R`:.
```{r,eval=FALSE}
install.packages("randomizr")
```
If you would like to use the current development release of **randomizr** (please be aware that development releases may include bugs or syntax changes), run the following:
```{r,eval=FALSE}
install.packages("randomizr", repos="http://r.declaredesign.org")
```
### Getting started with randomizr for R
**randomizr** has five main random assignment functions, corresponding to the common experimental designs listed above. You can read more about using each of these functions in our [reference library](https://declaredesign.org/R/randomizr/reference/) or by clicking on the function names: `simple_ra()`, `complete_ra()`, `block_ra()`, `cluster_ra()`, and `block_and_cluster_ra()`.
`complete_ra()` (Complete randomization) is the function that will be most appropriate for a large number of experimental situations: when you want to assign a fixed `m` units out of a population of `N` units to treatment:
```{r echo=TRUE, results="hide"}
library(randomizr)
Z <- complete_ra(N = 100, m = 50)
table(Z)
```
```{r echo=FALSE}
knitr::kable(t(as.matrix(table(Z))))
```
A more complicated design that, for example, assigns different numbers of clusters to three different treatments, makes use of `cluster_ra()` (Cluster randomization):
```{r echo=TRUE, results="hide"}
# This makes a cluster variable: one unit in cluster "a", two in "b"...
clust_var <- rep(letters[1:15], times = 1:15)
Z <- cluster_ra(
clusters = clust_var,
m_each = c(4, 4, 7),
conditions = c("control", "placebo", "treatment")
)
table(Z, clust_var)
```
```{r echo=FALSE}
knitr::kable(table(Z, clust_var))
```
For more information about all of **randomizr**'s functionality, please see our [online tutorial](https://declaredesign.org/R/randomizr/articles/randomizr_vignette.html)
## randomizr for Stata
Installing the latest stable version of **randomizr** from ssc is easy:
```{r eval=FALSE}
ssc install randomizr
```
If you would like to install the latest development release directly from GitHub, run the following code:
```{r eval=FALSE}
net install randomizr, from(https://raw.githubusercontent.com/DeclareDesign/strandomizr/master/) replace
```
## Getting started with randomizr for Stata
`complete_ra` (complete randomization) is the workhorse function that will be most appropriate for a large number of experimental situations: it assigns m of N units to treatment:
```{r eval=FALSE}
ssc install randomizr
set obs 100
complete_ra, m(50)
```
A Stata version of our [online tutorial](https://declaredesign.org/R/randomizr/articles/srandomizr_vignette.html) is also available.
Happy randomizing!