specify_clusters {CRTspat}R Documentation

Algorithmically assign locations to clusters in a CRT


specify_clusters algorithmically assigns locations to clusters by grouping them geographically


  trial = trial,
  c = NULL,
  h = NULL,
  algorithm = "NN",
  reuseTSP = FALSE



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


integer: number of clusters in each arm


integer: number of locations per cluster


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.

logical: indicator of whether a pre-existing path should be used by the TSP algorithm


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.


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


#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)

[Package CRTspat version 1.2.0 Index]