Statistical functions
Source:vignettes/sd-rse-calculation_overview.Rmd
sd-rse-calculation_overview.Rmd
prop_sd
Background
This function calculates the standard deviation of a proportion. In
epidemiology, we often need to calculate standard deviations of
proportions to provide further context for interpretation of other
statistical measures such as rates. The default sd() function in R uses
a denominator of n (sample size)-1
, but we wanted a
function that would use a denominator of n. Thus, the formula to
calculate the standard deviation (sd) of a proportion (prop) using the
prop_sd
function is
Basic usage
The function inputs include the numerator followed by the denominator of the proportion. The function checks to ensure that the numerator and denominator are numeric values prior to execution of the function.
num <- 50
denom <- 2000
prop_sd(num = num, denom = denom)
#> [1] 0.00349106
prop_rse
This function calculates the relative standard error (RSE) for sample and survey data. The RSE characterizes the reliability of a measure represented as a percentage. A low RSE would indicate a more stable and precise estimate while a high RSE suggests that the estimate is unreliable.
Basic usage: method = "sample"
For the sample method, the function inputs include the
prop_sd
, the sample size (n), and the method (“sample” in
this case) to determine the appropriate calculation for the data. The
sample method can typically be used on surveillance data sets common in
epidemiology. The formula for the prop_rse
function sample
method is
sample_sd <- 25
sample_n <- 1000
sample_method <- "sample"
prop_rse(prop_sd = sample_sd, n = sample_n, method = sample_method)
#> [1] 0.7905694
Basic usage: method = "survey"
For the survey method, the function inputs include the
prop_sd
, the sample size (n), and the method (“survey” in
this case) to determine the appropriate calculation for the data. The
survey method can be used on survey data sets in epidemiology. The first
step in calculating the relative standard error using the survey method
is to calculate the standard error (se) using the following formula,
which includes the standard deviation of the proportion (sd) and the
sample size (n).
Then, the standard error (se) and sample size (n) are used to calculate the relative standard error (rse) using the following formula.
survey_sd <- 25
survey_n <- 1000
survey_method <- "survey"
prop_rse(survey_sd, survey_n, survey_method)
#> [1] 0.07905694