Introduction

Historically, the most common use of camera traps for abundance estimation involved individually identifiable animals—either those with natural markings like spots or stripes, or with artificial markings placed by researchers. When animals are individually identifiable, researchers can use capture–recapture or mark–resight models (Karanth 1995; Karanth and Nichols 1998; Rich et al. 2014). More recently, spatially explicit versions of capture–recapture have also been implemented with cameras (Royle et al. 2009; Sollmann et al. 2013). However, many species have no natural markings that allow individual identification. Artificially marking animals can be expensive and dangerous to both humans and wildlife. Therefore, camera methods without the need for individual identification have gained traction in recent years, including the space and time to event models (STE and TTE) and instantaneous sampling estimator (IS) (Moeller et al. 2018).

The mathematical derivation of the STE, TTE, and IS models and their assumptions are described in detail in Moeller et al. (2018), but the authors do not focus on how to implement the models in the field or on the computer. In this paper, we introduce spaceNtime, a free R package for estimating abundance using STE, TTE, and IS. Here, we first summarize the models and their assumptions but refer readers looking for additional detail to Moeller et al. (2018). In the Functionality section, we detail the necessary components for each model, and we describe the steps to run each analysis in a complete R workflow from processing data to estimating abundance.

As detailed in Moeller et al. (2018), TTE and STE models use the mathematical relationship between the Poisson and exponential distributions to estimate animal density, and the IS estimator uses fixed-area point counts. Conceptually, TTE and STE rely on the basic idea that greater abundance in an area leads to greater detection rates at cameras. The first of these, TTE, estimates abundance from the amount of time that elapses before an animal enters the viewshed of a given camera. As shown by Moeller et al. (2018), if the number of animals in view of camera i on occasion j can be modeled by

$${N}_{ij}\sim \mathrm{Pois}\left(\lambda \right),$$
(1)

then the time to event at camera i on occasion j is modeled by

$${T}_{ij} \sim \mathrm{Exp}\left(\lambda \right).$$
(2)

Because time to detection also depends on animal movement, TTE requires an independent estimate of animal movement rate. Conceptually, STE is similar to TTE with space substituted for time (Moeller et al. 2018). At an instantaneous point in time j, the space to event is modeled by

$${S}_{j} \sim \mathrm{Exp}\left(\lambda \right).$$
(3)

Space to event is defined as the amount of area sampled on the ground until the species of interest is encountered. In contrast to TTE, the STE model uses instantaneous sampling occasions, and therefore it does not depend on movement rate. IS is a reduction of STE that uses fixed-area point counts at multiple instantaneous points in time. IS density is estimated by

$$\widehat{D}=\frac{1}{J}\bullet \frac{1}{M}\sum_{j=1}^{J}\sum_{i=1}^{M}\frac{{n}_{ij}}{{a}_{ij}}$$
(4)

where nij is the count of animals in camera i = 1, 2, …, M on occasion j = 1, 2, …, J and a is the camera’s viewable area. All three methods estimate average density within the viewable area of the cameras, then scale that density up to the area of interest (i.e., the sampling frame).

Moeller et al. (2018) describe four basic assumptions for STE, TTE and IS. First, they show that camera sites should be representative of the sampling frame. To implement this, cameras should be randomly or systematically deployed across the sampling frame. Practices to increase detections, such as targeting high-use trails, should be avoided as they can bias the abundance estimate. Second, the authors note that animals should have no behavioral response to cameras or camera sites. This precludes the use of bait or lures to increase encounter rates. It also means that cameras should be unobtrusive and not repel animals with bright flashes or human scent. Third, the authors indicate that the population should be closed and all animals should be available for detection. However, if the population is not closed and animals temporarily leave the sampling frame or become unavailable for detection (e.g., by hibernating), the models will estimate the mean number of animals present and available in the sampling frame over the course of the study (Loonam et al. 2021). Fourth, the area viewed by each camera should be known across time and measured accurately. If camera area is not measured accurately, abundance estimates will be biased.

In addition to the four assumptions common to all three methods, Moeller et al. (2018) describe several assumptions that apply to some, but not all, of the three methods. For STE and TTE, animal abundance should follow a Poisson distribution at the level of the camera. In other words, animals should move independently at the spatial scale of the camera’s viewshed. TTE is the only method of the three that requires an estimate of mean animal movement rate, defined across all animal behaviors, including rest (Moeller et al. 2018). Finally, for STE and IS, sampling should be instantaneous. In practice, sampling occasions should be short enough to approximate a snapshot of the landscape at a moment in time (Moeller et al. 2018).

Moeller et al. (2018) indicate that time-lapse photography provides a good way to meet the assumption of instantaneous sampling occasions for STE and IS. With time-lapse photography, a camera takes photos at even intervals throughout the day (e.g., every 15 min). Therefore, sampling effort, as defined by the number of cameras functioning throughout the study, is simple to quantify from time-lapse photography; cameras are known to be functioning when photos are taken at the expected intervals and cameras are not functioning if no photo is taken. With time-lapse photography, detection probability for STE and IS is narrowly defined as the probability that a species is correctly identified by an observer, given that it is in a photo. Although time-lapse photography has huge advantages for determining sampling effort and detection probability, most camera trap studies to date have relied on motion-sensor photography, with the goals of increasing detections of animals and decreasing the occurrence of “empty” photos. Motion-sensor datasets are produced through a complex combination of a detection function, an effort function, and species presence. For STE and IS, motion-sensor detection probability is defined by four conditions: the animal is present in the camera’s viewshed, the motion sensor detects the animal, the camera takes a picture with the animal still in view, and the user correctly identifies the species. This definition shows that motion-sensor detection probability is entwined with motion-sensor effort, meaning the camera was working as intended. Sampling effort is difficult to quantify from motion-sensor photography, as the outcome (no picture) is the same whether the camera stops working, the motion-sensor doesn’t detect the animal, or the animal is absent. Time-lapse photography can help define motion-sensor effort if the two are used in conjunction. For example, time-lapse photos throughout the day will show that the batteries are functioning, the lens is clear of snow and debris, and the camera is pointed in the intended direction, which can help give confidence that the motion sensor is working as intended. As memory storage becomes increasingly inexpensive and image processing can be done automatically (Tabak et al. 2019), there is little downside to collecting time-lapse data for STE and IS analyses. For TTE, which needs time-to-detection data provided by motion sensors, the combination of time-lapse and motion-sensor photography time-lapse is beneficial.

As described earlier, STE and TTE use camera data in a particularly unique way that may be unfamiliar to many users. Rather than using counts of individual animals or independent detection events, STE uses the amount of space sampled by cameras until an animal detection at a given time, while TTE uses the time elapsed from an arbitrary starting point to the first detection of the species of interest. Furthermore, users have different levels of familiarity with statistics and estimating model parameters from data, both of which are required for implementing STE and TTE. Therefore, we developed spaceNtime, an R package designed to assist in implementing space to event, time to event, and instantaneous sampling methods. We developed a set of functions for transforming camera data to create encounter histories to fit these models.

We demonstrate an example analysis of STE on simulated data, and we detail the workflow from data entry through analysis output. The package spaceNtime can be downloaded directly from GitHub using the R command devtools::install_github(“annam21/spaceNtime”). A detailed vignette on running all three analyses is included in the package, and adding the optional argument build_vignettes = TRUE to the previous command will allow the user access to the vignette. The package provides tools to assist the user and outlines a complete workflow from data transformation to abundance estimates.

Functionality


The spaceNtime workflow can be divided into five major steps (Fig. 1). It begins with photo processing and ends with estimating density or abundance. Many functions are shared between STE, TTE and IS. Functions that are particular to one analysis begin with the prefixes ste_, tte_ or ise_. The workflow steps are:

  1. 1.

    Data preparation: record information from photos and transform data into the required format for further analysis.

  2. 2.

    Define sampling effort: specify when cameras were turned on and functioning, along with their viewshed area.

  3. 3.

    Specify sampling occasions: define sampling intervals that will be used to subset camera data and estimate abundance.

  4. 4.

    Build encounter history: build the encounter history for the appropriate analysis.

  5. 5.

    Estimate density or abundance: run the analysis and return an estimate of density or abundance in the defined study area.

Fig. 1
figure 1

The spaceNtime workflow for count data. The user will go through five major steps for STE, TTE, and IS analyses. If the user has presence/absence (0 and 1) data instead of count data, the IS analysis is not appropriate, and the IS pathway should be removed from the flowchart

Step 1. Data preparation

The workflow begins when the user looks through photos and records species detections in a database. The user can record animal detections using any software or database designed for photo processing and data entry. One of the greatest advantages of camera traps is that they collect data that can be used to address multiple questions for multiple species, and we expect users will want to maximize the information collected during photo processing. We therefore recommend that users record the count of individuals of every species of interest in every photo. This method of data processing allows for the most flexibility to run STE, TTE, and IS, as well as many additional analyses.

The spaceNtime workflow is designed to estimate abundance of one species at a time. The user should begin with an R data.frame with one record for every photo. These data should have at minimum, a column named cam, containing unique IDs for each camera, a column datetime with the date and time the photo was taken, and a column count with the number of individuals of the target species in the photo (Table 1). The IS method is the only method of the three that uses counts of animals; STE and TTE use presence (1) and absence (0) only. For STE and TTE analyses, spaceNtime recognizes any value greater than or equal to 1 in the count column as presence, and 0 as absence.

Table 1 An example input data frame, with a record for each photo

Step 2. Define sampling effort

The second step in the spaceNtime workflow is to define sampling effort. In this context, sampling effort refers to the times cameras are fully functioning and viewable area is known. The first component, camera functioning, is easy to quantify when using time-lapse photography. If there is a photo at a time-lapse interval, the camera was working properly. If there is no photo, the camera was not working. Camera functioning is much more difficult to quantify when using motion-sensor photography. For example, if snow collects on the motion sensor and prevents the camera from taking photos, the user may not have any indication that this occurred. For motion-sensor photography, the user must make an informed guess about the period in which the camera was functioning. The second component of sampling effort is viewable area, which can vary over time due to factors, such as weather, time of day, vegetative growth, and changes to the camera setup. Once again, time-lapse photography makes quantifying changes to viewable area much easier than motion-sensor photography does. Time-lapse photography provides a complete record of viewable area over time. The user can determine whether the lens is obscured for any reason, and if so, set the viewable area to 0. If the lens is only partially obstructed and the viewable area can be calculated, the user can define the viewable area for that occasion. In contrast, with motion-sensor photography, the user only has a record of the camera’s viewable area when animals are present and photos are taken. The user must assume that the same area is sampled when photos are taken and when they are not.

Because many existing datasets consist of only motion-sensor photography, we created the functionality in this package to allow use of either time-lapse or motion-sensor photography or both. Regardless of whether the user has time-lapse or motion-sensor photography, sampling effort will have a similar structure (Tables 2 and 3). The user will create an R data.frame with a record for each period of time in which each camera was functioning as intended and had a constant viewable area. The sampling effort data.frame will contain the columns cam with unique IDs for each camera, start and end for the start and ends of each period of camera functioning, and area with the viewable area during that period. For time-lapse photography, sampling effort can be defined directly from the photographic data and will look similar to the data created in Step 1 (Table 2). With timelapse photography, viewable area can be defined for every photo. Any photos missing at time-lapse intervals imply that the camera was not correctly functioning. In Step 4 of the workflow, spaceNtime will interpret the absence of a photograph at a time-lapse interval as 0 sampled area. Whereas the sampling effort for time-lapse photography is defined at each time-lapse interval, for motion-sensor photography, sampling effort is defined by longer time periods in which the camera is assumed to be properly functioning and viewable area remains constant (Table 3). In Step 4 of the spaceNtime workflow, the package will assume that any non-detection (i.e., lack of photo) within the user-defined time period of camera functioning is a “true” 0 and the target species was not present in the camera’s viewshed. In contrast, any periods of time excluded from the sampling effort will be interpreted as the camera not functioning and will be treated as 0 sampled area.

Table 2 The structure of sampling effort for time-lapse photography
Table 3 The structure of sampling effort for motion-sensor photography

Step 3. Specify sampling occasions

All three of the estimators use samples of the camera data at given times, which are known as sampling occasions. STE and IS use instantaneous sampling occasions, whereas TTE uses longer sampling occasions. First, for STE and IS, sampling occasions are instantaneous moments in time in which every camera has a record of species presence/absence (for STE) or group count (for IS) (Moeller et al. 2018). The most straight-forward way to meet the assumption of instantaneous sampling occasions is to use time-lapse photography with all cameras coordinated to take photos at the same time. If time-lapse photography is not available, motion-sensor datasets can be used instead. To use motion-sensor photography for STE and IS, sampling occasions can be defined as very short windows of time rather than instantaneous moments (see Table 4). Consecutive sampling occasions for STE and IS should be separated by enough time to allow animals to redistribute themselves on the landscape (Moeller et al. 2018).

Table 4 The structure of sampling occasions for an STE or IS analysis, which can be built with the function build_occ()

TTE sampling occasions, on the other hand, are long periods of time that are defined by independent estimates of animal movement speed and the camera viewshed. As described in Moeller et al. (2018), TTE sampling occasions are broken up into k = 1, 2, …, K sampling periods. A sampling period is defined as the average length of time needed for an animal to move across the camera viewshed (also see Loonam et al. 2021). For example, if the camera viewshed is 100 m across and the species moves on average 100 m/h, each sampling period will be 1 h. The TTE sampling occasion is made up of multiple sampling periods and will be a length of time (e.g., 24 h) within which a camera is continuously monitoring a viewshed. There is currently no definitive rule for the number of sampling periods that should make up a sampling occasion, so the choice is somewhat arbitrary (Moeller et al. 2018).

In the spaceNtime workflow, sampling occasions for all three analyses have a similar structure of rows and columns (Tables 4 and 5). Sampling occasions will be defined in an R data.frame with a single row for each occasion. The data.frame should have, at minimum, the columns occ, with a consecutive unique ID for each sampling occasion, as well as columns start and end for the start time and end time of the sampling occasion. Sampling occasions either can be defined manually in this format by the user or with the functions build_occ() (for STE and IS) and tte_build_occ() (for TTE).

Table 5 The structure of sampling occasions for a TTE analysis

First, the function build_occ() works for defining both STE and IS sampling occasions. It builds instantaneous or near-instantaneous sampling occasions at a user-defined frequency (Table 4). For users with time-lapse photography, the start and end times of each sampling occasion will be equal (i.e., instantaneous sampling occasions). When using time-lapse photography, the frequency of sampling occasions can be any multiple of the time-lapse frequency. For example, if time-lapse photos are taken every 15 min, sampling occasions can be every 15 min, 30 min, or 45 min, etc. For users with motion-sensor photography, the start and end times will define a short window of time (i.e., near-instantaneous sampling occasions, Table 4). Sampling windows should be short, to approximate an instantaneous sample. In the next step of the workflow, spaceNtime will look for photos occurring within that window and treat any species detections as instantaneous.

The functions tte_samp_per() and tte_build_occ() help build TTE sampling occasions. The function tte_samp_per() helps users define the length of sampling period k from the average viewshed area of the user’s cameras and the user-defined average movement speed. The function tte_build_occ() then uses that sampling period length and a user-defined number of sampling periods to build sampling occasions (Table 5). Because TTE sampling occasions are lengths of time, the columns start and end will never be equal.

Step 4. Build encounter history

The encounter histories for all three analyses are built from the photo data formatted in Step 1, the camera effort defined in Step 2, and the sampling occasions defined in Step 3. Moeller et al. (2018) show the mathematical derivation of STE, TTE, and IS and describe the components needed for each analysis. Here, we summarize the necessary components and describe how they translate to an encounter history. Encounter histories for STE and TTE are markedly different from encounter histories for mark-recapture or occupancy analyses. They require data transformation that may be unfamiliar to many users. Because of this, we introduce functions in spaceNtime to assist users with building an encounter history for each analysis. Additionally, the functions ste_build_eh(), tte_build_eh(), and ise_build_eh() check the structure and validity of input data to help users locate issues.

The STE encounter history has two main components: the calculated space to event on each sampling occasion and a censor value for that sampling occasion. The function ste_build_eh() calculates both of these and builds a data.frame with one row per sampling occasion, a column STE with the calculated space to event for each sampling occasion, and a column censor, with the censor value for each sampling occasion (Table 6). Space to event is calculated by randomly ordering all cameras on each sampling occasion and calculating the sum of their viewable areas, stopping at the first camera with a detection of the target species (Moeller et al. 2018). The censor value is the sum of all cameras’ viewable areas on each sampling occasion. ste_build_eh() interprets a lack of photos on a sampling occasion as species absence if the sampling effort data.frame has a record for that camera/sampling occasion combination and it defines the camera area as greater than 0. If there is no record for that camera/sampling occasion in the sampling effort data.frame, ste_build_eh() will add 0 area to the censor value and ignore that camera when calculating STE. This is how spaceNtime accounts for motion-sensor datasets. If no detections are found at any of the cameras on a given sampling occasion, the STE column is given an NA and the occasion is right-censored. Right-censored sampling occasions contain valuable information for the model; they represent occasions on which the space to first detection was greater than the total sampled area on that occasion (i.e., the censor value for that occasion). For right-censored occasions, the model integrates under the right tail of the exponential curve above the censor value. Because any given sampling occasion is more likely to have no detections than a detection, the STE encounter history will be largely made up of right-censored occasions (NAs). NAs can be contrasted with zeros in the encounter history; a zero indicates that the first detection of the species of interest was immediately in front of the first camera (i.e., no space was sampled before the first detection was found).

Table 6 The structure of an STE encounter history, as built by ste_build_eh()

For TTE, the encounter history has a record for each camera on each sampling occasion, a column TTE with the calculated time to event for that camera occasion, and a column censor with the censor value for that occasion (Table 7). Time to event is calculated for each camera on each sampling occasion as the number of sampling periods k = 1, …, K that elapsed before the species of interest was first detected, and accounting for area of the camera (Moeller et al. 2018). The censor value for a TTE analysis is the number of periods that elapse from the beginning to the end of the sampling occasion, also accounting for area of the camera. If no detections are made at a given camera on a given sampling occasion, TTE is assigned an NA and the occasion is right-censored. A right-censored event occurs when no animal is detected at a given camera on a given sampling occasion. Right-censoring indicates that the time to first encounter was greater than the length of the sampling occasion. As with STE, this is important information that helps guide the model, which integrates under the right tail of the exponential curve. In contrast to an NA, a zero in a TTE encounter history indicates that the target species was found instantly at the beginning of the sampling occasion (i.e., the time to detection was 0).

Table 7 The structure of a TTE encounter history, as built by tte_build_eh()

An IS encounter history contains a record for each camera on each sampling occasion, a column area with the camera area, and a column count containing the animal count (Table 8). For time-lapse photography, the IS encounter history is identical to the initial photo dataset defined in Step 1 (Table 2). For motion-sensor photography, however, the function ise_build_eh() can be used to build the encounter history. With motion-sensor photography, ise_build_eh() uses the sampling effort data.frame to differentiate between occasions in which cameras are functioning (and lack of detections should be interpreted as a count of 0 animals) and occasions in which cameras are non-functioning (and viewable area is 0). ise_build_eh() differentiates between the two in the same way described for ste_build_eh().

Table 8 The structure of an IS encounter history, as built by ise_build_eh()

Step 5. Estimate density or abundance

The final step of the workflow is to estimate abundance or density, using the appropriate encounter history from Step 4 and the study area size. The functions for estimating abundance are ste_estN_fn(), tte_estN_fn(), and ise_estN_fn(). Study area size must be defined in the same units as the camera area in the sampling effort data. For example, if camera viewsheds are measured in m2, the study area should also be defined in m2. If the study area is measured in km2, camera viewsheds should also be defined in km2. The models are formulated to produce estimates of average density per unit2, then scale that up to the defined study area. For example, if the camera area is measured in m2 and the study area size is set to 1m2, then the resulting estimate will represent average density per m2. If the study area size was then changed to 1e6m2, the resulting estimate would be interpreted as average density per km2. To get abundance in a 78km2 area, the user would define the study area size as 7.8e7 m2. The output from the _estN_fn() functions contains the estimate of abundance, its standard error, and the calculated lower and upper bounds of a 95% confidence interval (LCI and UCI, respectively) formed under the assumption that the sampling distribution of the estimator follows a log-normal distribution (Burnham et al. 1987, Table 9).

Table 9 Output of the ste_estN_fn() from the simulated data, showing the abundance estimate (N), its standard error (SE), and the calculated lower and upper bounds of a 95% confidence interval (LCI and UCI, respectively) formed under the assumption that the sampling distribution of the estimator follows a log-normal distribution (Burnham et al. 1987)

Case study

We illustrate the spaceNtime workflow for an STE analysis on simulated data. The data were simulated using a random walk of 100 animals in a 10,000 unit2 area with a constant step length. We recorded each animal’s location once every 10 steps, to simulate time-lapse photography. We simulated 100 cameras, each with an area of 4 unit2, and we recorded the number of animals that were detected in each camera at each time-lapse “photo”. We demonstrate the spaceNtime STE workflow in R, using the tidyverse suite of packages (Wickham et al. 2019). The simulated photo data are available in the supplementary materials.

figure a

The output shows the estimate of abundance (N) in the study area, its standard error (SE), and the calculated lower and upper bounds of the 95% log-normal based confidence interval (LCI and UCI, respectively). STE encounter histories are built by randomly arranging the cameras at each sampling occasion, so the last two lines may produce slightly different results each time. A user could potentially re-create the encounter history and rerun the analysis multiple times, taking the mean estimated abundance from across the runs to reduce the effect of randomness.

Conclusion

There are multiple areas currently in development to expand and advance the spaceNtime package. The first of these is a simulation and power analysis tool. This tool will allow the user to compare precision of each estimator under different (a) animal densities, (b) number of cameras, and (c) number of sampling occasions. The user would then be able to determine the ideal sampling effort required for their desired precision. Second, goodness-of-fit tests for STE and TTE are in development and will be added to the package once they are validated. Third, due to the randomness inherent in building the STE encounter history, estimates of abundance vary slightly when the model is run multiple times. We intend to build a tool for running the STE analysis multiple times over different possible encounter histories to allow users to quantify Monte Carlo error associated with the STE method. This method could take advantage of parallel processing to speed up calculation.

When estimating abundance from cameras, time-lapse photography can be an extremely valuable tool. Time-lapse photography best meets the assumption of instantaneous sampling occasions for STE and IS. Furthermore, time-lapse photography helps define sampling effort in a clear and unbiased way, which is useful for all three methods in the spaceNtime package, along with many other abundance estimation methods. Time-lapse photography provides a complete record of camera effort, and it is easy to identify times when the camera was not working as intended. Motion-sensor photography, on the other hand, causes the user to rely on the assumption that the camera is working as intended, and each non-detection is due to an animal’s absence rather than the camera’s malfunction. Furthermore, time-lapse photography eliminates the need to estimate the sensitivity of a camera’s motion sensor or account for all the different animal behaviors that can result in a motion sensor not being triggered when an animal is in the viewshed (e.g., sleeping in front of the camera). Time-lapse photography can produce large datasets. Technological aides like species-recognition software can be useful for shortening photo processing time. Software that does not produce group counts would not be appropriate for IS analysis, but would be perfectly suited for STE or TTE.

The STE, TTE, and IS methods estimate animal density at cameras and scale that up to the population of interest. Randomly or systematically placed cameras are key for collecting a representative sample of the population of interest. This study design allows the three methods to scale up easily because their precision and accuracy do not depend on a specific camera density. Therefore, populations that are spread out over large geographic areas can be sampled using the same number of cameras used for a smaller geographic population.

spaceNtime is a package designed for the user to implement every step of the STE, TTE, and IS analyses without requiring advanced knowledge of R or statistical modeling. The package contains functions to walk the user through every step of the analysis, from data formatting to estimating abundance. The encounter histories required for STE and TTE analyses are particularly unique, and we designed the package to assist users who may be unfamiliar with formatting their data in this way.