calc_det_rate: Calculate detection rate of pathogens

Description Usage Arguments Value Examples

View source: R/TURN.R

Description

Calculate the percentage of total tests that are of a specific pathogen using the output from the calc_path_TURN function. It is calculated as Y for the pathogen divided by total Y. Since the Ys are calculate with the same denominator this is equivelant to tests for that pathogen/total tests. A three week moving average is applied to the numerator and denominator prior to calculation.

Usage

1
2
3
4
5
6
calc_det_rate(
  df,
  group_vars = vars(TargetName),
  return_week = TRUE,
  window = 3
)

Arguments

df

dataframe with at least columns of "InstrumentVersion", "epi_n_days", "Y", "path_Y", "epidate", and any other columns included in group_vars.

group_vars

names of columns to group by, wrapped in vars(). Must included TargetName and can also include other columns to group by (e.g. a column defining regions).

return_week

logical whether output should include epiweek and epiyear columns

window

width of the window over which to apply rolling window sum to calculate detection rate.

Value

data frame that includes a column 'det_rate', which is the detection rate (in percent), and TUR_mws which is the moving window sum of TUR

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
###############################################
############## Generating data ################
national_list <- calc_TURN(TUR_dat, return_means = TRUE)
means <- national_list$means
# national TURN
TURN_national <- national_list$df

# regional (state) TURN
site_info <- get_site_info(rp_raw)
TURN_region <- calc_TURN(TUR_dat,
                         group_vars = vars(InstrumentVersion, Region),
                         site_info = site_info,
                         means = means)

# calculate TURN for each pathogen -- national
path_turn_national <- calc_path_TURN(df = path_dat,
               TURN_df = TURN_national,
               means = means)

# calculate TURN for each pathogen -- regional
path_turn_region <- calc_path_TURN(df = path_dat,
               TURN_df = TURN_region,
               means = means,
               group_vars = vars(InstrumentVersion, Region),
               site_info = site_info)

###############################################
############## detection rate ################

# calculate detection rate--national
calc_det_rate(path_turn_national)
# calculate detection rate--regional
calc_det_rate(path_turn_region, group_vars = vars(TargetName, Region))

MartinHoldrege/turnr documentation built on May 16, 2020, 10:39 a.m.