Skip to contents

Summarize species information from a data table

Usage

summarize_species(
  df,
  spp_col,
  cam_col = NULL,
  obstype_col = NULL,
  count_col = NULL,
  ncam = NULL,
  by_cam = FALSE,
  keep_all_camera_levels = FALSE,
  dfcam = NULL,
  cam_col_dfcam = ifelse(is.null(dfcam), NULL, cam_col),
  duration_col_dfcam = ifelse(is.null(dfcam), NULL, "sampling_length"),
  NA_count_placeholder = NA
)

Arguments

df

the observation dataframe to summarize

spp_col

Name of the species column

cam_col

Name of the column containing camera codes (optional if by_cam is FALSE)

obstype_col

Name of the observation type column (optional)

count_col

Name of the column containing species count (optional)

ncam

Number of cameras to take into account when computing the proportion of cameras the species was ween on. If NULL, defaults to the number of cameras present in the df (not needed if cam_col is not provided).

by_cam

Should the values be summarized by camera? If yes, there will be one row per cameras-species

keep_all_camera_levels

If there is a camera on which no species were seen, should it be present in the output? Not needed if cam_col is not provided.

dfcam

Dataframe containing information about the cameras sampling length. If it is provided, then cam_col_dfcam and duration_col_dfcam must be in its column names.

cam_col_dfcam

Column name containing cameras names in dfcam

duration_col_dfcam

Column name containing sampling duration in dfcam

NA_count_placeholder

Value with which to replace NAs present in the column containing counts. Defaults to NA (i.e. values are not replaced).

Value

A table summarizing species information with the following columns:

  • Species (named like spp_col): species identity (same as the spp_col input column)

  • Observation type (present only if obstype_col is not NULL and named like obstype_col): observation type (same as the obstype_col input column)

  • sightings: number of rows where the species was photographed.

  • individuals: count of individuals observed on all pictures (using the input count_col column). If count_col is NULL, it contains the same values as sightings. If there are NAs in the input count_col, they will propagate in individuals (unless a value is specified in NA_count_placeholder).

If by_cam is FALSE, the following rows are also present:

  • n_cameras (present only if cam_col is not NULL) : the number of cameras the species was seen on.

  • prop_cam (present only if cam_col is not NULL): the proportion of cameras the species was seen on. If ncam is provided, then it uses ncam as the total number of cameras.

If by_cam is TRUE, the following rows are also present:

  • sightings_prop: the proportion of sightings represented by the species at the camera.

  • individuals_prop: the proportion of individuans represented by the species at the camera.

If by_cam is TRUE and dfcam is provided, the following rows are also present:

  • 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 duration (named like duration_col_dfcam): sampling duration for each camera

Finally, if keep_all_camera_levels is TRUE, a final column named empty is added to indicate which cameras were empty (have no data).

Examples

df <- data.frame(species = c("zebra", "cat", "cat", "cow", NA, NA),
                 type = c("animal", "animal", "animal", "animal", "human", "blank"),
                 camera = c("C1", "C1", "C2", "C3", "C3", "C4"),
                 count = c(1, 1, 3, 50, 1, NA))
# Summarize species across all cameras
summarize_species(df, 
                  spp_col = "species", cam_col = "camera",
                  obstype_col = "type",
                  count_col = "count",
                  NA_count_placeholder = 1)
#>   species   type sightings individuals n_cameras prop_cam
#> 1     cat animal         2           4         2     0.50
#> 2     cow animal         1          50         1     0.25
#> 3   zebra animal         1           1         1     0.25
#> 4    <NA>  blank         1           1         1     0.25
#> 5    <NA>  human         1           1         1     0.25
# Summarize per species and cameras
summarize_species(df, 
                  spp_col = "species", cam_col = "camera",
                  obstype_col = "type",
                  count_col = "count",
                  by_cam = TRUE,
                  NA_count_placeholder = 1)
#>   species   type camera sightings individuals sightings_prop individuals_prop
#> 1     cat animal     C1         1           1            0.5       0.50000000
#> 2     cat animal     C2         1           3            1.0       1.00000000
#> 3     cow animal     C3         1          50            0.5       0.98039216
#> 4   zebra animal     C1         1           1            0.5       0.50000000
#> 5    <NA>  blank     C4         1           1            1.0       1.00000000
#> 6    <NA>  human     C3         1           1            0.5       0.01960784
# Add camera sampling length to get the RAI
cam_sampling <- data.frame(camera = c("C1", "C2", "C3", "C4"),
                           sampling_duration = c(100, 1, 10, 10))
summarize_species(df, 
                  spp_col = "species", cam_col = "camera",
                  obstype_col = "type",
                  count_col = "count",
                  by_cam = TRUE,
                  dfcam = cam_sampling,
                  duration_col_dfcam = "sampling_duration",
                  NA_count_placeholder = 1)
#>   species   type camera sightings individuals sightings_prop individuals_prop
#> 1     cat animal     C1         1           1            0.5       0.50000000
#> 2     cat animal     C2         1           3            1.0       1.00000000
#> 3     cow animal     C3         1          50            0.5       0.98039216
#> 4   zebra animal     C1         1           1            0.5       0.50000000
#> 5    <NA>  blank     C4         1           1            1.0       1.00000000
#> 6    <NA>  human     C3         1           1            0.5       0.01960784
#>   sightings_RAI individuals_RAI sampling_duration
#> 1          0.01            0.01               100
#> 2          1.00            3.00                 1
#> 3          0.10            5.00                10
#> 4          0.01            0.01               100
#> 5          0.10            0.10                10
#> 6          0.10            0.10                10