A function to create homogeneous groups of named objects according
to an objective function evaluated at a covariate. It can be useful
to design experiments which contain a fixed covariate factor.
Usage
creategroups(x, ngroups, sizes, fun = mean, tol = 0.01, maxit = 200)
Arguments
x
a numeric vector of a covariate at which to evaluate the objective function.
ngroups
the number of groups to create.
sizes
a numeric vector of length equal to ngroups containing the group sizes.
fun
the objective function, i.e., to create groups with similar fun; default is mean.
tol
the tolerance level to define the groups as homogenenous; see details.
maxit
the maximum number of iterations; default is 200.
Value
The value returned is a list of named vectors containing the values
for the groups. Also, the result of the objective function evaluated
at the covariate x is always printed, as well as the number of iterations
required to achieve convergence.
Details
creategroups uses a tol value to evaluate the following statistic:
$h = \sum_{j}^{ngroups} abs( t_{j+1} - t_j ) / ngroups$, where $t_j = fun(group_j)$.
If $h \leq tol$, the groups are considered homogeneous.