# Algorithmically assign locations to clusters in a CRT

`specify_clusters.Rd`

`specify_clusters`

algorithmically assigns locations to clusters by grouping them geographically

## Arguments

- trial
A CRT object or data frame containing (x,y) coordinates of households

- c
integer: number of clusters in each arm

- h
integer: number of locations per cluster

- algorithm
algorithm for cluster boundaries, with options:

`NN`

Nearest neighbour: assigns equal numbers of locations to each cluster `kmeans`

kmeans clustering: aims to partition locations so that each belongs to the cluster with the nearest centroid. `TSP`

travelling salesman problem heuristic: Assigns locations sequentially along a travelling salesman path. - reuseTSP
logical: indicator of whether a pre-existing path should be used by the TSP algorithm

## Value

A list of class `"CRTsp"`

containing the following components:

`geom_full` | list: | summary statistics describing the site, and cluster assignments. |

`trial` | data frame: | rows correspond to geolocated points, as follows: |

`x` | numeric vector: x-coordinates of locations | |

`y` | numeric vector: y-coordinates of locations | |

`cluster` | factor: assignments to cluster of each location | |

`...` | other objects included in the input `"CRTsp"` object or data frame |

## Details

The `reuseTSP`

parameter is used to allow the path to be reused
for creating alternative allocations with different cluster sizes.

Either `c`

or `h`

must be specified. If both are specified
the input value of `c`

is ignored.

## Examples

```
#Assign clusters of average size h = 40 to a test set of co-ordinates, using the kmeans algorithm
exampletrial <- specify_clusters(trial = readdata('exampleCRT.txt'),
h = 40, algorithm = 'kmeans', reuseTSP = FALSE)
```