
Combine Potential Impact Fractions and Population Attributable Fractions
totalpifpaf.RdCombine potential impact fractions or the population attributable fractions
to either generate the total fraction from the fractions of
subpopulations (pif_total/paf_total) or the ensemble fraction of a population
from different (independent) exposures.
Usage
paf_total(
paf1,
...,
weights,
var_weights = 0,
var_pif_weights = NULL,
conf_level = 0.95,
link = "log-complement",
link_inv = NULL,
link_deriv = NULL,
quiet = FALSE,
label = NULL
)
pif_total(
pif1,
...,
weights,
var_weights = 0,
var_pif_weights = NULL,
conf_level = 0.95,
link = "log-complement",
link_inv = NULL,
link_deriv = NULL,
quiet = FALSE,
label = NULL,
is_paf = FALSE,
weights_sum_to_1 = TRUE
)
paf_ensemble(
paf1,
...,
weights = NULL,
var_weights = 0,
var_pif_weights = NULL,
link = "identity",
link_inv = NULL,
link_deriv = NULL,
conf_level = 0.95,
label = NULL,
quiet = FALSE
)
pif_ensemble(
pif1,
...,
weights = NULL,
var_weights = 0,
var_pif_weights = NULL,
link = "identity",
link_inv = NULL,
link_deriv = NULL,
conf_level = 0.95,
quiet = FALSE,
label = NULL,
is_paf = FALSE
)Arguments
- paf1
A population attributable fraction (class
pif_class)- ...
The remaining potential impact fractions or (respectively) population attributable fractions.
- weights
A vector containing the proportion of the population for each of the categories (for each of the pifs given).
- var_weights
link_covariance structure for the
weights. Can be0(default) if the weights are not random, a vector if only the link_variances of the weights are available or a link_covariance matrix.- var_pif_weights
covariance matrix with row
iand columnjrepresenting the covariance between thei-th potential impact fraction of the list and thej-th weight- conf_level
Confidence level for the confidence interval (default 0.95).
- link
Link function such that the
pifconfidence intervals stays within the expected bounds.- link_inv
(Optional). If
linkis a function then yhe inverse oflink. For example iflinkislogitthis should beinv_logit.- link_deriv
Derivative of the
linkfunction. The function tries to build it automatically fromlinkusingDeriv::Deriv().- quiet
Whether to show messages.
- label
Character identifier for the impact fraction. This is for
- pif1
A potential impact fraction (class
pif_class)- is_paf
Whether the computed quantity is a population attributable fraction or not
- weights_sum_to_1
Boolean flag indicating if the weights sum to 1 (normalized weights) or if they are not (unnormalized).
Value
A pif_class object containing the estimate for the total
fraction or the ensemble fraction that aggregates several fractions
(either potential impact or population attributable).
Total potential impact fraction
Assuming the overall population can be subdivided into \(N\) distinct subpopulations each of them with a different potential impact fraction (or population attributable fraction) we can estimate the total population attributable fraction or potential impact fraction of the whole population as:
$$ \text{PIF}_{\text{Total}} = \sum\limits_{i = 1}^{N} \pi_i \cdot \text{PIF}_i $$
where each \(\text{PIF}_i\) corresponds to the potential impact fraction of the i-th subpopulation and \(\pi_i\) correspond to the proportion of the total population occupied by \(\text{PIF}_i\). The weights are such that \(\sum_{i=1}^{N} \pi_i = 1\).
Ensemble potential impact fraction
If a population is exposed to \(K\) different independent risk factors then the ensemble impact fraction of the combination of those factors can be written as:
$$ \text{PIF}_{\text{Ensemble}} = 1 - \prod\limits_{\ell = 1}^{K} \Big(1 - \pi_{\ell} \cdot \text{PIF}_{\ell}\Big) $$
where each \(\text{PIF}_{\ell}\) corresponds to the potential impact fraction of the \(\ell\)-th risk factor for the same population.
Examples
#Potential impact fraction for women
pif_women <- pif(0.32, 0.1, 1.2, quiet = TRUE, var_p = 0.1)
#Potential impact fraction for men
pif_men <- pif(0.27, 0.1, 1.3, quiet = TRUE, var_p = 0.1)
#Population potential impact fraction with 49% men and 51% women
pif_total(pif_men, pif_women, weights = c(0.49, 0.51), link = "logit")
#>
#> ── Potential Impact Fraction: [deltapif-264893202856241] ──
#>
#> PIF = 27.862% [95% CI: 22.944% to 33.377%]
#> standard_deviation(pif %) = 23.319
#> ────────────────────────────────── Components: ─────────────────────────────────
#> • 26.372% (sd %: 36.119) --- [deltapif-206365445053881]
#> • 29.294% (sd %: 29.772) --- [deltapif-063317817552485]
#> ────────────────────────────────────────────────────────────────────────────────
#Population attributable fraction for women
paf_women <- paf(0.32, 1.3, quiet = TRUE, var_p = 0.1)
#Population attributable fraction for men
paf_men <- paf(0.27, 1.3, quiet = TRUE, var_p = 0.1)
paf_total(paf_men, paf_women, weights = c(0.49, 0.51), link = "logit")
#>
#> ── Population Attributable Fraction: [deltapif-0675244698081724] ──
#>
#> PAF = 44.018% [95% CI: 38.601% to 49.581%]
#> standard_deviation(paf %) = 18.760
#> ────────────────────────────────── Components: ─────────────────────────────────
#> • 41.884% (sd %: 28.509) --- [deltapif-0845195738551864]
#> • 46.068% (sd %: 24.552) --- [deltapif-063953477020697]
#> ────────────────────────────────────────────────────────────────────────────────
# Calculate the ensemble from lead and radiation exposure
paf_lead <- paf(0.2, 2.2, quiet = TRUE, var_p = 0.001)
paf_rad <- paf(0.1, 1.2, quiet = TRUE, var_p = 0.0001)
pif_ensemble(paf_lead, paf_rad)
#>
#> ── Population Attributable Fraction: [deltapif-210215247889527] ──
#>
#> PAF = 68.841% [95% CI: 64.670% to 73.013%]
#> standard_deviation(paf %) = 3.092
#> ────────────────────────────────── Components: ─────────────────────────────────
#> • 61.612% (sd %: 3.740) --- [deltapif-021223603483794]
#> • 18.832% (sd %: 1.529) --- [deltapif-0906340178564226]
#> ────────────────────────────────────────────────────────────────────────────────
# Totals and ensembles can be combined
pif_lead_women <- paf(0.27, 2.2, quiet = TRUE, var_p = 0.001)
pif_rad_women <- paf(0.12, 1.2, quiet = TRUE, var_p = 0.001)
pif_women <- pif_ensemble(pif_lead_women, pif_rad_women)
pif_lead_men <- paf(0.30, 2.2, quiet = TRUE, var_p = 0.001)
pif_rad_men <- paf(0.10, 1.2, quiet = TRUE, var_p = 0.001)
pif_men <- pif_ensemble(pif_lead_men, pif_rad_men)
pif_total(pif_men, pif_women, weights = c(0.49, 0.51))
#>
#> ── Population Attributable Fraction: [deltapif-0876777326556075] ──
#>
#> PAF = 75.731% [95% CI: 74.815% to 76.612%]
#> standard_deviation(paf %) = 1.668
#> ────────────────────────────────── Components: ─────────────────────────────────
#> • 76.180% (sd %: 2.271) --- [deltapif-141602391449351]
#> • 75.299% (sd %: 2.435) --- [deltapif-0480725266268846]
#> ────────────────────────────────────────────────────────────────────────────────