Functions & Formulae

Each applied formula has its own function page, with a signature, implementations, and tests.

Expected value of an uncertain cost, health outcome or model output

E[X] = sum_(k=1)^K p_k * x_k

Maps the probability distribution of an uncertain quantity, such as a cost per patient, a QALY total or a model output that depends on uncertain parameters, to its probability-weighted mean, which carries the units of the quantity. The discrete form applied at chance nodes is HE-FM-CHN-001 on the chance node page, the Monte Carlo mean over probabilistic simulations is HE-FM-ENB-001 and the constant-hazard event probability used below is HE-FM-TP-001. The records here cover the cases in which the mean of a function differs from the function of the means: a product of correlated quantities, a curved output with an uncertain parameter, an event probability under a gamma-distributed hazard and the mean of a log-normal cost. Notation follows the Expected Value article.

  • Expected value of a product of two correlated quantities

    E_NU = E_N * E_U + Cov_NU

    Gives the expected value of a product, such as the number of admissions times the cost per admission, from the two means and their covariance. The identity is exact for any joint distribution with finite variances. The product of the means equals the expected product only when the covariance is zero, for example when the two quantities are independent; a positive covariance raises the expected product above the product of the means and a negative one lowers it.

  • Second-order approximation to the expected value of a curved model output

    E_g = g_mu + 0.5 * d2g * Var_theta

    Approximates the expected value of an output g(theta) that depends on one uncertain parameter by its value at the parameter mean plus half its second derivative at the mean times the parameter variance. The correction shows the direction of Jensen's inequality: it is negative for a concave output, positive for a convex one and zero for a linear one. With several parameters the article's double sum adds a term for each pair, weighted by their covariance; for the product N times U the only second derivative is the cross term, equal to 1, so the expansion is exact and gives HE-FM-EV-001. The approximation indicates sign and rough size; the simulated mean (HE-FM-ENB-001) or a closed form is the estimate.

  • Expected survival and event probability under a gamma-distributed constant hazard

    S_bar = (1 + s * t)^(-k); p_bar = 1 - S_bar

    When a constant hazard h is uncertain and follows a gamma distribution with shape k and scale s, so that its mean is k times s and its variance k times s squared, the expected value of exp(minus h t) is the gamma Laplace transform evaluated at t, and the expected event probability over the horizon t is one minus that value. It replaces the deterministic 1 minus exp(minus h t) at the mean hazard (HE-FM-TP-001), which overstates the expected probability because the probability is concave in h. The same identity gives population survival under a gamma frailty with a constant baseline hazard.

  • Mean and median of a log-normal cost

    E_C = exp(mu + sigma^2 / 2); M_C = exp(mu)

    When the natural log of cost is normally distributed with mean mu and standard deviation sigma, the median cost and the geometric mean cost both equal exp(mu), and the expected cost is the median multiplied by exp(sigma squared over 2). The factor is Jensen's inequality for the convex exponential: exponentiating the mean log cost returns the median, not the mean. The expected cost is the figure that, multiplied by the number of patients, gives the total budget.