https://github.com/DeclareDesign/randomizr
randomizr: Easy-to-Use Tools for Common Forms of Random Assignment and Sampling
https://github.com/DeclareDesign/randomizr
Last synced: over 1 year ago
JSON representation
randomizr: Easy-to-Use Tools for Common Forms of Random Assignment and Sampling
- Host: GitHub
- URL: https://github.com/DeclareDesign/randomizr
- Owner: DeclareDesign
- License: other
- Created: 2014-10-13T02:59:02.000Z (over 11 years ago)
- Default Branch: main
- Last Pushed: 2024-01-05T20:25:18.000Z (over 2 years ago)
- Last Synced: 2024-09-20T05:13:32.908Z (almost 2 years ago)
- Language: R
- Homepage: https://declaredesign.org/r/randomizr
- Size: 1.57 MB
- Stars: 36
- Watchers: 8
- Forks: 9
- Open Issues: 2
-
Metadata Files:
- Readme: README.Rmd
- License: LICENSE
Awesome Lists containing this project
README
---
output: github_document
title: "randomizr: Tools for random assignment and random sampling"
---
```{r, echo = FALSE}
set.seed(42)
knitr::opts_chunk$set(
collapse = TRUE,
message = FALSE,
comment = "#>",
fig.path = "README-"
)
options(digits = 2)
```
[](https://cran.r-project.org/package=randomizr)
[](https://r-pkg.org/pkg/randomizr)
[](https://github.com/DeclareDesign/randomizr/actions/workflows/R-CMD-check.yaml)
[](https://app.codecov.io/gh/DeclareDesign/randomizr)
[](https://softwarecite.com/package/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`](https://declaredesign.org/r/randomizr) and [`Stata`](https://declaredesign.org/stata/randomizr).
### Installing randomizr for R
Installing the latest stable version of **randomizr** in `R`:.
```{r,eval=FALSE}
install.packages("randomizr")
```
### 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
```
Happy randomizing!