get_ds_rt: Perform direct standardization

Description Usage Arguments Details Value References See Also Examples

View source: R/get_ds_rt.R

Description

Compute a directly standardized rate given the counts of events, the size of each defined population and the size of each group of the standard population.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
get_ds_rt(
  counts,
  popn,
  std_popn,
  scale = NULL,
  power = NULL,
  output_type = "rate",
  clean_strata = "none",
  dist = NULL,
  interval = NULL,
  method = NULL
)

Arguments

counts

A numeric vector containing the frequency of events.

popn

A numeric vector containing the size of each defined population.

std_popn

A numeric vector containing the size of each group of the standard 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 argument is supplied, scale = 1 will be applied.

output_type

If "rate" (default), the directly standardized rate is returned. If "counts", the expected number of events for each stratum is returned.

clean_strata
  • "none" returns a directly standardized rate if and only if the evaluated specific rates are free of NA and std_popn is free of NA and 0.

  • "exclude" removes strata with specific rates of NA or std_popn values of NA or 0 from the calculation of the directly standardized rate. NA is returned if all strata are excluded from the calculation.

  • "zero" sets specific rates evaluated to NA as 0. In addition, when std_popn contains 0, the respective stratum is excluded from the calculation of the directly standardized rate. However, when std_popn contains NA, the directly standardized rate evaluates to NA. When output_type = "counts", the expected counts are calculated after specific rates of NA have been set to 0. Confidence intervals cannot be constructed when this argument is used.

dist

A string to indicate the type of probability distribution for the confidence interval to follow. Can be either "normal", "log normal" or "gamma". 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.

method

A string specifying the method to use when using the gamma distribution. Use "tcz06" (default) for the method proposed by Tiwari, Clegg, and Zou (2006) and "ff97" for the more conservative method proposed by Fay and Feuer (1997). This parameter must be left empty when calculating confidence intervals using other distributions. See SAS Help Center: Direct Standardization for more details.

Details

This low-level function assumes that the counts in each stratum, the size of each stratum in the observed population and the size of each stratum in the standard population are provided in the same order.

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

Value

If output_type = "rate" (default) and neither dist nor interval is supplied, the directly standardized rate is returned as a numeric vector.

If output_type = "rate" and both dist and interval are provided, then a data frame is returned with the columns dsr, lower, upper and interval.

If output_type = "counts", the expected counts are returned as a numeric vector.

References

The STDRATE Procedure

See Also

get_ci_norm(), get_ci_lnorm(), get_ci_gamma()

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
## Not run: 
# using vectors
counts <- c(10, 7, 6, 4, 2)
popn <- c(300, 595, 492, 43, 422)
std_popn <- c(807, 355, 379, 244, 781)

get_ds_rt(counts, popn, std_popn)
get_ds_rt(counts, popn, std_popn, scale = 1000)
get_ds_rt(counts, popn, std_popn, power = 3)
get_ds_rt(counts, popn, std_popn, output_type = "counts")
get_ds_rt(counts, popn, std_popn, clean_strata = "exclude")
get_ds_rt(
  counts, popn, std_popn,
  scale = 1000,
  dist = "normal", interval = 0.95
)
get_ds_rt(
  counts, popn, std_popn,
  scale = 100000,
  dist = "gamma", interval = 0.9, method = "ff97"
)

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

get_ds_rt(df$counts, df$popn, df$std_popn, scale = 1000)
get_ds_rt(df$counts, df$popn, df$std_popn, power = 3)

## End(Not run)

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