You can either give obtain_condition_probabilities() an declaration, as created by `declare_ra`

or you can specify the other arguments to describe a random assignment procedure.
This function is especially useful when units have different probabilties of assignment and the analyst plans to use inverse-probability weights.

obtain_condition_probabilities(declaration = NULL, assignment, N = NULL, block_var = NULL, clust_var = NULL, m = NULL, m_each = NULL, prob = NULL, prob_each = NULL, block_m = NULL, block_m_each = NULL, block_prob = NULL, block_prob_each = NULL, num_arms = NULL, condition_names = NULL, simple = FALSE)

declaration | A random assignment declaration, created by |
---|---|

assignment | A vector of random assignments, often created by |

N | The number of units. N must be a positive integer. (required) |

block_var | A vector of length N that indicates which block each unit belongs to. |

clust_var | A vector of length N that indicates which cluster each unit belongs to. |

m | Use for a two-arm design in which m units (or clusters) are assigned to treatment and N-m units (or clusters) are assigned to control. In a blocked design, exactly m units in each block will be treated. (optional) |

m_each | Use for a multi-arm design in which the values of m_each determine the number of units (or clusters) assigned to each condition. m_each must be a numeric vector in which each entry is a nonnegative integer that describes how many units (or clusters) should be assigned to the 1st, 2nd, 3rd... treatment condition. m_each must sum to N. (optional) |

prob | Use for a two-arm design in which either floor(N*prob) or ceiling(N*prob) units (or clusters) are assigned to treatment. The probability of assignment to treatment is exactly prob because with probability 1-prob, floor(N*prob) units (or clusters) will be assigned to treatment and with probability prob, ceiling(N*prob) units (or clusters) will be assigned to treatment. prob must be a real number between 0 and 1 inclusive. (optional) |

prob_each | Use for a multi-arm design in which the values of prob_each determine the probabilties of assignment to each treatment condition. prob_each must be a numeric vector giving the probability of assignment to each condition. All entries must be nonnegative real numbers between 0 and 1 inclusive and the total must sum to 1. Because of integer issues, the exact number of units assigned to each condition may differ (slightly) from assignment to assignment, but the overall probability of assignment is exactly prob_each. (optional) |

block_m | Use for a two-arm design in which block_m describes the number of units to assign to treatment within each block. Note that in previous versions of randomizr, block_m behaved like block_m_each. |

block_m_each | Use for a multi-arm design in which the values of block_m_each determine the number of units (or clusters) assigned to each condition. block_m_each must be a matrix with the same number of rows as blocks and the same number of columns as treatment arms. Cell entries are the number of units (or clusters) to be assigned to each treatment arm within each block. The rows should respect the ordering of the blocks as determined by sort(unique(block_var)). The columns should be in the order of condition_names, if specified. |

block_prob | Use for a two-arm design in which block_prob describes the probability of assignment to treatment within each block. Differs from prob in that the probability of assignment can vary across blocks. |

block_prob_each | Use for a multi-arm design in which the values of block_prob_each determine the probabilties of assignment to each treatment condition. block_prob_each must be a matrix with the same number of rows as blocks and the same number of columns as treatment arms. Cell entries are the probabilites of assignment to treatment within each block. The rows should respect the ordering of the blocks as determined by sort(unique(block_var)). Use only if the probabilities of assignment should vary by block, otherwise use prob_each. Each row of block_prob_each must sum to 1. |

num_arms | The number of treatment arms. If unspecified, num_arms will be determined from the other arguments. (optional) |

condition_names | A character vector giving the names of the treatment groups. If unspecified, the treatment groups will be named 0 (for control) and 1 (for treatment) in a two-arm trial and T1, T2, T3, in a multi-arm trial. An execption is a two-group design in which num_arms is set to 2, in which case the condition names are T1 and T2, as in a multi-arm trial with two arms. (optional) |

simple | logical, defaults to FALSE. If TRUE, simple random assignment is used. When simple = TRUE, please do not specify m, m_each, block_m, or block_m_each. |

# Conduct a block random assignment block_var <- rep(c("A", "B","C"), times=c(50, 100, 200)) block_m_each <- rbind(c(10, 40), c(30, 70), c(50, 150)) declaration <- declare_ra(block_var = block_var, block_m_each = block_m_each) Z <- conduct_ra(declaration = declaration) table(Z, block_var)#> block_var #> Z A B C #> 0 10 30 50 #> 1 40 70 150observed_probabilities <- obtain_condition_probabilities(declaration = declaration, assignment = Z) # Probabilities in the control group: table(observed_probabilities[Z == 0], block_var[Z == 0])#> #> A B C #> 0.2 10 0 0 #> 0.25 0 0 50 #> 0.3 0 30 0# Probabilities in the treatment group: table(observed_probabilities[Z == 1], block_var[Z == 1])#> #> A B C #> 0.7 0 70 0 #> 0.75 0 0 150 #> 0.8 40 0 0# Sometimes it is convenient to skip the declaration step Z <- conduct_ra(block_var = block_var, block_m_each = block_m_each) observed_probabilities <- obtain_condition_probabilities(assignment = Z, block_var = block_var, block_m_each = block_m_each) table(observed_probabilities[Z == 0], block_var[Z == 0])#> #> A B C #> 0.2 10 0 0 #> 0.25 0 0 50 #> 0.3 0 30 0table(observed_probabilities[Z == 1], block_var[Z == 1])#> #> A B C #> 0.7 0 70 0 #> 0.75 0 0 150 #> 0.8 40 0 0