Field sites and monitoring

We studied coconut crabs at the western edge of the species’ distribution on Pemba Island, Tanzania, which is characterised by a warm, humid, tropical climate. Five field sites were visited (all coordinates in decimal degrees, latitude-longitude, respectively): (1) Makangale Beach (− 4.924, 39.675), (2) Ras Kigomasha (− 4.868, 39.683), (3) Fundo Island (− 5.063, 39.647), (4) Kisiwa Panza (− 5.459, 39.647) and 5) Misali Island (− 5.235, 39.607). Sites have a varied composition of habitats ranging from shoreline, beach, coral rag, thicket and then a sharp edge bordering areas cleared for cultivation ascending in that order away from the shore. We recorded the habitat type where crabs were found as closed, edge, and open areas (i.e. thickets, edge and cultivated habitats); none were found on beaches. We collected crabs by walking trails through these habitat types during evenings after sunset. Crabs were typically heard first, then located using a white LED torch and captured by hand. The crabs were then placed in a container to be photographed. Before release the crabs were marked (using a blue marker) on their dorsal carapace to avoid measuring the same individual again.

Photographic measurements

To quantify the colour and pattern of the coconut crabs, we took photographs with a Samsung NX1000 camera, customised to full spectrum range with Nikon EL-80 mm lens and mounted on a tripod (Velbon Ultra LUXi L with PHD-410 mount). The photographs were taken in the field by placing crabs one by one inside a transparent plastic container (size approximately 50 × 40 × 30 cm) in which photographic standards were also placed. We illuminated the scene with a white-LED torch. As these animals are chiefly nocturnal in populations where they are hunted (e.g. Pemba), we took photos using only light in the human-visible spectrum, since nightly illumination is low (Table S1; lux readings) and the level of ultraviolet light is small.

Images were analysed with a custom multispectral image analysis plugin using image J software (Troscianko and Stevens 2015). The protocol workflow consists of several steps. First the images were screened for quality control. The photographs were then converted as linear 16-bit images and the relevant channels extracted according to camera configuration file. The images were linearized based on quantified camera responses to control for nonlinear responses in image value to changes in light levels (Stevens et al. 2007). Grey standards (93% white and 7% black) were selected and image channels aligned. The toolbox creates a configuration file and the multispectral image stack is converted into 32-bit normalised image stack. After this regions of interest were selected from the photos.

We measured the whole abdominal and thoracic carapaces that were visible from the dorsal side and we also measured the ventral side from the first leg segments closest to the body. These regions of interest were used to extract data about colour metrics and pattern diversity. The images were first equalized and converted to reflectance data (Troscianko and Stevens 2015). The camera’s responses to short, medium, and long wavelengths (i.e. blue, green, and red channels) were used to calculate hue, being a ratio of short wavelengths versus long wavelengths (LW/SW, i.e. red divided by blue channel) (Komdeur et al. 2005; Stevens et al. 2014). This channel was chosen since a priori it was expected to be the most effective for distinguishing individual morphs based on colour.

We also extracted several pattern metrics from the photographs. Pattern analysis procedure involves decomposing an image into a series of different spatial frequencies (‘granularity bands’) using Fourier analysis and band pass filtering, followed by determining the relative contribution of different marking sizes to the overall pattern spectrum (Barbosa et al. 2008; Hanlon et al. 2009; Stoddard and Stevens 2010). This filtering into different frequency bands captures pixel energy at different spatial scales, which corresponds to different sized markings (for details how pattern analysis was conducted see Troscianko and Stevens 2015). From each granularity spectrum, we obtained several carapace pattern metrics (Stoddard and Stevens 2010): (1) proportion energy (i.e. how much one marking size dominates, or the diversity of marking sizes), whereby a high value indicates that the pattern is dominated by one or a few marking sizes; (2) total energy (i.e. pattern contrast), being the total energy or amplitude of the spectrum (Chiao et al. 2009), whereby higher values indicate more contrasting markings; and (3) marking size (i.e. dominant marking size of the crab pattern) based on the maximum energy value at any point in the spectrum. Note that while we did not test melanisation as percentage, we used several pattern metrics testing carapace melanisation (see hypotheses above). All analyses were conducted on normalised camera responses (i.e. reflectance information), and no vision modelling was undertaken.

Morphological measurements and behaviour

We took several morphological measurements (Table 1). We measured live weight to the closest gram using a spring scale. Carapace width and length were measured from the abdominal carapace from the widest point to the shortest point, respectively (Fletcher 1969). Lengths of both chelae were also measured. Sex was determined from the presence of abdominal pleopods, an organ that berried females use to maintain an offspring clutch, that does not occur in males (Fletcher 1969). As coloration has been reportedly associated with competitiveness in some decapods (Reid et al. 1997), we ranked individuals subjectively into two broad behavioural categories (shy or bold) depending on the level of aggression that they showed when while being measured. They were ranked as ‘calm’ if passive to handle, or ‘bold’ if they were aggressive (i.e. defending themselves) or trying to escape.

Table 1 Mean morphometric measures of adult coconut crabs sampled on Pemba in 2016 Full size table

Measuring background matching

To evaluate the degree of background matching, we used colour values of the dorsal abdominal carapace and backgrounds categorized into six broad types that characterized predominant habitat types: shore, beach, coral rag, thicket, edge and cultivated areas. Background matching was determined as Euclidian distance of the crab coloration to the background (in two dimensional XY colour space, e.g. Kelber et al. 2003). Prior to analysis, camera colour channel values (RGB) were converted into XY colour space. After this, the colour distance (i.e. background match) of crabs were calculated against the backgrounds using the formula: distance = √(((X crab − X background )2) + ((Y crab − Y background )2)). This provides a receiver independent estimate of the degree of background match across habitat types. We chose to use this approach and to not construct vision models that would be specific to particular perceptual systems, as it is not yet known which non-human species are the most important predators of coconut crabs on Pemba.

Statistical analyses

Prior to analyses, all colour and pattern metrics were log-transformed to satisfy normality. All statistical analyses were performed with the R Statistical Package v 3.1.2 (R Core Team 2015) and IBM SPSS Statistics (v22).

Discriminant function analysis (DFA) was conducted to determine if colour varies in a polymorphic fashion and what colour and pattern metrics best characterize this (Huberty and Olejnik 2006; Barbosa et al. 2008; Troscianko and Stevens 2015). The analysis was conducted separately for abdominal and thoracic carapaces and ventra. In the discriminant function analysis, we used a visually pre-defined colour (red, blue) as a grouping variable. We used a stepwise method with Mahalanobis distances to test significance of independent variables explaining the grouping value using a leave-one-out-method. Independents used were LW, MW, SW and hue for the colour and energy at the maximum spatial frequency, dominant marking size, pattern diversity, contrast and mean energy for the pattern. The criterion of entry was based on F-value of 3.84 and removal 2.71 (Huberty and Olejnik 2006).

To obtain an alternative perspective on the DFA results, we also conducted a principal component analysis (PCA) for the colour metrics, and plotted the first two components against each other to investigate the degree of clustering based on colour values. We conducted two PCA’s. The first included only colour variables: normalised camera responses to red, green and blue channels for both abdominal dorsal carapace and ventral side. The second included both colour and pattern metrics for dorsal abdominal and thoracic carapaces and ventral side as follows: red, green and blue channels, hue (R/B-channels) for colour, and maximum spatial frequency, dominant marking size, pattern diversity, and contrast for the pattern.

Crab coloration was also analysed with respect to weight, carapace and chelae size. Before analysing carapace and chelae size these were condensed with a principal component analysis as carapace length and width were highly correlated with each other, likewise as were the size of right and left chelae, the latter of which is larger. Carapace size yielded one principal component, which explained 97.9% of the variation in carapace size with eigenvalue 1.958. Chelae size yielded one principal component, which explained 89.6% of the variation in carapace size with eigenvalue 1.792. These two variables were used to represent carapace and chelae size variation in the analyses. We tested these morphological variables using a general linear model with morphometric (weight, carapace, chelae) as dependent variables and sex and colour morph as explanatory variables. Full models were fitted but non-significant terms subsequently removed. The frequency-based data of crab behaviour and habitat use was analysed with non-parametric Chi Squared test statistics.

To test background matching we transformed camera raw values into XY-colour space, and determined the distance between representative samples of backgrounds (see above). These data were then analysed using linear mixed effects models (LMer-function) in R. We analysed the background match of colour types across different habitat types. Distance was set as dependent variable and the colour morph, the habitat type and the corresponding interactions as predictor variables (Table 2). Individual was set as random factor to control for dependency structure, because colour values were compared across several background types. Crabs were never resampled individuals as we marked them after photography.