Skip to contents

Flag potentially spurious observations

Usage

epict_flag_spurious_obs(
  obs,
  max_t_rel_uncensored = 60,
  max_onset_t_rel_uncensored = 15,
  flag = TRUE,
  drop = TRUE,
  return_spurious = FALSE
)

Arguments

obs

A data.frame with the following variables:

  • t_rel_uncensored: Time of test relative to the first uncensored Ct value for that id.

  • onset_t_rel_uncensored: Time of onset relative to the first uncensored Ct value for that id. (optional). NA if unavailable/asymptomatic.

max_t_rel_uncensored

Numeric defaults to 60 days. Flags the maximum absolute relative time that is considered plausible for tests to be spaced by per ID.

max_onset_t_rel_uncensored

Numeric defaults to 15 days. Flags the maximum absolute relative time that is considered plausible for symptom onset from the first uncensored test per ID.

flag

Logical, defaults to TRUE. Should spurious tests be flagged

drop

Logical, defaults to TRUE. Should spurious tests and onsets be dropped (set to NA for onsets and filtered out for tests).

return_spurious

Logical, defaults to FALSE. Rather than returning observations should observations flagged as spurious be returned.

Value

A data.table of observations

Author

Sam Abbott

Examples

obs <- data.frame(t_rel_uncensored = c(0, 2, 10, 60, 100, 30))

# Run with defaults
fil_obs <- epict_flag_spurious_obs(obs)
#> The following tests have been identified as having spurious data
#>    t_rel_uncensored
#> 1:              100
#> Spurious tests have been dropped
fil_obs
#>    t_rel_uncensored
#> 1:                0
#> 2:                2
#> 3:               10
#> 4:               60
#> 5:               30
epict_flag_spurious_obs(fil_obs)
#>    t_rel_uncensored
#> 1:                0
#> 2:                2
#> 3:               10
#> 4:               60
#> 5:               30

# Add onsets and repeat
obs$onset_t_rel_uncensored <- c(0, 15, 2, NA, 40, 5)
fil_obs <- epict_flag_spurious_obs(obs)
#> The following tests have been identified as having spurious data
#>    t_rel_uncensored onset_t_rel_uncensored
#> 1:              100                     40
#> 2:                2                     15
#> Spurious tests have been dropped
fil_obs
#>    t_rel_uncensored onset_t_rel_uncensored
#> 1:                0                      0
#> 2:                2                     NA
#> 3:               10                      2
#> 4:               60                     NA
#> 5:               30                      5
epict_flag_spurious_obs(fil_obs)
#>    t_rel_uncensored onset_t_rel_uncensored
#> 1:                0                      0
#> 2:                2                     NA
#> 3:               10                      2
#> 4:               60                     NA
#> 5:               30                      5

# Return spurious observations
epict_flag_spurious_obs(obs, return_spurious = TRUE)
#>    t_rel_uncensored onset_t_rel_uncensored
#> 1:              100                     40
#> 2:                2                     15

# Flag spurious results but don't drop
epict_flag_spurious_obs(obs, drop = FALSE)
#> The following tests have been identified as having spurious data
#>    t_rel_uncensored onset_t_rel_uncensored
#> 1:              100                     40
#> 2:                2                     15
#>    t_rel_uncensored onset_t_rel_uncensored
#> 1:                0                      0
#> 2:                2                     15
#> 3:               10                      2
#> 4:               60                     NA
#> 5:              100                     40
#> 6:               30                      5

# Siltently drop
epict_flag_spurious_obs(obs, flag = FALSE)
#> Spurious tests have been dropped
#>    t_rel_uncensored onset_t_rel_uncensored
#> 1:                0                      0
#> 2:                2                     NA
#> 3:               10                      2
#> 4:               60                     NA
#> 5:               30                      5