Learn R Programming

softwareRisk (version 0.1.0)

risk_form_variance_share_fun: Proportion of risk-score variance due to functional-form uncertainty

Description

Computes, for each node, the proportion of variance in the node risk score that is attributable to uncertainty in the functional form used to construct the risk score (additive vs power-mean), as opposed to uncertainty in the parameters within a given form.

Usage

risk_form_variance_share_fun(all_paths_out, N, q = 0.5, eps = 1e-12)

Value

A data.table with columns:

name

Node name.

form_variance_share

Proportion of node-risk variance attributable to functional-form uncertainty.

Arguments

all_paths_out

A list produced by all_paths_fun() with element nodes. nodes must contain columns name, cyclomatic_complexity, indeg, and btw.

N

Integer. Base sample size passed to sensobol::sobol_matrices().

q

Numeric scalar in \([0,1]\). Mixture weight giving the probability that the functional form is "power_mean" (and \(1-q\) for "additive"). Default 0.5.

eps

Numeric. Small positive constant \(\epsilon\) used for numerical stability in the \(p \to 0\) evaluation. Default 1e-12.

Details

The function draws parameter samples for two model forms:

  • Additive form with weights \((\alpha,\beta,\gamma)\) normalized to sum to one.

  • Power-mean form with weights \((\alpha,\beta,\gamma)\) normalized to sum to one and a power parameter \(p\) mapped to the interval \([-1,2]\).

For each node, it evaluates the risk under both forms and applies the variance decomposition for a two-component mixture model:

$$\mathrm{Var}(Y) = \mathbb{E}\left[\mathrm{Var}(Y \mid M)\right] + \mathrm{Var}\left(\mathbb{E}[Y \mid M]\right)\,,$$

where \(M\) indicates the functional form. Let \(q\) be the probability of choosing the power-mean form (and \(1-q\) the probability of choosing the additive form). The between-form component is

$$V_{\mathrm{between}} = q(1-q)\,(\mu_1 - \mu_0)^2\,,$$

and the total variance is

$$V_{\mathrm{total}} = (1-q)V_0 + qV_1 + V_{\mathrm{between}}\,,$$

where \(\mu_0, V_0\) are the mean and variance under the additive form and \(\mu_1, V_1\) are the mean and variance under the power-mean form. The reported proportion is \(V_{\mathrm{between}} / V_{\mathrm{total}}\).

This function focuses only on variance attributable to the choice of functional form. It does not return full uncertainty draws, Sobol sensitivity indices, or path-level uncertainty propagation.

Examples

Run this code
data(synthetic_graph)
out <- all_paths_fun(graph = synthetic_graph, complexity_col = "cyclo")
vf <- risk_form_variance_share_fun(all_paths_out = out, N = 2^10, q = 0.5)
vf

Run the code above in your browser using DataLab