2-Stage surveys for demonstration of freedom
# Calculate sample sizes for 2-stage freedom survey with fixed cluster-level sensitivity

### Inputs

### Outputs

**Note:**

Calculate sample sizes for 2-stage surveys for demonstrating disease freedom, for specified target cluster-level sensitivity and system (population) sensitivity. This analysis calculates the number of clusters and the number of units within each cluster to be tested to provide specified cluster and system sensitivities (probability of detecting disease) for the given unit and cluster-level design prevalences and test sensitivity. Test specificity is assumed to be 100% (or follow-up testing of any positive will be undertaken to confirm or exclude disease).

Numbers of clusters to test are calculated using the hypergeometric approximation if the number of clusters in the population is specified as well as using the binomial fomula assuming unknown (large) number of clusters in the population. If the population size is not specified only the binomial results are presented.

Numbers of units to test in each cluster are calculated for a range of cluster sizes using the hypergeometric approximation and for unknown (large) cluster sizes using the binomial calculation.

Design prevalence (specified level of disease to be detected) must be specified at both unit and cluster levels. Design prevalence can be specified as either:

- a proportion of the population infected; or
- a specific (integer) number of units or clusters infected. For cluster-prevalence, the number of clusters in the population must be specified if design prevalence is specified as an integer.

Inputs required include:

- unit-level design prevalence as either a proportion or an integer number of units;
- cluster-level design prevalence as either a proportion or an integer number of clusters;
- the estimated test sensitivity;
- the target cluster-level sensitivity (SeH) which is the probability of detecting disease if it is present in a cluster at the specified unit-level design prevalence;
- the target system sensitivity (SSe) which is the probability of detecting disease if it is present in the population at the specified unit and cluster level design prevalences;
- The number of clusters in the population (optional).

Outputs from the analysis include:

- The total numbers of clusters to be sampled;
- The maximum total sample size;
- The numbers of units to test in each cluster, for a range of cluster sizes to achieve the specified value for SeH; and
- The numbers of units to test in cluster and the corresponding numbers of clusters to test, for a range of cluster sizes and SeH values.

- If it is not possible to achieve the desired cluster sensitivity by testing all units in a cluster of given size, the sample size is left blank;
- If unit-level prevalence is specified as a number of units, sample size for an unknown cluster size cannot be calculated;
- If cluster-level prevalence is specified as a number of clusters, the number of clusters to be sampled for a large or unknown population cannot be calculated and population size must be specified.