get_spec_rt: Calculate specific rates

Description Usage Arguments Details Value References See Also Examples

View source: R/get_spec_rt.R

Description

Calculate specific rates given a vector containing the frequencies of events and a vector containing the sizes of the defined populations.

Usage

1
2
3
4
5
6
7
8
9
get_spec_rt(
  counts,
  popn,
  scale = NULL,
  power = NULL,
  output_status = FALSE,
  dist = NULL,
  interval = NULL
)

Arguments

counts

A numeric vector containing the frequency of events.

popn

A numeric vector containing the size of each defined population.

scale, power

Provide either scale, a positive integer, to specify the scale, or power, a non-negative integer, to specify the power of 10 to use when expressing the result. If neither are supplied, scale = 1 will be applied.

output_status

If FALSE (default) the calculated rates are returned as a numeric vector. If TRUE a data frame containing both the rates and the validity of the corresponding elements in the input vectors is returned.

dist

A string to indicate the type of probability distribution for the confidence interval to follow. Can be one of the following: "normal", "log normal" or "poisson". This parameter is case insensitive.

interval

A scalar, between 0 and 1, indicating the width of the confidence interval. For example, for a 95% confidence interval, use interval = 0.95.

Details

This low-level function assumes that counts and sizes of respective subpopulations are provided in the same order. It can also be used to calculate a crude rate if counts and popn are scalars and represent the sum of all counts and the size of the entire population respectively.

To construct confidence intervals for the rate estimates, arguments must be explicitly supplied to both dist and interval.

Value

If output_status = FALSE and neither dist or interval is supplied, a numeric vector is returned.

Otherwise, a data frame is returned with a column for rate and up to 4 additional columns:

The status column of the output can be interpreted as follows:

References

The STDRATE Procedure

See Also

get_ci_norm(), get_ci_lnorm(), get_ci_pois()

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
## Not run: 
# using vectors
counts <- c(100, 200, 300, 400, 500)
popn <- c(1000, 5000, 10000, 50000, 100000)

get_spec_rt(counts, popn)
get_spec_rt(counts, popn, scale = 1000)
get_spec_rt(counts, popn, power = 3)

# get output status
get_spec_rt(counts, popn, output_status = TRUE)

# construct confidence intervals for rate estimates
get_spec_rt(counts, popn, dist = "normal", interval = 0.95)

# using a data frame
df <- data.frame(counts, popn)

get_spec_rt(df$counts, df$popn, scale = 100000)
get_spec_rt(df$counts, df$popn, power = 5)

# using dplyr to create a column
df <- df %>%
  dplyr::mutate(spec_rate = get_spec_rt(counts, popn, scale = 1000))

## End(Not run)

bcgov/bcEpiRate documentation built on Feb. 24, 2022, 4:05 p.m.