# stratify: Stratification of an Auxiliary Variable In optimStrat: Choosing the Sample Strategy

## Description

Stratify the auxiliary variable `x` into `H` strata using the cum-sqrt-rule.

## Usage

 `1` ```stratify(x, H, forced = FALSE, J = NULL) ```

## Arguments

 `x` a positive numeric vector giving the values of the auxiliary variable. `H` a positive integer smaller or equal than `length(x)` giving the desired number of strata. `forced` a logical value indicating if the number of strata must be exactly equal to `H` (see ‘Details’). `J` a positive integer indicating the number of bins used for the cum-sqrt-rule.

## Details

The cum-sqrt-rule is used in order to define `H` strata from the auxiliary vector `x`.

Depending on some characteristics of `x`, e.g. high skewness, few observations or too many ties, the resulting stratification may have a number of strata other than `H`. Using `forced = TRUE` tries its best to obtain exactly `H` strata.

Note that if `length(x) < H` then `forced` will be set to `FALSE`.

## Value

A numeric vector giving the stratum to which each observation in `x` belongs.

## References

Sarndal, C.E., Swensson, B. and Wretman, J. (1992). Model Assisted Survey Sampling. Springer.

`optiallo` for allocating the sample into the strata using Neyman optimal allocation.

## Examples

 ```1 2``` ```x<- 1 + sort( rgamma(100, shape=4/9, scale=108) ) stratify(x, H=3) ```

### Example output

```sh: 1: cannot create /dev/null: Permission denied