# Constrained Optimal Sample Allocation in Multilevel Randomized Trials

#### February 5, 2017

Specify rhots = 0 for constrained optimal sample allocation in multilevel randomized trials. Of particular interest is the optimization of proportion of treatment allocation (p) under unequal marginal cost assumption. In the following examples p is optimized along with the sample size at the randomization level.

# Treatment at level 1

## Block/Multisite Two-level Random Assignment (BIRA2r1) Design

# cost constrained - optimize n1 and p
cosa.bird2r1(constrain = "cost", cost = 2000, rhots = 0,
cn1 = c(5, 2), cn2 = 10,
es = .20, rho2 = .20, omega2 = .20,
r21 = .20, r2t2 = .20, g2 = 1,
n2 = 150)
##  Results are equivalent to random assignment design
##  Solution converged with LBFGS
##
##  Rounded solution:
##  -----------------------------------------------
##     n1 [n2]     p [cost]    es 95%lcl 95%ucl power
##  1.053  150 0.386   1999 0.371  0.111  0.631 0.327
##  -----------------------------------------------
##  Per unit marginal costs:
##  Level 1 treatment: 5
##  Level 1 control: 2
##  Level 2: 10
##  -----------------------------------------------
##  MDES = 0.371 (with power = 80)
##  power = 0.327 (for ES = 0.2)
##  -----------------------------------------------
##  []: point constrained (fixed)
##  <<: bound constrained

## Block/Multisite Three-level Random Assignment (BIRA3r1) Design

# cost constrained - optimize n1 and p
cosa.bird3r1(constrain = "cost", cost = 10000, rhots = 0,
cn1 = c(5, 3), cn2 = 10, cn3 = 30,
es = .20, rho2 = .20, rho3 = .10, omega2 = .20, omega3 = .10,
r21 = .20, r2t2 = .20, r2t3 = .20, g3 = 1, n2 = 3, n3 = 50)
##  Results are equivalent to random assignment design
##  Solution converged with LBFGS
##
##  Rounded solution:
##  -----------------------------------------------
##      n1 [n2] [n3]     p [cost]    es 95%lcl 95%ucl power
##  12.047    3   50 0.437   9999 0.116  0.034  0.197 0.998
##  -----------------------------------------------
##  Per unit marginal costs:
##  Level 1 treatment: 5
##  Level 1 control: 3
##  Level 2: 10
##  Level 3: 30
##  -----------------------------------------------
##  MDES = 0.116 (with power = 80)
##  power = 0.998 (for ES = 0.2)
##  -----------------------------------------------
##  []: point constrained (fixed)
##  <<: bound constrained

## Block/Multisite Four-level Random Assignment (BIRA4r1) Design

# cost constrained - optimize n1 and p
cosa.bird4r1(constrain = "cost", cost = 50000, rhots = 0,
cn1 = c(5, 3), cn2 = 10, cn3 = 30, cn4 = 50,
es = .20, rho2 = .20, rho3 = .10, rho4 = .05,
omega2 = .20, omega3 = .10, omega4 = .10,
r21 = .20, r2t2 = .20, r2t3 = .20, r2t4 = .20,
g4 = 1, n2 = 3, n3 = 20, n4 = 5)
##  Results are equivalent to random assignment design
##  Solution converged with LBFGS
##
##  Rounded solution:
##  -----------------------------------------------
##      n1 [n2] [n3] [n4]     p [cost]    es 95%lcl 95%ucl power
##  37.653    3   20    5 0.437  50000 0.143  0.034  0.252  0.96
##  -----------------------------------------------
##  Per unit marginal costs:
##  Level 1 treatment: 5
##  Level 1 control: 3
##  Level 2: 10
##  Level 3: 30
##  Level 4: 50
##  -----------------------------------------------
##  MDES = 0.143 (with power = 80)
##  power = 0.96 (for ES = 0.2)
##  -----------------------------------------------
##  []: point constrained (fixed)
##  <<: bound constrained

# Treatment at level 2

## Cluster-level Random Assignment (CRA2r2) Design

# cost constrained - optimize n2 and p
cosa.crd2r2(constrain = "cost", cost = 10000, rhots = 0,
cn1 = 5, cn2 = c(10, 8),
es = .20, rho2 = .20, r21 = .20, r22 = .30,
g2 = 1, n1 = 10)
##  Results are equivalent to random assignment design
##  Solution converged with LBFGS
##
##  Rounded solution:
##  -----------------------------------------------
##  [n1]  n2     p [cost]    es 95%lcl 95%ucl power
##    10 170 0.412  10000 0.198  0.059  0.337 0.807
##  -----------------------------------------------
##  Per unit marginal costs:
##  Level 1 treatment: 5
##  Level 1 control: 5
##  Level 2 treatment: 10
##  Level 2 control: 8
##  -----------------------------------------------
##  MDES = 0.198 (with power = 80)
##  power = 0.807 (for ES = 0.2)
##  -----------------------------------------------
##  []: point constrained (fixed)
##  <<: bound constrained

## Block/Multisite Three-level Random Assignment (BCRA3r2) Design

# cost constrained - optimize n2 and p
cosa.bcrd3r2(constrain = "cost", cost = 10000, rhots = 0,
cn1 = c(5, 2), cn2 = 10, cn3 = 30,
es = .20, rho2 = .20, rho3 = .10, omega3 = .10,
r21 = .20, r22 = .20, r2t3 = .20,
g3 = 1, n1 = 25, n3 = 20)
##  Results are equivalent to random assignment design
##  Solution converged with LBFGS
##
##  Rounded solution:
##  -----------------------------------------------
##  [n1]  n2 [n3]     p [cost]   es 95%lcl 95%ucl power
##    25 5.2   20 0.404   9990 0.26  0.076  0.444 0.579
##  -----------------------------------------------
##  Per unit marginal costs:
##  Level 1 treatment: 5
##  Level 1 control: 2
##  Level 2 treatment: 10
##  Level 2 control: 10
##  Level 3: 30
##  -----------------------------------------------
##  MDES = 0.26 (with power = 80)
##  power = 0.579 (for ES = 0.2)
##  -----------------------------------------------
##  []: point constrained (fixed)
##  <<: bound constrained

## Block/Multisite Four-level Random Assignment (BCRA4r2) Design

# cost constrained - optimize n2 and p
cosa.bcrd4r2(constrain = "cost", cost = 100000, rhots = 0,
cn1 = c(5, 4), cn2 = 10, cn3 = 30, cn4 = 50,
es = .20, rho2 = .20, rho3 = .10, rho4 = .05,
omega3 = .10, omega4 = .20,
r21 = .20, r22 = .20, r2t3 = .20, r2t4 = .20,
g4 = 1, n1 = 25, n3 = 50, n4 = 5)
##  Results are equivalent to random assignment design
##  Solution converged with LBFGS
##
##  Rounded solution:
##  -----------------------------------------------
##  [n1]    n2 [n3] [n4]     p [cost]    es 95%lcl 95%ucl power
##    25 3.028   50    5 0.474  99995 0.212   0.05  0.374  0.74
##  -----------------------------------------------
##  Per unit marginal costs:
##  Level 1 treatment: 5
##  Level 1 control: 4
##  Level 2 treatment: 10
##  Level 2 control: 10
##  Level 3: 30
##  Level 4: 50
##  -----------------------------------------------
##  MDES = 0.212 (with power = 80)
##  power = 0.74 (for ES = 0.2)
##  -----------------------------------------------
##  []: point constrained (fixed)
##  <<: bound constrained

# Treatment at level 3

## Cluster-level Random Assignment (CRA3r3) Design

# cost constrained - optimize n3 and p
cosa.crd3r3(constrain = "cost", cost = 50000, rhots = 0,
cn1 = 5, cn2 = 10, cn3 = c(50, 20),
es = .20, rho2 = .20, rho3 = .10,
r21 = .20, r22 = .30, r23 = .40,
g3 = 1, n1 = 25, n2 = 3)
##  Results are equivalent to random assignment design
##  Solution converged with LBFGS
##
##  Rounded solution:
##  -----------------------------------------------
##  [n1] [n2]  n3     p [cost]   es 95%lcl 95%ucl power
##    25    3 114 0.456  50010 0.18  0.054  0.305 0.877
##  -----------------------------------------------
##  Per unit marginal costs:
##  Level 1 treatment: 5
##  Level 1 control: 5
##  Level 2 treatment: 10
##  Level 2 control: 10
##  Level 3 treatment: 50
##  Level 3 control: 20
##  -----------------------------------------------
##  MDES = 0.18 (with power = 80)
##  power = 0.877 (for ES = 0.2)
##  -----------------------------------------------
##  []: point constrained (fixed)
##  <<: bound constrained

## Block/Multisite Four-level Random Assignment (BCRA4r3) Design

# cost constrained - optimize n3 and p
cosa.bcrd4r3(constrain = "cost", cost = 50000, rhots = 0,
cn1 = c(5, 3), cn2 = 10, cn3 = 30, cn4 = 50,
es = .20, rho2 = .20, rho3 = .10, rho4 = .05, omega4 = .20,
r21 = .20, r22 = .20, r23 = .20, r2t4 = .20,
g4 = 1, n1 = 25, n2 = 3, n4 = 5)
##  Results are equivalent to random assignment design
##  Solution converged with LBFGS
##
##  Rounded solution:
##  -----------------------------------------------
##  [n1] [n2]   n3 [n4]     p [cost]    es 95%lcl 95%ucl power
##    25    3 28.2    5 0.447  49885 0.312  0.073  0.551 0.449
##  -----------------------------------------------
##  Per unit marginal costs:
##  Level 1 treatment: 5
##  Level 1 control: 3
##  Level 2 treatment: 10
##  Level 2 control: 10
##  Level 3 treatment: 30
##  Level 3 control: 30
##  Level 4: 50
##  -----------------------------------------------
##  MDES = 0.312 (with power = 80)
##  power = 0.449 (for ES = 0.2)
##  -----------------------------------------------
##  []: point constrained (fixed)
##  <<: bound constrained

# Treatment at level 4

## Cluster-level Random Assignment (CRA4r4) Design

# cost constrained - optimize n4 and p
cosa.crd4r4(constrain = "cost", cost = 500000, rhots = 0,
cn1 = 5, cn2 = c(10, 5), cn3 = c(30, 10), cn4 = c(50,30),
es = .20, rho2 = .20, rho3 = .10, rho4 = .05,
r21 = .20, r22 = .30, r23 = .40, r24 = .50,
g4 = 1, n1 = 25, n2 = 3, n3 = 10)
##  Results are equivalent to random assignment design
##  Solution converged with LBFGS
##
##  Rounded solution:
##  -----------------------------------------------
##  [n1] [n2] [n3]  n4     p [cost]    es 95%lcl 95%ucl power
##    25    3   10 119 0.462 499920 0.099   0.03  0.168     1
##  -----------------------------------------------
##  Per unit marginal costs:
##  Level 1 treatment: 5
##  Level 1 control: 5
##  Level 2 treatment: 10
##  Level 2 control: 5
##  Level 3 treatment: 30
##  Level 3 control: 10
##  Level 4 treatment: 50
##  Level 4 control: 30
##  -----------------------------------------------
##  MDES = 0.099 (with power = 80)
##  power = 1 (for ES = 0.2)
##  -----------------------------------------------
##  []: point constrained (fixed)
##  <<: bound constrained