Skip to contents

This function replaces spatial coordinate values with NA if the confidence values are below a specified threshold. The confidence column is also filtered.

Usage

filter_na_confidence(data, threshold = 0.6)

Arguments

data

An aniframe containing a confidence column and spatial columns as defined in the metadata's variables_where.

threshold

A numeric value specifying the minimum confidence level to retain data. Must be a single value between 0 and 1. Default is 0.6.

Value

An aniframe with the same structure as the input, but where spatial and confidence values are replaced with NA if the confidence is below the threshold.

Examples

# 2D example
data <- aniframe::aniframe(
  time = 1:5,
  x = 1:5,
  y = 6:10,
  confidence = c(0.5, 0.7, 0.4, 0.8, 0.9)
)

filter_na_confidence(data, threshold = 0.6)
#> Warning: Unknown or uninitialised column: `individual`.
#> # Individuals:
#> # Keypoints:   centroid
#>   keypoint  time     x     y confidence
#>   <fct>    <int> <dbl> <dbl>      <dbl>
#> 1 centroid     1    NA    NA       NA  
#> 2 centroid     2     2     7        0.7
#> 3 centroid     3    NA    NA       NA  
#> 4 centroid     4     4     9        0.8
#> 5 centroid     5     5    10        0.9

# With z column (3D)
data_3d <- aniframe::aniframe(
  time = 1:5,
  x = 1:5,
  y = 6:10,
  z = 11:15,
  confidence = c(0.5, 0.7, 0.4, 0.8, 0.9),
  variables_where = c("x", "y", "z")
)

filter_na_confidence(data_3d, threshold = 0.6)
#> Warning: Unknown or uninitialised column: `individual`.
#> # Individuals:
#> # Keypoints:   centroid
#>   keypoint  time     x     y     z confidence
#>   <fct>    <int> <dbl> <dbl> <dbl>      <dbl>
#> 1 centroid     1    NA    NA    NA       NA  
#> 2 centroid     2     2     7    12        0.7
#> 3 centroid     3    NA    NA    NA       NA  
#> 4 centroid     4     4     9    14        0.8
#> 5 centroid     5     5    10    15        0.9