Learn R Programming

cosa (version 1.2.0)

cosa-package: Constrained Optimal Sample Allocation

Description

Constrained Optimal Sample Allocation (COSA) functions are designed to optimize sample sizes at one or more levels subject to budget, statistical power, or effect size constraints. COSA can be found in the following forms; (i) under budgetary constraints given marginal costs per unit while minimizing the sampling variance of the treatment effect (or, alternatively, while maximizing statistical power), (ii) under statistical power or effect size (ES) constraints while minimizing the total cost, and (iii) under sample size constraints for one or more levels along with (i) or (ii). Specifying rhots = 0 produces result equivalent to corresponding random assignment designs, which means there is no relationship between the treatment [random] and the score variable. Therefore, COSA functions also allows optimization of proportion of treatment allocation (p) under unequal marginal costs when primary constraint is on total cost. Different starting values and algorithms may produce different results especially when marginal cost information is not provided and sample sizes at two or more levels and p are optimized. Comparing several algorithms may faciliate decisions regarding sample sizes and p.

Designs available in cosa package:

Design Total Levels Treatment Level Top Level
ird1r1 1 1 random
bird2r1 2 1 random
bird2f1 2 1 fixed
bird3r1 3 1 random
bird4r1 4 1 random
crd2r2 2 2 random
bcrd3f2 3 2 fixed
bcrd3r2 3 2 random
bcrd4r2 4 2 random
crd3r3 3 3 random
bcrd4f3 4 3 fixed
bcrd4r3 4 3 random

ird: individual-level regression discontinuity. bird: blocked individual-level regression discontinuity. crd: cluster-level regression discontinuity. bcrd: blocked cluster-level regression discontinuity.

Design parameters follows a sequential order. Numbers at the end of a sequential parameter refers to the corresponding level. For example rho2 is the proportion of variance in the outcome between level 2 units, rho3 is the proportion of variance in the outcome between level 3 units. Similiarly, r21 is the proportion of the variance in the outcome explained by level 1 covariates, r22 is the proportion of the variance in the outcome explained by level 2 covariates and so on. Similiar naming conventions applies to other design parameters.

Wrapper functions described below pass arguments to design-specific functions. Most of the arguments should be specified in the vector or list form length of which depends on the type of design specified in design argument. To use these functions, some knowledge about design parameters is required. For example for design = "bird3r1" the length of rho is 2, the length of omega is 2, the length of r2 is 1, and the length of r2t is 2. Otherwise design-specific functions are recommended.

Usage

cosa(design = "ird1r1",
     cn = as.list(rep(0, length(n))), cost = NULL,
     n = list(NULL), p = NULL, n0 = rep(5 + g, length(n)), p0 = .499,
     constrain = "power", local.solver = c("LBFGS", "SLSQP", "MMA", "COBYLA"),
     power = .80, es = .25, alpha = .05, two.tailed = TRUE,
     rhots = NULL, k = c(-6, 6), dists = "normal",
     rho = NULL, omega = NULL, r2t = NULL,
     r2 = 0,  g = 0)

mdes(design = "ird1r1", power = .80, alpha = .05, two.tailed = TRUE, rhots = NULL, k = c(-6, 6), dists = "normal", rho = NULL, omega = NULL, r2t = NULL, r2 = 0, n = 250, g = 0, p = .50)

power(design = "ird1r1", es = .25, alpha = .05, two.tailed = TRUE, rhots = NULL, k = c(-6, 6), dists = "normal", rho = NULL, omega = NULL, r2t = NULL, r2 = 0, n = 250, g = 0, p = .50)

Arguments

design

One of the "ird1r1", "bird2f1", "bird2r1", "bird3r1", "bird4r1", "crd2r2", "bcrd3f2", "bcrd3r2", "bcrd4r2", "crd3r3", "bcrd4f3", "bcrd4r3", "crd4r4".

cn

list of marginal costs per unit (positional). e.g. list(cn1, cn2, cn3).

cost

total cost or budget.

n

list of sample sizes (positional). e.g. list(n1, n2, n3).

p

proportion of units in treatment condition.

n0

vector of starting values for n (positional). Starting values are replaced with averages when sample sizes are constrained by bounds.

p0

starting value for p when rhots = 0 and p = NULL. Starting value is replaced with average when p is constrained by bounds.

power

statistical power (1 - \(\beta\)).

es

effect size (Cohen's d).

alpha

probability of type I error (\(\alpha\)).

two.tailed

logical; TRUE for two-tailed hypothesis testing.

constrain

character; "cost", "power", or "mdes".

local.solver

subset of c("LBFGS", "SLSQP", "MMA", "COBYLA").

rhots

correlation between the treatment and the scoring variable. Specify rhots = 0 to obtain results equivalent to random assignment designs.

k

vector of left and right truncation point (in standard deviation units from full normal distribution mean), ignored when rhots is not NULL or dists = "uniform". e.g. c(k1, k2).

dists

character; distribution of the scoring variable, "normal" or "uniform". By default, dists = "normal" specification implies a truncated normal distribution with k = c(-6, 6).

rho

vector or list; proportion of variance in the outcome between level X units. e.g. c(rho2, rho3) (unconditional ICC).

omega

vector or list; ratio of the treatment effect variance between level X units to the variance in the outcome between level X units (positional) e.g. c(omega2, omega3).

g

number of covariates at the top level.

r2

vector or list; proportion of variance in the outcome explained by level X covariates (positional). e.g. c(r21, r23)

r2t

vector or list; proportion of treatment effect variance between level X units explained by level X covariates (positional). e.g. c(r2t2, r2t3)

Value

parms

list of parameters used in the function.

df

degrees of freedom.

sse

standardized standard error.

cosa

constrained optimal sample allocation.

mdes

minimum detectable effect size and (1 - \(\alpha\))% confidence limits.

power

statistical power (1 - \(\beta\))

Examples

Run this code
# NOT RUN {
# cost constrained - optimize n2 and n3
cosa(design = "crd3r3", rhots = 0,
     cn =list(c(5, 3), c(10,5), c(50,20)),
     constrain = "cost", cost = 15000,
     rho = c(.17, .06),
     g = 4, r2 = c(.30, .20, .20),
     n = list(15, NULL, NULL))

# minimum detectable effect size
mdes(design = "crd2r2",
     rho = .20,
     r2 = c(0, 0),
     p = .50, n = c(4, 20))

# statistical power
power(design = "bird3r1",
      rho = c(.17, .06),
      r2 = 0, r2t = c(0, 0),
      omega = c(.30, .30),
      p = .50, n = c(15, 3, 60))
# }

Run the code above in your browser using DataLab