comp_freq computes frequencies (typically
as rounded integers) given 3 basic probabilities –
for a population of
It returns a list of 11 frequencies
as its output.
The condition's prevalence
The decision's sensitivity
The decision's specificity value
The number of individuals in the population.
Boolean value that determines whether frequencies are
rounded to the nearest integer. Default:
In addition to
spec are necessary arguments.
If only their complements
are known, use the wrapper function
which also accepts
fart as inputs
(but requires that the entire set of provided probabilities is
sufficient and consistent).
to obtain the 3 essential probabilities.
comp_freq is the frequency counterpart to the
comp_freq and its wrapper function
round frequencies to nearest integers to avoid decimal values in
round = TRUE by default).
When frequencies are rounded, probabilities computed from
freq may differ from exact probabilities.
Using the option
round = FALSE turns off rounding.
Key relationships between probabilities and frequencies:
Three perspectives on a population:
A population of
N individuals can be split into 2 subsets of frequencies
in 3 different ways:
N = cond_true + cond_false
cond_true depends on the prevalence
cond_false depends on the prevalence's complement
1 - prev.
N = dec_pos + dec_neg
dec_pos depends on the proportion of positive decisions
dec_neg depends on the proportion of negative decisions
1 - ppod.
by accuracy (i.e., correspondence of decision to condition):
N = dec_cor + dec_err
Each perspective combines 2 pairs of the 4 essential probabilities (hi, mi, fa, cr).
When providing probabilities, the population size
N is a free parameter (independent of the
N is unknown (
NA), a suitable minimum value can be computed by
Defining probabilities in terms of frequencies:
Probabilities are – determine, describe, or are defined as – the relationships between frequencies. Thus, they can be computed as ratios between frequencies:
prev = cond_true/N = (hi + mi) / (hi + mi + fa + cr)
sens = hi/cond_true = hi / (hi + mi) = (1 - mirt)
mirt = mi/cond_true = mi / (hi + mi) = (1 - sens)
spec = cr/cond_false = cr / (fa + cr) = (1 - fart)
false alarm rate
fart = fa/cond_false = fa / (fa + cr) = (1 - spec)
proportion of positive decisions
ppod = dec_pos/N = (hi + fa) / (hi + mi + fa + cr)
positive predictive value
PPV = hi/dec_pos = hi / (hi + fa) = (1 - FDR)
negative predictive value
NPV = cr/dec_neg = cr / (mi + cr) = (1 - FOR)
false detection rate
FDR = fa/dec_pos = fa / (hi + fa) = (1 - PPV)
false omission rate
FOR = mi/dec_neg = mi / (mi + cr) = (1 - NPV)
acc = dec_cor/N = (hi + cr) / (hi + mi + fa + cr)
Note: When frequencies are rounded (by
round = TRUE in
probabilities computed from
freq may differ from exact probabilities.
Functions translating between representational formats:
(see documentation of
comp_prob_prob for details).
freq containing 11 frequency values.
comp_freq_prob corresponding wrapper function;
num contains basic numeric variables;
init_num initializes basic numeric variables;
freq contains current frequency information;
prob contains current probability information;
comp_prob computes current probability information;
comp_complement computes a probability's complement;
comp_comp_pair computes pairs of complements;
comp_complete_prob_set completes valid sets of probabilities;
comp_min_N computes a suitable population size
N (if missing).
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
comp_freq() # => ok, using current defaults length(comp_freq()) # => 11 # Rounding effects: comp_freq(prev = .5, sens = .5, spec = .5, N = 1) # => yields fa = 1 (see ?round for reason) comp_freq(prev = .1, sens = .9, spec = .8, N = 10) # => 1 hit (TP, rounded) comp_freq(prev = .1, sens = .9, spec = .8, N = 10, round = FALSE) # => hi = .9 comp_freq(prev = 1/3, sens = 6/7, spec = 2/3, N = 1, round = FALSE) # => hi = 0.2857143 # Extreme cases: comp_freq(prev = 1, sens = 1, spec = 1, 100) # => ok, N hits (TP) comp_freq(prev = 1, sens = 1, spec = 0, 100) # => ok, N hits comp_freq(prev = 1, sens = 0, spec = 1, 100) # => ok, N misses (FN) comp_freq(prev = 1, sens = 0, spec = 0, 100) # => ok, N misses comp_freq(prev = 0, sens = 1, spec = 1, 100) # => ok, N correct rejections (TN) comp_freq(prev = 0, sens = 1, spec = 0, 100) # => ok, N false alarms (FP) # Watch out for: comp_freq(prev = 1, sens = 1, spec = 1, N = NA) # => ok, but warning that N = 1 was computed comp_freq(prev = 1, sens = 1, spec = 1, N = 0) # => ok, but all 0 + warning (extreme case: N hits) comp_freq(prev = .5, sens = .5, spec = .5, N = 10, round = TRUE) # => ok, rounded (see mi and fa) comp_freq(prev = .5, sens = .5, spec = .5, N = 10, round = FALSE) # => ok, not rounded # Ways to fail: comp_freq(prev = NA, sens = 1, spec = 1, 100) # => NAs + warning (prev NA) comp_freq(prev = 1, sens = NA, spec = 1, 100) # => NAs + warning (sens NA) comp_freq(prev = 1, sens = 1, spec = NA, 100) # => NAs + warning (spec NA) comp_freq(prev = 8, sens = 1, spec = 1, 100) # => NAs + warning (prev beyond range) comp_freq(prev = 1, sens = 8, spec = 1, 100) # => NAs + warning (sens beyond range)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.