Skip to contents

Recursively obtains the link_covariance matrix of a pif_total_class

Computes the link_covariance (covariance) or correlation (correlation) for multiple potential impact fractions and the link_variance variance and standard deviation standard_deviationfor a potential impact fraction.

Usage

cov_total_pif(
  pif1,
  pif2,
  var_p = NULL,
  var_beta = NULL,
  uncorrelated_p = "guess",
  uncorrelated_beta = "guess",
  quiet = FALSE
)

covariance(
  x,
  ...,
  var_p = NULL,
  var_beta = NULL,
  uncorrelated_p = "guess",
  uncorrelated_beta = "guess",
  quiet = FALSE
)

variance(x, ...)

standard_deviation(x, ...)

correlation(
  x,
  ...,
  var_p = NULL,
  var_beta = NULL,
  uncorrelated_p = "guess",
  uncorrelated_beta = "guess",
  quiet = FALSE
)

Arguments

pif1

Either a pif_atomic_class or a pif_total_class

pif2

Either a pif_atomic_class or a pif_total_class

var_p

link_covariance matrix for the prevalences in all pif1 and the ones included in ....

var_beta

link_covariance matrix for the parameter beta in all pif1 and the ones included in ....

uncorrelated_p

If all the pifs share the same prevalence data. Either TRUE, FALSE, guess (default) or a matrix. If a matrix is given then uncorrelated_p[i,j] = 1 if the i-th and j-th pifs share the same prevalence data uncorrelated_p[i,j] = 0 if the i-th and j-th pifs don't share the same prevalence data.

uncorrelated_beta

If all the pifs share the same beta parameter. Either TRUE, FALSE or guess (default) or a matrix. If a matrix is given then uncorrelated_beta[i,j] = 1 if the i-th and j-th pifs share the same relative risk parameters uncorrelated_beta[i,j] = 0 if the i-th and j-th pifs don't share the same relative risk parameters.

quiet

Whether to throw warnings and other messages

x

A potential impact fraction

...

Multiple additional potential impact fraction objects separated by commas.

Examples

# Get the approximate link_variance of a pif object
my_pif <- pif(p = 0.5, p_cft = 0.25, beta = 1.3, var_p = 0.1, var_beta = 0.2)
variance(my_pif)
#> [1] 0.01309351

# This is the same as link_covariance with just 1 pIF
covariance(my_pif)
#>            [,1]
#> [1,] 0.01309351

# Calculate the link_covariance between 3 fractions with shared relative risk
beta <- 0.3
var_beta <- 0.1
pif1 <- pif(0.5, 0.2, beta, var_p = 0.5 * (1 - 0.5) / 100, var_beta = var_beta)
pif2 <- pif(0.3, 0.1, beta, var_p = 0.3 * (1 - 0.3) / 100, var_beta = var_beta)
pif3 <- pif(0.7, 0.3, beta, var_p = 0.7 * (1 - 0.7) / 100, var_beta = var_beta)
covariance(pif1, pif2, pif3, uncorrelated_beta = FALSE)
#>            [,1]       [,2]       [,3]
#> [1,] 0.05549391 0.02275466 0.10919787
#> [2,] 0.02275466 0.01255449 0.04928281
#> [3,] 0.10919787 0.04928281 0.24599711

# The link_covariance between a pif and itself only has the link_variance as entries
covariance(pif1, pif1, uncorrelated_beta = FALSE, uncorrelated_p = FALSE)
#>            [,1]       [,2]
#> [1,] 0.05549391 0.05549391
#> [2,] 0.05549391 0.05549391

# Or if there is a link_covariance structure between different betas you can specify with
# var_beta in the link_covariance
betas <- c(1.3, 1.2, 1.27)

# link_covariance among all betas
var_beta <- matrix(c(
  1.0000000, -0.12123053, 0.35429369,
  -0.1212305, 1.00000000, -0.04266409,
  0.3542937, -0.04266409, 1.00000000
), byrow = TRUE, ncol = 3)
pif1 <- pif(0.5, 0.2, betas[1], var_p = 0.5 * (1 - 0.5) / 100, var_beta = var_beta[1, 1])
pif2 <- pif(0.3, 0.1, betas[2], var_p = 0.3 * (1 - 0.3) / 100, var_beta = var_beta[2, 2])
pif3 <- pif(0.3, 0.1, betas[3], var_p = 0.3 * (1 - 0.3) / 100, var_beta = var_beta[3, 3])
covariance(pif1, pif2, pif3, var_beta = var_beta)
#> ! The prevalence parameters p for the potential impact fractions appear to be the same. If they are, set `uncorrelated_p = FALSE`. Otherwise set `uncorrelated_p = TRUE
#>              [,1]         [,2]         [,3]
#> [1,]  0.051602337 -0.004895035  0.013755222
#> [2,] -0.004895035  0.031752970 -0.001209275
#> [3,]  0.013755222 -0.001209275  0.029410798

# Compute the correlation
correlation(pif1, pif2, pif3, var_beta = var_beta, quiet = TRUE)
#>            [,1]        [,2]        [,3]
#> [1,]  1.0000000 -0.12092859  0.35308520
#> [2,] -0.1209286  1.00000000 -0.03957123
#> [3,]  0.3530852 -0.03957123  1.00000000