comp_freq {riskyr} | R Documentation |
Compute frequencies from (3 essential) probabilities.
Description
comp_freq
computes frequencies (typically
as rounded integers) given 3 basic probabilities –
prev
, sens
, and spec
–
for a population of N
individuals.
It returns a list of 11 key frequencies freq
as its output.
Usage
comp_freq(
prev = num$prev,
sens = num$sens,
spec = num$spec,
N = num$N,
round = TRUE,
sample = FALSE
)
Arguments
prev |
The condition's prevalence |
sens |
The decision's sensitivity |
spec |
The decision's specificity value |
N |
The number of individuals in the population.
If |
round |
Boolean value that determines whether frequency values
are rounded to the nearest integer.
Default: Note: Removed |
sample |
Boolean value that determines whether frequency values
are sampled from Note: Sampling uses |
Details
In addition to prev
, both
sens
and spec
are necessary arguments.
If only their complements mirt
or fart
are known, use the wrapper function comp_freq_prob
which also accepts mirt
and fart
as inputs
(but requires that the entire set of provided probabilities is
sufficient and consistent).
Alternatively, use comp_complement
,
comp_comp_pair
, or comp_complete_prob_set
to obtain the 3 essential probabilities.
comp_freq
is the frequency counterpart to the
probability function comp_prob
.
By default, comp_freq
and its wrapper function
comp_freq_prob
round frequencies to nearest integers to avoid decimal values in
freq
(i.e., 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:by condition:
N = cond_true + cond_false
The frequency
cond_true
depends on the prevalenceprev
and the frequencycond_false
depends on the prevalence's complement1 - prev
.by decision:
The frequency
dec_pos
depends on the proportion of positive decisionsppod
and the frequencydec_neg
depends on the proportion of negative decisions1 - ppod
.by accuracy (i.e., correspondence of decision to condition):
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 essential probabilitiesprev
,sens
, andspec
).If
N
is unknown (NA
), a suitable minimum value can be computed bycomp_min_N
.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:
prevalence
prev
:sensitivity
sens
:miss rate
mirt
:specificity
spec
:false alarm rate
fart
:proportion of positive decisions
ppod
:positive predictive value
PPV
:negative predictive value
NPV
:false detection rate
FDR
:false omission rate
FOR
:accuracy
acc
:rate of hits, given accuracy
p_acc_hi
:rate of false alarms, given inaccuracy
p_err_fa
:
Beware of rounding and sampling issues! If frequencies are rounded (by
round = TRUE
incomp_freq
) or sampled from probabilities (bysample = TRUE
), then any probabilities computed fromfreq
may differ from original and exact probabilities.
Functions translating between representational formats:
comp_prob_prob
, comp_prob_freq
,
comp_freq_prob
, comp_freq_freq
(see documentation of comp_prob_prob
for details).
Value
A list freq
containing 11 key frequency values.
See Also
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).
Other functions computing frequencies:
comp_freq_freq()
,
comp_freq_prob()
,
comp_min_N()
,
comp_prob_prob()
Examples
comp_freq() # ok, using current defaults
length(comp_freq()) # 11 key frequencies
# Rounding:
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
# Sampling (from probabilistic description):
comp_freq_prob(prev = .5, sens = .5, spec = .5, N = 100, sample = TRUE) # freq values vary
# 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)