Skip to contents

This vignette demonstrates how this package can be used to summarize camera trap data.

Import and prepare data

data(recordTableSample, package = "camtrapR")
data(camtraps, package = "camtrapR")
recordTableSample$DateTimeOriginal <- as.POSIXct(recordTableSample$DateTimeOriginal)
recordTableSample$Date <- as.Date(recordTableSample$Date)
recordTableSample$Time <- chron::times(recordTableSample$Time)

camtraps$Setup_date <- as.Date(camtraps$Setup_date, format = "%d/%m/%Y")
camtraps$Retrieval_date <- as.Date(camtraps$Retrieval_date, format = "%d/%m/%Y")

Camera information

We can summarize the camera sampling with the function summarize_cameras. The start and end dates are taken from the data and the sampling length is computed using the cameraOperation matrix from the camtrapR package.

If we provide only the observation dataframe, sampling will be computed from first and last picture.

camsum <- summarize_cameras(recordTableSample,
                            cam_col = "Station",
                            date_col = "Date",
                            time_col = "Time")
knitr::kable(camsum)
Station pictures sampling_length setup retrieval setup_origin retrieval_origin
StationA 6 27.5028 2009-04-10 05:07:00 2009-05-07 17:11:00 picture picture
StationB 12 39.0833 2009-04-05 00:11:00 2009-05-14 02:11:00 picture picture
StationC 21 35.9805 2009-04-06 03:00:00 2009-05-12 02:32:00 picture picture

The summary table has the following columns:

  • The first column is named as the cameras ID column (here Station) and contains cameras ID.
  • pictures is the number of pictures caught on each camera.
  • sampling_length is the length of the sampling period in days (computed with the cameraOperation function from the camtrapR package).
  • setup contains the start of the sampling for each camera.
  • retrieval contains the end of the sampling for each camera.
  • setup_origin containing the method used to determine the start of the sampling (possible values are picture or setup).
  • retrieval_origin containing the method used to determine the end of the sampling (picture or setup).

If we add the species column with the spp_col argument, a column species is added to the summary (it contains the number of species caught on each camera).

camsum <- summarize_cameras(recordTableSample,
                            cam_col = "Station",
                            date_col = "Date",
                            time_col = "Time",
                            spp_col = "Species")
knitr::kable(camsum)
Station pictures species sampling_length setup retrieval setup_origin retrieval_origin
StationA 6 2 27.5028 2009-04-10 05:07:00 2009-05-07 17:11:00 picture picture
StationB 12 3 39.0833 2009-04-05 00:11:00 2009-05-14 02:11:00 picture picture
StationC 21 4 35.9805 2009-04-06 03:00:00 2009-05-12 02:32:00 picture picture

If we provide the cameras dataframe, whenever possible the sampling information will be obtained from setup and retrieval columns.

camsum <- summarize_cameras(recordTableSample,
                            cam_col = "Station",
                            date_col = "Date",
                            time_col = "Time",
                            spp_col = "Species",
                            dfcam = camtraps, 
                            cam_col_dfcam = "Station", 
                            setup_col = "Setup_date",
                            retrieval_col = "Retrieval_date")
knitr::kable(camsum)
Station pictures species sampling_length setup retrieval setup_origin retrieval_origin
StationA 6 2 42 2009-04-02 2009-05-14 metadata metadata
StationB 12 3 43 2009-04-03 2009-05-16 metadata metadata
StationC 21 4 43 2009-04-04 2009-05-17 metadata metadata

If some information is missing from the camera dataframe, then the information from the observations will be used.

cam_missing <- camtraps
cam_missing$Retrieval_date[cam_missing$Station == "StationA"] <- NA

knitr::kable(cam_missing |> 
               select(Station, Setup_date, Retrieval_date))
Station Setup_date Retrieval_date
StationA 2009-04-02 NA
StationB 2009-04-03 2009-05-16
StationC 2009-04-04 2009-05-17
camsum <- summarize_cameras(recordTableSample,
                            cam_col = "Station",
                            date_col = "Date",
                            time_col = "Time",
                            spp_col = "Species",
                            dfcam = cam_missing, 
                            cam_col_dfcam = "Station", 
                            setup_col = "Setup_date",
                            retrieval_col = "Retrieval_date")
knitr::kable(camsum)
Station pictures species sampling_length setup retrieval setup_origin retrieval_origin
StationA 6 2 35.716 2009-04-02 2009-05-07 17:11:00 metadata picture
StationB 12 3 43.000 2009-04-03 2009-05-16 00:00:00 metadata metadata
StationC 21 4 43.000 2009-04-04 2009-05-17 00:00:00 metadata metadata

Species information

We can also summarize the species sightings with the function summarize_species.

sppsum <- summarize_species(recordTableSample,
                            spp_col = "Species", 
                            cam_col = "Station")
knitr::kable(sppsum)
Species sightings individuals n_cameras prop_cam
EGY 6 6 1 0.3333333
MNE 2 2 1 0.3333333
PBE 18 18 3 1.0000000
TRA 8 8 1 0.3333333
VTA 5 5 3 1.0000000

The summary table has the following columns:

  • the first column is named as the species column (here Species) and contains species name
  • sightings is the number of sightings of the species (corresponding to row count in the data)
  • individuals takes into account the information from the counting column (if provided). Else, it is the same as sightings.
  • n_cameras gives the number of cameras the species was observed on.
  • prop_cam gives the proportion of cameras the species was observed on.

We can also include the count information:

with_count <- recordTableSample |> 
  mutate(count = 3)
sppsum <- summarize_species(with_count,
                            spp_col = "Species", 
                            cam_col = "Station", 
                            count_col = "count")
knitr::kable(sppsum)
Species sightings individuals n_cameras prop_cam
EGY 6 18 1 0.3333333
MNE 2 6 1 0.3333333
PBE 18 54 3 1.0000000
TRA 8 24 1 0.3333333
VTA 5 15 3 1.0000000

If any of the count data is NA, it is possible to provide a value to replace it:

with_count_NA <- with_count |> 
  mutate(count = ifelse(Species == "PBE", NA, count))

sppsum <- summarize_species(with_count_NA,
                            spp_col = "Species", 
                            cam_col = "Station", 
                            count_col = "count",
                            NA_count_placeholder = 1)

knitr::kable(sppsum)
Species sightings individuals n_cameras prop_cam
EGY 6 18 1 0.3333333
MNE 2 6 1 0.3333333
PBE 18 18 3 1.0000000
TRA 8 24 1 0.3333333
VTA 5 15 3 1.0000000

If obstype_col is included, the final table will have one more column describing type and the values will be summarized by species_col and obstype_col.

with_obstype <- recordTableSample |> 
  mutate(type = "animal")
with_obstype <- rbind(with_obstype,
                      c(rep(NA, 11), "human"))
with_obstype <- rbind(with_obstype,
                      c(rep(NA, 11), "fire"))

sppsum <- summarize_species(with_obstype,
                            spp_col = "Species", 
                            cam_col = "Station", 
                            obstype_col = "type")
knitr::kable(sppsum)
Species type sightings individuals n_cameras prop_cam
EGY animal 6 6 1 0.25
MNE animal 2 2 1 0.25
PBE animal 18 18 3 0.75
TRA animal 8 8 1 0.25
VTA animal 5 5 3 0.75
NA fire 1 1 1 0.25
NA human 1 1 1 0.25

Summarize per species and cameras

It is also possible to summarize the information per species and camera using the argument by_cam in the summarize_species function:

bycam <- summarize_species(recordTableSample,
                           spp_col = "Species", 
                           cam_col = "Station",
                           by_cam = TRUE)
knitr::kable(bycam)
Species Station sightings individuals sightings_prop individuals_prop
EGY StationC 6 6 0.2857143 0.2857143
MNE StationB 2 2 0.1666667 0.1666667
PBE StationA 4 4 0.6666667 0.6666667
PBE StationB 8 8 0.6666667 0.6666667
PBE StationC 6 6 0.2857143 0.2857143
TRA StationC 8 8 0.3809524 0.3809524
VTA StationA 2 2 0.3333333 0.3333333
VTA StationB 2 2 0.1666667 0.1666667
VTA StationC 1 1 0.0476190 0.0476190

Then, we obtain a table with one row per species and camera. The four first columns are the same as without the by_cam option, but the following rows differ:

  • sightings_prop is the proportion of sightings of a given species at a given camera

  • individuals_prop is the proportion of individuals of a given species at a given camera

When providing additional information on cameras sampling (typically obtained with summarize_cameras), the relative abundance index can also be computed.

camsum <- summarize_cameras(recordTableSample,
                            cam_col = "Station",
                            date_col = "Date",
                            time_col = "Time")
bycam_RAI <- summarize_species(recordTableSample,
                           spp_col = "Species", 
                           cam_col = "Station",
                           dfcam = camsum,
                           by_cam = TRUE)
knitr::kable(bycam_RAI)
Species Station sightings individuals sightings_prop individuals_prop sightings_RAI individuals_RAI sampling_length
EGY StationC 6 6 0.2857143 0.2857143 0.1667570 0.1667570 35.9805
MNE StationB 2 2 0.1666667 0.1666667 0.0511728 0.0511728 39.0833
PBE StationA 4 4 0.6666667 0.6666667 0.1454397 0.1454397 27.5028
PBE StationB 8 8 0.6666667 0.6666667 0.2046910 0.2046910 39.0833
PBE StationC 6 6 0.2857143 0.2857143 0.1667570 0.1667570 35.9805
TRA StationC 8 8 0.3809524 0.3809524 0.2223427 0.2223427 35.9805
VTA StationA 2 2 0.3333333 0.3333333 0.0727199 0.0727199 27.5028
VTA StationB 2 2 0.1666667 0.1666667 0.0511728 0.0511728 39.0833
VTA StationC 1 1 0.0476190 0.0476190 0.0277928 0.0277928 35.9805

When dfcam is provided, there are three additional columns:

  • sightings_RAI: relative abundance index for species’ sightings at each camera. It is computed as the number of sightings over the sampling duration (it represents the number of sightings per time unit).

  • individuals_RAI: the same as sightings_RAI, but computed as the number of individuals over the sampling duration.

  • sampling_length containing the sampling duration for each camera