Giter Site home page Giter Site logo

randomizr's Introduction

Travis-CI Build Status

randomizr is designed to make conducting field, lab, survey, or online experiments easier by automating the random assignment process.

Installation from CRAN is easy:

install.packages("randomizr")

If you'd like to install the most current development release, use the following code:

install.packages("devtools")
devtools::install_github("DeclareDesign/randomizr")

There are five main random assignment functions in randomizr: simple_ra(), complete_ra(), block_ra(), cluster_ra(), and block_and_cluster_ra(), which correspond to common experimental designs.

complete_ra() is the workhorse function that will be most appropriate for a large number of experimental situations: it assigns m of N units to treatment:

library(randomizr)
Z <- complete_ra(N = 100, m = 50)
table(Z)
#> Z
#>  0  1 
#> 50 50

A more complicated design that, for example, assigns different numbers of clusters to three different treatments can be accomodated like this:

# This makes a cluster variable: one unit in cluster "a", two in "b"...
clust_var <- rep(letters, times = 1:26)

Z <- cluster_ra(clust_var=clust_var, m_each = c(7, 7, 12),
                condition_names=c("control", "placebo", "treatment"))
table(Z, clust_var)
#>            clust_var
#> Z            a  b  c  d  e  f  g  h  i  j  k  l  m  n  o  p  q  r  s  t  u
#>   control    1  2  0  0  0  0  0  0  0  0 11 12 13  0  0  0  0  0 19  0  0
#>   placebo    0  0  3  0  5  0  0  8  0  0  0  0  0 14  0  0  0 18  0 20  0
#>   treatment  0  0  0  4  0  6  7  0  9 10  0  0  0  0 15 16 17  0  0  0 21
#>            clust_var
#> Z            v  w  x  y  z
#>   control    0  0  0 25  0
#>   placebo    0  0 24  0  0
#>   treatment 22 23  0  0 26

Happy randomizing!

randomizr's People

Contributors

acoppock avatar graemeblair avatar ck37 avatar lukesonnet avatar

Watchers

James Cloos avatar  avatar

Forkers

guhjy

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.