Skip to content
Biomedical Science

biomedical-science-ai999x

Pharmacokinetics and dosing models, epidemic models, diagnostic test statistics, survival analysis, biomechanics, neuron models and medical-imaging physics (quantitative only, no clinical advice).

86capabilities
9topics
86formulas typeset
8worked examples below
1.0.1version
About this model

What Biomedical Science does

Biomedical Science (biomedical-science-ai999x) is an offline Python package for biomedical science. It covers pharmacokinetics and dosing models, epidemic models, diagnostic test statistics, survival analysis, biomechanics, neuron models and medical-imaging physics (quantitative only, no clinical advice).

It has 86 capabilities — 86 computational procedures — in 9 topics, the largest being Pharmacokinetic models, Medical-imaging physics, Biomechanics, Neuron models, Epidemic models and Survival analysis. Ask a question in words with ask(), or call a capability by name with typed inputs with solve(). Every answer carries its value and unit, the steps that produced it and the formula in LaTeX.

When a question is not determined — a value is missing, an input is out of range, or the request is outside the package — it says so and names what it needs, instead of guessing. It runs on an ordinary CPU without a network connection (Python >=3.10), and the same question always gets the same answer.

Install

pip install biomedical-science-ai999x
hf download AI999X/biomedical-science-ai999x --local-dir biomedical-science-ai999x

What it covers

Biomechanics11Basal metabolic rate by a stated regression (a calculation, not medical advice) · Body mass index (a calculation, not medical advice) · Cardiac output by indicator dilution (Stewart-Hamilton) …Diagnostic test statistics5Cohen's kappa for agreement between two raters or two tests · Optimal diagnostic cut-off by the Youden index · ROC curve area of a diagnostic score (Mann-Whitney form) …Epidemic models8Reed-Frost chain-binomial epidemic: distribution and mean of the final size · Reproduction number from an epidemic growth rate (gamma-distributed generation interval) · SEIR epidemic model: final size …Epidemiological measures of association6Absolute risk reduction and number needed to treat with Wald intervals · Incidence rate ratio of two person-time groups with log-Wald interval · Mantel-Haenszel pooled odds ratio over strata with Robins-Breslow-Greenland interval …Medical-imaging physics14CT number in Hounsfield units · Diffusion MRI: apparent diffusion coefficient from signals at several b-values · Imaging resolution: MTF of a Gaussian point-spread function …Neuron models10FitzHugh-Nagumo neuron model: fixed point and its stability · Goldman-Hodgkin-Katz current equation: ionic current density through a membrane · Goldman-Hodgkin-Katz voltage equation: membrane potential from K, Na and Cl …Pharmacokinetic data analysis4Absolute bioavailability from IV and oral concentration profiles (a model calculation, not medical advice) · AUC from concentration-time data by the trapezoidal rule · Elimination rate constant and half-life from concentration data (log-linear fit) …Pharmacokinetic models20Area under the concentration curve of a one-compartment IV bolus (a model calculation, not medical advice) · Constant infusion: time to reach a fraction of steady state (a model calculation, not medical advice) · Constant-rate IV infusion: concentration at a time and steady state (a model calculation, not medical advice) …Survival analysis8Cox proportional-hazards model with one covariate: hazard ratio (Efron ties) · Exponential survival model: hazard rate, mean and median survival (maximum likelihood) · Hazard ratio of two exponential survival groups with Wald interval …
Try it

Worked examples

Each question below was put to biomedical-science-ai999x and the answer shown is the one it returned, with the steps it took.

Pharmacokinetic modelsm.ask(…)

IV bolus concentration: D = 500 mg, V = 40 L, k = 0.1 1/h, t = 6 h

C = 0.006860145451 kg/m^3
fraction_remaining = 0.5488116361
Show the steps
  1. One-compartment IV bolus: concentration at a time (a model calculation, not medical advice)
    C(t) = \frac{D}{V}\,e^{-k t}
    with D = 500 mg, V = 40 L, k = 0.1 1/h, t = 6 h
    → C = 0.006860145451 kg/m^3, fraction_remaining = 0.5488116361 kg/m^3
Epidemic modelsm.ask(…)

SIR final size: R0 = 2.5, s0 = 0.99, i0 = 0.01

s_inf = 0.1058941943
attack = 0.8841058057
Show the steps
  1. SIR epidemic model: final size (final susceptible fraction and attack fraction)
    \ln\frac{s_0}{s_\infty} = R_0\,(s_0 + i_0 - s_\infty)
    with R0 = 2.5, s0 = 0.99, i0 = 0.01
    → s_inf = 0.1058941943, attack = 0.8841058057
Survival analysism.ask(…)

Kaplan-Meier survival: times = [2, 3, 3, 5, 8, 9, 12, 15], events = [1, 0, 1, 1, 0, 1, 1, 0], t = 6

S_t = 0.6
median = 9
Show the steps
  1. Kaplan-Meier survival estimate at a time and median survival
    \hat S(t) = \prod_{u_i \le t}\left(1 - \frac{d_i}{n_i}\right)
    with times = [2, 3, 3, 5, 8, 9, 12, 15], events = [1, 0, 1, 1, 0, 1, 1, 0], t = 6
    → S_t = 0.6, median = 9
Neuron modelsm.ask(…)

GHK voltage: T = 310 K, PK = 1, PNa = 0.04, PCl = 0.45, K_o = 4 mmol/L, K_i = 140 mmol/L, Na_o = 145 mmol/L, Na_i = 12 mmol/L, Cl_o = 116 mmol/L, Cl_i = 4 mmol/L

V_m = -0.07506627615 V
Show the steps
  1. Goldman-Hodgkin-Katz voltage equation: membrane potential from K, Na and Cl
    V_m = \frac{RT}{F}\ln\frac{P_K[K^+]_o + P_{Na}[Na^+]_o + P_{Cl}[Cl^-]_i}{P_K[K^+]_i + P_{Na}[Na^+]_i + P_{Cl}[Cl^-]_o}
    with T = 310 K, PK = 1, PNa = 0.04, PCl = 0.45, K_o = 4 mmol/L, K_i = 140 mmol/L, Na_o = 145 mmol/L, Na_i = 12 mmol/L, Cl_o = 116 mmol/L, Cl_i = 4 mmol/L
    → V_m = -0.07506627615 V
Epidemiological measures of associationm.solve(…)
m.solve("bmed_odds_ratio_ci", a=20, b=80, c=10, d=90, level=0.95)
OR = 2.25
lower = 0.9942948923
upper = 5.091547829
Show the steps
  1. Odds ratio of a 2x2 exposure-outcome table with Woolf (logit) interval
    OR = \frac{ad}{bc},\quad \mathrm{SE}(\ln OR) = \sqrt{\tfrac1a + \tfrac1b + \tfrac1c + \tfrac1d}
    with a = 20, b = 80, c = 10, d = 90, level = 0.95
    → OR = 2.25, lower = 0.9942948923, upper = 5.091547829
Biomechanicsm.ask(…)

Body mass index: m = 70 kg, h = 1.75 m

BMI = 22.85714286
BMI_prime = 0.9142857143
Show the steps
  1. Body mass index (a calculation, not medical advice)
    \mathrm{BMI} = \frac{m}{h^2}
    with m = 70 kg, h = 1.75 m
    → BMI = 22.85714286, BMI_prime = 0.9142857143
Diagnostic test statisticsm.ask(…)

Cohen's kappa: counts = [[40, 10], [5, 45]]

kappa = 0.7
p_observed = 0.85
Show the steps
  1. Cohen's kappa for agreement between two raters or two tests
    \kappa = \frac{p_o - p_e}{1 - p_e},\quad p_e = \sum_i \frac{n_{i\cdot}\,n_{\cdot i}}{n^2}
    with counts = [40 10; 5 45]
    → kappa = 0.7, p_observed = 0.85
Medical-imaging physicsm.ask(…)

Gaussian PSF MTF: fwhm = 0.5 mm, f = 1 1/mm

MTF = 0.4106858004
f50 = 882.5424006 1/m
Show the steps
  1. Imaging resolution: MTF of a Gaussian point-spread function
    \mathrm{MTF}(f) = e^{-2\pi^2\sigma^2 f^2},\quad \sigma = \frac{\mathrm{FWHM}}{2\sqrt{2\ln 2}}
    with fwhm = 0.5 mm, f = 1 1/mm
    → MTF = 0.4106858004, f50 = 882.5424006 1/m
Use it

From Python or the command line

Every snippet was run as shown; the output under it is what it printed.

import biomedical_science_ai999x as m

a = m.ask("IV bolus concentration: D = 500 mg, V = 40 L, k = 0.1 1/h, t = 6 h")
print(a.outcome)
print(a.values)
for step in a.steps:
    print(step["name"])
Output
SOLVED
{'C': 0.00686014545118, 'fraction_remaining': 0.548811636094}
One-compartment IV bolus: concentration at a time (a model calculation, not medical advice)
Figures

Computed, not drawn by hand

Every value in these figures was computed by the package, each point a run of solve(); in a notebook, plot() and plot_relation() draw a capability's curves the same way.

Kaplan–Meier survival curve with confidence band

\hat S(t) = \prod_{u_i \le t}\left(1 - \frac{d_i}{n_i}\right)
Kaplan–Meier survival curve with confidence bandKaplan–Meier survival estimate for 21 subjects (9 events, the rest censored), with its pointwise 95 % confidence band, both computed by the package at every whole time from 0 to 36. S(12) = 0.752941; marked: median survival t = 23, S = 0.448179.010203000.250.50.751S = 0.5median 2395 % confidence bandKaplan–Meier estimatet — timeS(t) — probability of surviving past t
Kaplan–Meier survival estimate for 21 subjects (9 events, the rest censored), with its pointwise 95 % confidence band, both computed by the package at every whole time from 0 to 36. S(12) = 0.752941; marked: median survival t = 23, S = 0.448179.

ROC curve of a diagnostic test

\mathrm{Se} = \frac{TP}{TP + FN},\quad \mathrm{Sp} = \frac{TN}{TN + FP}
ROC curve of a diagnostic testROC curve of a test with 5 diseased and 6 healthy scores: sensitivity and specificity computed by the package at 12 thresholds; area under the curve 0.883333. Marked: the Youden-optimal cut-off 0.55 (sensitivity 0.8, specificity 0.833333, J = 0.633333).00.5100.20.40.60.81cut-off 0.55chancearea under the curve = 0.8833331 − specificity (false-positive rate)sensitivity (true-positive rate)
ROC curve of a test with 5 diseased and 6 healthy scores: sensitivity and specificity computed by the package at 12 thresholds; area under the curve 0.883333. Marked: the Youden-optimal cut-off 0.55 (sensitivity 0.8, specificity 0.833333, J = 0.633333).

Oral dose: concentration against time

C(t) = \frac{F D k_a}{V (k_a - k)}\left(e^{-k t} - e^{-k_a t}\right)
Oral dose: concentration against timePlasma concentration after one oral dose (D = 250 mg, F = 0.8, V = 35 L, ka = 1.2 1/h, k = 0.15 1/h), computed by the package at 120 times over 24 h; marked: t_max = 1.98042 h, C_max = 4.2457 mg/L.0102001234C_max 4.2457 mg/L at 1.98042 ht — time after the dose [h]C — plasma concentration [mg/L]
Plasma concentration after one oral dose (D = 250 mg, F = 0.8, V = 35 L, ka = 1.2 1/h, k = 0.15 1/h), computed by the package at 120 times over 24 h; marked: t_max = 1.98042 h, C_max = 4.2457 mg/L.

Repeated doses: accumulation to steady state

C_n(t) = \frac{D}{V}\,\frac{1 - e^{-n k \tau}}{1 - e^{-k \tau}}\,e^{-k t}
Repeated doses: accumulation to steady stateSeven intravenous doses of 500 mg every 8 h (V = 40 L, k = 0.1 1/h): the concentration computed by the package at 31 times in each interval rises towards the steady state it returns (max 22.6996 mg/L, min 10.1996 mg/L, accumulation ratio 1.81597); marked: peak after dose 7, t = 48 h, C = 22.6156 mg/L.020405101520steady-state max 22.6996steady-state min 10.199622.6156t — time since the first dose [h]C — plasma concentration [mg/L]
Seven intravenous doses of 500 mg every 8 h (V = 40 L, k = 0.1 1/h): the concentration computed by the package at 31 times in each interval rises towards the steady state it returns (max 22.6996 mg/L, min 10.1996 mg/L, accumulation ratio 1.81597); marked: peak after dose 7, t = 48 h, C = 22.6156 mg/L.

Confusion matrix at the optimal cut-off

\mathrm{Se} = \frac{TP}{TP + FN},\quad \mathrm{Sp} = \frac{TN}{TN + FP}
Confusion matrixThe 2 × 2 table (rows: diseased, healthy; columns: test positive, test negative) with the same table as rates per row (right), for the test at its Youden-optimal cut-off 0.55, counted by the package from 5 diseased and 6 healthy scores: TP = 4, FN = 1, FP = 1, TN = 5. Sensitivity 0.8 (95 % interval 0.375535–0.963776), specificity 0.833333 (0.436497–0.969947).4115counts0.80.20.1670.833rates per row
The 2 × 2 table (rows: diseased, healthy; columns: test positive, test negative) with the same table as rates per row (right), for the test at its Youden-optimal cut-off 0.55, counted by the package from 5 diseased and 6 healthy scores: TP = 4, FN = 1, FP = 1, TN = 5. Sensitivity 0.8 (95 % interval 0.375535–0.963776), specificity 0.833333 (0.436497–0.969947).

Effect sizes with confidence intervals (forest plot)

OR = \frac{ad}{bc},\quad \mathrm{SE}(\ln OR) = \sqrt{\tfrac1a + \tfrac1b + \tfrac1c + \tfrac1d}
Effect sizes with confidence intervals (forest plot)Forest plot of six effect measures, each computed by the package on its own worked example, with 95 % intervals: odds ratio 2.25 (0.994295–5.09155); relative risk 2 (0.986563–4.05448); incidence rate ratio 2.4 (1.29133–4.46051); Mantel–Haenszel odds ratio 2.60776 (1.08405–6.27313); exponential hazard ratio 5.16055 (1.58923–16.7573); Cox hazard ratio 1.04846 (0.279864–3.92787). An interval that crosses 1 (grey point) is compatible with no effect.110odds ratio 2.25relative risk 2incidence rate ratio 2.4Mantel–Haenszel odds ratio 2.60776exponential hazard ratio 5.16055Cox hazard ratio 1.04846ratio (logarithmic axis; 1 = no effect)
Forest plot of six effect measures, each computed by the package on its own worked example, with 95 % intervals: odds ratio 2.25 (0.994295–5.09155); relative risk 2 (0.986563–4.05448); incidence rate ratio 2.4 (1.29133–4.46051); Mantel–Haenszel odds ratio 2.60776 (1.08405–6.27313); exponential hazard ratio 5.16055 (1.58923–16.7573); Cox hazard ratio 1.04846 (0.279864–3.92787). An interval that crosses 1 (grey point) is compatible with no effect.
Formulas

The mathematics inside

12 of its 86 formulas; every one is in the capability browser below.

SIR epidemic model: final size (final susceptible fraction and attack fraction)
\ln\frac{s_0}{s_\infty} = R_0\,(s_0 + i_0 - s_\infty)
Kaplan-Meier survival estimate at a time and median survival
\hat S(t) = \prod_{u_i \le t}\left(1 - \frac{d_i}{n_i}\right)
Goldman-Hodgkin-Katz voltage equation: membrane potential from K, Na and Cl
V_m = \frac{RT}{F}\ln\frac{P_K[K^+]_o + P_{Na}[Na^+]_o + P_{Cl}[Cl^-]_i}{P_K[K^+]_i + P_{Na}[Na^+]_i + P_{Cl}[Cl^-]_o}
Odds ratio of a 2x2 exposure-outcome table with Woolf (logit) interval
OR = \frac{ad}{bc},\quad \mathrm{SE}(\ln OR) = \sqrt{\tfrac1a + \tfrac1b + \tfrac1c + \tfrac1d}
Cohen's kappa for agreement between two raters or two tests
\kappa = \frac{p_o - p_e}{1 - p_e},\quad p_e = \sum_i \frac{n_{i\cdot}\,n_{\cdot i}}{n^2}
Imaging resolution: MTF of a Gaussian point-spread function
\mathrm{MTF}(f) = e^{-2\pi^2\sigma^2 f^2},\quad \sigma = \frac{\mathrm{FWHM}}{2\sqrt{2\ln 2}}
Optimal diagnostic cut-off by the Youden index
J(c) = \mathrm{Se}(c) + \mathrm{Sp}(c) - 1,\quad c^* = \arg\max_c J(c)
Reed-Frost chain-binomial epidemic: distribution and mean of the final size
S_{t+1} \sim \mathrm{Bin}\!\left(S_t, (1 - p)^{I_t}\right),\quad I_{t+1} = S_t - S_{t+1}
Absolute risk reduction and number needed to treat with Wald intervals
ARR = p_c - p_t,\quad NNT = \frac{1}{ARR},\quad \mathrm{SE} = \sqrt{\tfrac{p_t(1-p_t)}{n_t} + \tfrac{p_c(1-p_c)}{n_c}}
Capabilities

Every capability, with an example

Search by name, formula, input or topic. Each capability opens to show what it takes, what it returns, when it applies, and a question it answered.

86 capabilities

Biomechanics 11

Basal metabolic rate by a stated regression (a calculation, not medical advice)bmed_bmr

The basal metabolic rate estimated by the Mifflin-St Jeor (1990) or the revised Harris-Benedict (Roza and Shizgal 1984) regression from mass, height, age and sex, in kcal/day, W and MJ/day; a model calculation, not dietary or medical advice.

\mathrm{BMR} = 10\,m + 6.25\,h - 5\,a + s

Inputs

  • m body mass [kg]
  • h height [m]
  • age age in years (adults)
  • sex sex (the equations have a male and a female form) choice
  • equation regression: mifflin_st_jeor or harris_benedict_revised choice

Returns

  • BMR_kcal_day basal metabolic rate in kcal/day
  • BMR_W basal metabolic rate (W) [W]
  • BMR_MJ_day basal metabolic rate in MJ/day

Applies when

  • a population regression, not a measurement and not advice
  • adults 18 to 120 years
  • 1 kcal = 4.184 kJ

Example

m.ask("Basal metabolic rate: m = 70 kg, h = 175 cm, age = 30, sex = male, equation = mifflin_st_jeor")
→ BMR_kcal_day = 1648.75, BMR_W = 79.8422 W, BMR_MJ_day = 6.89837
Body mass index (a calculation, not medical advice)bmed_bmi

The body mass index BMI = m/h^2 (kg/m^2) and BMI prime (BMI/25) as a calculation from mass and height; no category or health advice is given.

\mathrm{BMI} = \frac{m}{h^2}

Inputs

  • m body mass [kg]
  • h height [m]

Returns

  • BMI body mass index in kg/m^2
  • BMI_prime BMI/25

Applies when

  • a calculation only: not medical advice
  • 1 <= m <= 700 kg, 0.3 <= h <= 2.8 m

Example

m.ask("Body mass index: m = 70 kg, h = 1.75 m")
→ BMI = 22.8571, BMI_prime = 0.914286
Cardiac output by indicator dilution (Stewart-Hamilton)bmed_indicator_dilution_cardiac_output

The cardiac output (volume flow) from the mass of an injected indicator and its sampled first-pass concentration curve, by the Stewart-Hamilton principle with a trapezoidal area.

CO = \frac{m}{\int_0^{\infty} C(t)\,dt}

Inputs

  • m mass of indicator injected [kg]
  • t sampling times in s, strictly increasing vector
  • C indicator concentrations in mg/L (first pass, recirculation excluded) vector

Returns

  • AUC area under the concentration curve, mg*s/L
  • CO cardiac output m / AUC [m^3/s]

Applies when

  • complete mixing, no indicator loss
  • first-pass curve (recirculation removed by the user)
  • times in s, concentrations in mg/L
  • linear trapezoids

Example

m.ask("Indicator dilution cardiac output: m = 5 mg, t = [0, 2, 4, 6, 8, 10, 12, 14, 16], C = [0, 0.5, 2.8, 4.1, 3.5, 2.2, 1.1, 0.5, 0.2]")
→ AUC = 29.6, CO = 0.000168919 m^3/s
Kelvin-Voigt viscoelastic tissue model: creep strain under constant stressbmed_kelvin_voigt_creep

The strain of a Kelvin-Voigt (spring parallel to dashpot) tissue model a time t after a constant stress is applied.

\varepsilon(t) = \frac{\sigma}{E}\left(1 - e^{-E t/\eta}\right)

Inputs

  • sigma applied constant stress [Pa]
  • E spring modulus [Pa]
  • eta dashpot viscosity (Pa*s) [Pa*s]
  • t time since loading [s]

Returns

  • strain strain at time t

Applies when

  • linear viscoelasticity
  • stress applied as a step at t = 0, no initial strain

Example

m.ask("Kelvin-Voigt creep: sigma = 10 kPa, E = 100 kPa, eta = 500 kPa*s, t = 3 s")
→ strain = 0.0451188
Poiseuille flow in a blood vessel: flow rate, mean velocity, wall shear stress, resistancebmed_poiseuille_vessel_flow

Laminar (Hagen-Poiseuille) flow of a Newtonian fluid through a rigid vessel: volume flow rate, mean velocity, wall shear stress and hydraulic resistance from the pressure drop, radius, length and viscosity.

Q = \frac{\pi r^4 \Delta P}{8 \mu L},\quad \tau_w = \frac{4\mu Q}{\pi r^3},\quad R = \frac{8\mu L}{\pi r^4}

Inputs

  • dP pressure drop along the vessel [Pa]
  • r vessel radius [m]
  • L vessel length [m]
  • mu viscosity of the blood (Newtonian) [Pa*s]

Returns

  • Q volume flow rate [m^3/s]
  • v_mean mean velocity [m/s]
  • tau_wall wall shear stress [Pa]
  • R_hyd hydraulic resistance [Pa*s/m^3]

Applies when

  • steady laminar flow, Newtonian fluid
  • rigid straight cylindrical vessel, fully developed flow

Example

m.ask("Poiseuille vessel flow: dP = 4 mmHg, r = 2 mm, L = 10 cm, mu = 3.5 mPa*s")
→ Q = 9.57359e-06 m^3/s, v_mean = 0.761842 m/s, tau_wall = 5.3329 Pa, R_hyd = 5.57042e+07 Pa*s/m^3
Single-compartment respiratory mechanics: resistance and compliance by least squaresbmed_respiratory_mechanics_fit

Airway resistance, respiratory compliance and the end-expiratory pressure of the single-compartment equation of motion P = R Q + V/C + P0, fitted by least squares to sampled pressure, flow and volume.

P = R\,\dot V + \frac{V}{C} + P_0

Inputs

  • P airway pressures in cmH2O vector
  • Q flows in L/s at the same instants vector
  • V volumes above end-expiration in L at the same instants vector

Returns

  • R resistance, cmH2O*s/L
  • C compliance, L/cmH2O
  • P0 pressure at zero flow and volume, cmH2O

Applies when

  • linear single-compartment model
  • pressures in cmH2O, flows in L/s, volumes in L
  • ordinary least squares

Example

m.ask("Respiratory mechanics fit: P = [5.2, 9.8, 13.1, 15.9, 18.6, 20.2], Q = [0.5, 0.5, 0.45, 0.4, 0.35, 0.3], V = [0, 0.1, 0.19, 0.27, 0.34, 0.4]")
→ R = 16.7141, C = 0.0216558, P0 = -3.16919
Standard linear solid (Zener) tissue model: creep under constant stressbmed_sls_creep

The creep strain of a standard linear solid (a spring E_inf parallel to a Maxwell arm E1-eta) a time t after a constant stress is applied, and the final strain.

\varepsilon(t) = \frac{\sigma}{E_\infty} - \left(\frac{\sigma}{E_\infty} - \frac{\sigma}{E_\infty + E_1}\right)e^{-t/\tau_c},\ \tau_c = \frac{\eta(E_\infty + E_1)}{E_\infty E_1}

Inputs

  • sigma applied constant stress [Pa]
  • E_inf equilibrium (parallel) spring modulus [Pa]
  • E1 spring modulus of the Maxwell arm [Pa]
  • eta dashpot viscosity of the Maxwell arm [Pa*s]
  • t time since loading [s]

Returns

  • strain strain at time t
  • strain_inf final strain sigma/E_inf

Applies when

  • linear viscoelasticity
  • step stress at t = 0

Example

m.ask("Standard linear solid creep: sigma = 10 kPa, E_inf = 50 kPa, E1 = 100 kPa, eta = 200 kPa*s, t = 2 s")
→ strain = 0.104462, strain_inf = 0.2
Standard linear solid (Zener) tissue model: stress relaxation at constant strainbmed_sls_stress_relaxation

The stress of a standard linear solid a time t after a step strain eps0 is imposed, and the relaxed (equilibrium) stress.

\sigma(t) = \varepsilon_0\left(E_\infty + E_1 e^{-E_1 t/\eta}\right)

Inputs

  • eps0 imposed step strain (a pure number, e.g. 0.05)
  • E_inf equilibrium spring modulus [Pa]
  • E1 spring modulus of the Maxwell arm [Pa]
  • eta dashpot viscosity of the Maxwell arm [Pa*s]
  • t time since the strain step [s]

Returns

  • stress stress at time t [Pa]
  • stress_inf relaxed stress E_inf eps0 [Pa]

Applies when

  • linear viscoelasticity
  • step strain at t = 0

Example

m.ask("Standard linear solid relaxation: eps0 = 0.05, E_inf = 50 kPa, E1 = 100 kPa, eta = 200 kPa*s, t = 1 s")
→ stress = 5532.65 Pa, stress_inf = 2500 Pa
Static lever model of the forearm: muscle force and joint reactionbmed_elbow_lever_muscle_force

For a horizontal forearm held in static equilibrium, the elbow-flexor muscle force and the joint reaction force from the hand load, the forearm weight, their distances from the elbow and the muscle's insertion distance and angle.

F_m = \frac{W d_L + W_a d_a}{d_m \sin\theta},\quad R_x = F_m\cos\theta,\quad R_y = W + W_a - F_m\sin\theta

Inputs

  • W load held in the hand (weight) [N]
  • d_load distance of the load from the elbow [m]
  • W_arm weight of the forearm and hand [N]
  • d_arm distance of the forearm's centre of mass from the elbow [m]
  • d_muscle distance of the muscle insertion from the elbow [m]
  • theta angle between the muscle and the forearm [rad]

Returns

  • F_muscle muscle force [N]
  • R_x joint reaction along the forearm (towards the hand positive) [N]
  • R_y joint reaction, upward positive [N]
  • R magnitude of the joint reaction [N]

Applies when

  • static equilibrium in a vertical plane
  • forearm horizontal from the elbow, loads vertical
  • one muscle pulling up and back towards the elbow at angle theta
  • 0 < theta < 180 deg

Example

m.ask("Forearm lever muscle force: W = 50 N, d_load = 35 cm, W_arm = 15 N, d_arm = 15 cm, d_muscle = 4 cm, theta = 80 deg")
→ F_muscle = 501.367 N, R_x = 87.0614 N, R_y = -428.75 N, R = 437.5 N
Two-element Windkessel: diastolic pressure decaybmed_windkessel_diastolic_decay

The arterial pressure of a two-element Windkessel model during diastole (no inflow), decaying from P0 towards the venous pressure with time constant RC.

P(t) = P_v + (P_0 - P_v)\,e^{-t/(RC)}

Inputs

  • P0 pressure at the start of diastole [Pa]
  • Pv venous (outflow) pressure [Pa]
  • R peripheral resistance [Pa*s/m^3]
  • C arterial compliance [m^3/Pa]
  • t time into diastole [s]

Returns

  • P arterial pressure at time t [Pa]

Applies when

  • no inflow during diastole
  • linear resistance and compliance

Example

m.ask("Windkessel diastolic decay: P0 = 120 mmHg, Pv = 5 mmHg, R = 1 mmHg*s/mL, C = 1.5 mL/mmHg, t = 0.5 s")
→ P = 11652.5 Pa
Windkessel models (two- and three-element): input impedance at a frequencybmed_windkessel_input_impedance

The modulus and phase of the input impedance of a two-element (R, C) or three-element (Zc, R, C) Windkessel model of the arterial tree at a stated frequency.

Z(\omega) = Z_c + \frac{R}{1 + j\omega R C}

Inputs

  • model Windkessel model choice
  • R peripheral resistance [Pa*s/m^3]
  • C arterial compliance [m^3/Pa]
  • f frequency [Hz]
  • Zc characteristic impedance of the aorta (three-element model only) [Pa*s/m^3] optional

Returns

  • Z_mod impedance modulus [Pa*s/m^3]
  • phase_deg impedance phase in degrees

Applies when

  • linear model, sinusoidal steady state
  • Zc only for the three-element model

Example

m.ask("Windkessel impedance: model = two_element, R = 1 mmHg*s/mL, C = 1.5 mL/mmHg, f = 1.2 Hz")
→ Z_mod = 1.17425e+07 Pa*s/m^3, phase_deg = -84.9471

Diagnostic test statistics 5

Cohen's kappa for agreement between two raters or two testsbmed_cohens_kappa

Cohen's kappa (chance-corrected agreement) and the observed agreement of two raters or two diagnostic tests classifying the same subjects, from their k x k agreement table.

\kappa = \frac{p_o - p_e}{1 - p_e},\quad p_e = \sum_i \frac{n_{i\cdot}\,n_{\cdot i}}{n^2}

Inputs

  • counts agreement table: rows = categories given by rater A, columns = categories given by rater B matrix

Returns

  • kappa Cohen's kappa
  • p_observed observed proportion of agreement

Applies when

  • the same subjects rated by both
  • unweighted kappa
  • the same categories in rows and columns

Example

m.ask("Cohen's kappa: counts = [[40, 10], [5, 45]]")
→ kappa = 0.7, p_observed = 0.85
Optimal diagnostic cut-off by the Youden indexbmed_dx_youden_cutoff

The score threshold that maximises the Youden index J = sensitivity + specificity - 1 over all observed cut-offs, with the sensitivity and specificity there.

J(c) = \mathrm{Se}(c) + \mathrm{Sp}(c) - 1,\quad c^* = \arg\max_c J(c)

Inputs

  • scores_pos scores of the diseased subjects vector
  • scores_neg scores of the non-diseased subjects vector

Returns

  • threshold optimal cut-off (score >= threshold is test-positive)
  • sensitivity sensitivity at the cut-off
  • specificity specificity at the cut-off
  • J Youden index at the cut-off

Applies when

  • higher scores indicate disease
  • cut-offs at the observed scores
  • ties in J: the highest threshold (most specific)
  • some cut-off has J > 0

Example

m.ask("Youden cut-off: scores_pos = [0.9, 0.8, 0.7, 0.55, 0.4], scores_neg = [0.6, 0.45, 0.4, 0.3, 0.2, 0.1]")
→ threshold = 0.55, sensitivity = 0.8, specificity = 0.833333, J = 0.633333
ROC curve area of a diagnostic score (Mann-Whitney form)bmed_dx_roc_auc

The area under the ROC curve of a continuous diagnostic score from the scores of diseased and non-diseased subjects: the probability that a diseased subject scores higher (ties count one half), with the Mann-Whitney U.

AUC = \frac{1}{n_1 n_0}\sum_{i,j}\left[\mathbb{1}(x_i > y_j) + \tfrac12\mathbb{1}(x_i = y_j)\right]

Inputs

  • scores_pos scores of the diseased (condition-positive) subjects vector
  • scores_neg scores of the non-diseased subjects vector

Returns

  • AUC area under the ROC curve
  • U Mann-Whitney U of the diseased group

Applies when

  • higher scores indicate disease
  • ties count one half

Example

m.ask("ROC AUC: scores_pos = [0.9, 0.8, 0.7, 0.55, 0.4], scores_neg = [0.6, 0.45, 0.4, 0.3, 0.2, 0.1]")
→ AUC = 0.883333, U = 26.5
Sensitivity and specificity of a diagnostic score at a cut-offbmed_dx_threshold_sensitivity_specificity

The confusion-matrix counts, sensitivity and specificity of a continuous diagnostic score when scores at or above a threshold are called positive.

\mathrm{Se} = \frac{TP}{TP + FN},\quad \mathrm{Sp} = \frac{TN}{TN + FP}

Inputs

  • scores_pos scores of the diseased subjects vector
  • scores_neg scores of the non-diseased subjects vector
  • threshold cut-off: a score >= threshold is test-positive

Returns

  • sensitivity TP/(TP + FN)
  • specificity TN/(TN + FP)
  • TP true positives
  • FN false negatives
  • TN true negatives
  • FP false positives

Applies when

  • a score at or above the threshold is positive

Example

m.ask("Sensitivity and specificity at a cut-off: scores_pos = [0.9, 0.8, 0.7, 0.55, 0.4], scores_neg = [0.6, 0.45, 0.4, 0.3, 0.2, 0.1], threshold = 0.5")
→ sensitivity = 0.8, specificity = 0.833333, TP = 4, FN = 1, TN = 5, FP = 1
Sensitivity and specificity with Wilson score intervalsbmed_dx_sensitivity_specificity_ci

Sensitivity and specificity of a diagnostic test from its 2x2 counts, each with a Wilson score confidence interval at the stated level.

\frac{\hat p + \frac{z^2}{2n} \pm z\sqrt{\frac{\hat p(1-\hat p)}{n} + \frac{z^2}{4n^2}}}{1 + \frac{z^2}{n}}

Inputs

  • TP true positives integer
  • FN false negatives integer
  • TN true negatives integer
  • FP false positives integer
  • level confidence level (95% or 0.95)

Returns

  • sensitivity TP/(TP + FN)
  • sens_lower lower Wilson limit
  • sens_upper upper Wilson limit
  • specificity TN/(TN + FP)
  • spec_lower lower Wilson limit
  • spec_upper upper Wilson limit

Applies when

  • independent subjects
  • Wilson score interval (no continuity correction)
  • level stated

Example

m.ask("Sensitivity and specificity intervals: TP = 45, FN = 5, TN = 90, FP = 10, level = 95%")
→ sensitivity = 0.9, sens_lower = 0.786398, sens_upper = 0.956524, specificity = 0.9, spec_lower = 0.825634, spec_upper = 0.944771

Epidemic models 8

Reed-Frost chain-binomial epidemic: distribution and mean of the final sizebmed_epi_reed_frost_final_size

The probability distribution of the number of susceptibles eventually infected in a Reed-Frost chain-binomial epidemic in a small closed group, its mean and the chance of no spread.

S_{t+1} \sim \mathrm{Bin}\!\left(S_t, (1 - p)^{I_t}\right),\quad I_{t+1} = S_t - S_{t+1}

Inputs

  • n initial number of susceptibles (1 to 30) integer
  • m initial number of infectives (1 to 30) integer
  • p probability that one infective infects one given susceptible in a generation (0 < p < 1)

Returns

  • mean_final expected number of susceptibles infected
  • P_no_spread probability that no susceptible is infected
  • distribution probabilities of 0, 1, ..., n susceptibles infected

Applies when

  • discrete generations, each infective infectious for one generation
  • independent contacts

Example

m.ask("Reed-Frost final size: n = 4, m = 1, p = 0.2")
→ mean_final = 1.27014, P_no_spread = 0.4096, distribution = [0.4096, 0.2097152, 0.163577856, 0.1351614464, 0.0819454976]
Reproduction number from an epidemic growth rate (gamma-distributed generation interval)bmed_epi_r_from_growth_rate

The reproduction number implied by an observed exponential growth rate when the generation interval follows a gamma distribution of stated mean and standard deviation (Wallinga-Lipsitch).

R = \left(1 + r\,\frac{s^2}{\mu}\right)^{\mu^2/s^2}

Inputs

  • r exponential growth rate (negative for a decline) [1/s]
  • Tg_mean mean generation interval [s]
  • Tg_sd standard deviation of the generation interval [s]

Returns

  • R reproduction number

Applies when

  • exponential growth or decline
  • gamma-distributed generation interval

Example

m.ask("Reproduction number from growth rate: r = 0.1 1/day, Tg_mean = 5 day, Tg_sd = 2 day")
→ R = 1.6177
SEIR epidemic model: final sizebmed_epi_seir_final_size

The final susceptible fraction and the attack fraction of an SEIR epidemic (the latent stage does not change the final size) from R0 and the initial susceptible, exposed and infectious fractions.

\ln\frac{s_0}{s_\infty} = R_0\,(s_0 + e_0 + i_0 - s_\infty)

Inputs

  • R0 basic reproduction number beta/gamma
  • s0 initial susceptible fraction
  • e0 initial exposed (latent) fraction
  • i0 initial infectious fraction

Returns

  • s_inf susceptible fraction at the end
  • attack fraction infected during the epidemic, s0 - s_inf

Applies when

  • closed population, homogeneous mixing
  • exponentially distributed latent and infectious periods
  • e0 + i0 > 0

Example

m.ask("SEIR final size: R0 = 3, s0 = 0.98, e0 = 0.01, i0 = 0.01")
→ s_inf = 0.058078, attack = 0.921922
SEIR epidemic model: initial exponential growth rate from R0bmed_epi_seir_growth_rate

The early exponential growth (or decline) rate of an SEIR epidemic in a fully susceptible population, from R0, the rate of leaving the latent stage and the recovery rate.

r = \frac{-(\sigma + \gamma) + \sqrt{(\sigma + \gamma)^2 + 4\sigma\gamma(R_0 - 1)}}{2}

Inputs

  • R0 basic reproduction number beta/gamma
  • sigma rate of leaving the latent stage (1/latent period) [1/s]
  • gamma recovery rate (1/infectious period) [1/s]

Returns

  • r initial growth rate (negative when R0 < 1) [1/s]

Applies when

  • fully susceptible population at the start
  • exponential latent and infectious periods

Example

m.ask("SEIR growth rate: R0 = 2.5, sigma = 0.2 1/day, gamma = 0.1 1/day")
→ r = 9.15842e-07 1/s
SEIR epidemic model: peak prevalence and the time of the peakbmed_epi_seir_peak

The largest infectious fraction of an SEIR epidemic and the time at which it occurs, from the transmission, incubation and recovery rates and the initial fractions.

\dot s = -\beta s i,\ \dot e = \beta s i - \sigma e,\ \dot i = \sigma e - \gamma i;\quad t_{peak}:\ \sigma e = \gamma i

Inputs

  • beta transmission rate [1/s]
  • sigma rate of leaving the latent stage (1/latent period) [1/s]
  • gamma recovery rate [1/s]
  • s0 initial susceptible fraction
  • e0 initial exposed (latent) fraction
  • i0 initial infectious fraction

Returns

  • t_peak time of the peak of the infectious fraction [s]
  • i_max peak infectious fraction
  • s_at_peak susceptible fraction at the peak
  • e_at_peak exposed fraction at the peak

Applies when

  • closed population, homogeneous mixing, frequency-dependent transmission
  • R0 s0 > 1, e0 + i0 > 0
  • the peak is the first maximum of i after t = 0 and exceeds i0

Example

m.ask("SEIR peak: beta = 0.5 1/day, sigma = 0.2 1/day, gamma = 0.1 1/day, s0 = 0.99, e0 = 0.008, i0 = 0.002")
→ t_peak = 3.17722e+06 s, i_max = 0.30625, s_at_peak = 0.122176, e_at_peak = 0.153125
SIR epidemic model: final size (final susceptible fraction and attack fraction)bmed_epi_sir_final_size

The fraction still susceptible when an SIR epidemic ends and the fraction infected during it, from R0 and the initial susceptible and infected fractions (the final-size relation).

\ln\frac{s_0}{s_\infty} = R_0\,(s_0 + i_0 - s_\infty)

Inputs

  • R0 basic reproduction number beta/gamma
  • s0 initial susceptible fraction
  • i0 initial infected fraction (> 0)

Returns

  • s_inf susceptible fraction at the end
  • attack fraction infected during the epidemic, s0 - s_inf

Applies when

  • closed population, no births or deaths, homogeneous mixing
  • fractions of the population
  • the rest of the population (1 - s0 - i0) is immune

Example

m.ask("SIR final size: R0 = 2.5, s0 = 0.99, i0 = 0.01")
→ s_inf = 0.105894, attack = 0.884106
SIR epidemic model: peak prevalence and the time of the peakbmed_epi_sir_peak

The largest infected fraction of an SIR epidemic and the time at which it occurs, from the transmission and recovery rates and the initial fractions.

i_{max} = s_0 + i_0 - \frac{1 + \ln(R_0 s_0)}{R_0},\quad t_{peak} = \int_{1/R_0}^{s_0}\frac{ds}{\beta s\,i(s)}

Inputs

  • beta transmission rate [1/s]
  • gamma recovery rate [1/s]
  • s0 initial susceptible fraction
  • i0 initial infected fraction (> 0)

Returns

  • i_max peak infected fraction
  • t_peak time of the peak [s]

Applies when

  • closed population, homogeneous mixing, frequency-dependent transmission
  • R0 s0 > 1

Example

m.ask("SIR peak: beta = 0.3 1/day, gamma = 0.1 1/day, s0 = 0.999, i0 = 0.001")
→ i_max = 0.300796, t_peak = 3.3139e+06 s
SIS epidemic model: prevalence at a time and the endemic levelbmed_epi_sis_prevalence

The infected fraction of an SIS model (no immunity after recovery) at time t and the endemic equilibrium it approaches.

i(t) = \frac{i_0\,e^{rt}}{1 + i_0\,\beta\,(e^{rt} - 1)/r},\quad r = \beta - \gamma,\quad i^* = 1 - \gamma/\beta

Inputs

  • beta transmission rate [1/s]
  • gamma recovery rate [1/s]
  • i0 initial infected fraction
  • t time [s]

Returns

  • i infected fraction at time t
  • i_star endemic infected fraction (0 when beta <= gamma)

Applies when

  • closed population, homogeneous mixing
  • recovered individuals are susceptible again

Example

m.ask("SIS prevalence: beta = 0.4 1/day, gamma = 0.1 1/day, i0 = 0.01, t = 10 day")
→ i = 0.160111, i_star = 0.75

Epidemiological measures of association 6

Absolute risk reduction and number needed to treat with Wald intervalsbmed_nnt_ci

The absolute risk reduction (control risk minus treated risk) of a two-arm trial with its Wald confidence interval, and the number needed to treat with the interval obtained by inverting it.

ARR = p_c - p_t,\quad NNT = \frac{1}{ARR},\quad \mathrm{SE} = \sqrt{\tfrac{p_t(1-p_t)}{n_t} + \tfrac{p_c(1-p_c)}{n_c}}

Inputs

  • events_t events in the treated group integer
  • n_t size of the treated group integer
  • events_c events in the control group integer
  • n_c size of the control group integer
  • level confidence level (95% or 0.95)

Returns

  • ARR absolute risk reduction
  • ARR_lower lower limit
  • ARR_upper upper limit
  • NNT number needed to treat 1/ARR
  • NNT_lower 1/ARR_upper
  • NNT_upper 1/ARR_lower

Applies when

  • unpooled Wald interval for the difference of proportions
  • the interval excludes zero (a finite NNT interval)
  • level stated
  • NNT not rounded

Example

m.ask("Number needed to treat: events_t = 15, n_t = 100, events_c = 30, n_c = 100, level = 95%")
→ ARR = 0.15, ARR_lower = 0.0361364, ARR_upper = 0.263864, NNT = 6.66667, NNT_lower = 3.78984, NNT_upper = 27.6729
Incidence rate ratio of two person-time groups with log-Wald intervalbmed_incidence_rate_ratio_ci

The ratio of the incidence rates (events per person-time) of two groups with the log-scale Wald confidence interval at the stated level.

IRR = \frac{e_1/T_1}{e_2/T_2},\quad \mathrm{SE}(\ln IRR) = \sqrt{\tfrac1{e_1} + \tfrac1{e_2}}

Inputs

  • events1 events in group 1 integer
  • time1 person-time of group 1 (the same unit for both groups)
  • events2 events in group 2 (reference) integer
  • time2 person-time of group 2
  • level confidence level (95% or 0.95)

Returns

  • IRR incidence rate ratio group 1 / group 2
  • lower lower limit
  • upper upper limit

Applies when

  • Poisson counts
  • log-Wald interval
  • the same person-time unit for both groups
  • level stated

Example

m.ask("Incidence rate ratio: events1 = 30, time1 = 1000, events2 = 15, time2 = 1200, level = 95%")
→ IRR = 2.4, lower = 1.29133, upper = 4.46051
Mantel-Haenszel pooled odds ratio over strata with Robins-Breslow-Greenland intervalbmed_mantel_haenszel_odds_ratio

The Mantel-Haenszel odds ratio pooled over strata of 2x2 tables (adjusting for a confounder), with the Robins-Breslow-Greenland confidence interval at the stated level.

OR_{MH} = \frac{\sum_i a_i d_i / n_i}{\sum_i b_i c_i / n_i}

Inputs

  • tables one row [a, b, c, d] per stratum: exposed cases, exposed non-cases, unexposed cases, unexposed non-cases matrix
  • level confidence level (95% or 0.95)

Returns

  • OR_MH Mantel-Haenszel pooled odds ratio
  • lower lower limit
  • upper upper limit

Applies when

  • a common odds ratio across strata
  • Robins-Breslow-Greenland variance
  • level stated

Example

m.ask("Mantel-Haenszel odds ratio: tables = [[10, 20, 5, 30], [8, 12, 6, 20]], level = 95%")
→ OR_MH = 2.60776, lower = 1.08405, upper = 6.27313
Odds ratio of a 2x2 exposure-outcome table with Woolf (logit) intervalbmed_odds_ratio_ci

The odds ratio of an exposure-outcome 2x2 table (case-control or cohort) with the Woolf logit confidence interval at the stated level.

OR = \frac{ad}{bc},\quad \mathrm{SE}(\ln OR) = \sqrt{\tfrac1a + \tfrac1b + \tfrac1c + \tfrac1d}

Inputs

  • a exposed with the outcome integer
  • b exposed without the outcome integer
  • c unexposed with the outcome integer
  • d unexposed without the outcome integer
  • level confidence level (95% or 0.95)

Returns

  • OR odds ratio ad/(bc)
  • lower lower confidence limit
  • upper upper confidence limit

Applies when

  • no zero cell (no continuity correction)
  • Woolf interval exp(ln OR +- z SE)
  • level stated

Example

m.ask("Odds ratio with confidence interval: a = 20, b = 80, c = 10, d = 90, level = 95%")
→ OR = 2.25, lower = 0.994295, upper = 5.09155
Relative risk (risk ratio) of a cohort 2x2 table with log (Katz) intervalbmed_relative_risk_ci

The risk ratio of exposed to unexposed in a cohort 2x2 table with the log-scale (Katz) confidence interval at the stated level.

RR = \frac{a/(a+b)}{c/(c+d)},\quad \mathrm{SE}(\ln RR) = \sqrt{\tfrac1a - \tfrac1{a+b} + \tfrac1c - \tfrac1{c+d}}

Inputs

  • a exposed with the outcome integer
  • b exposed without the outcome integer
  • c unexposed with the outcome integer
  • d unexposed without the outcome integer
  • level confidence level (95% or 0.95)

Returns

  • RR risk ratio [a/(a + b)]/[c/(c + d)]
  • lower lower confidence limit
  • upper upper confidence limit

Applies when

  • cohort (risks estimable)
  • no zero cell
  • log interval exp(ln RR +- z SE)
  • level stated

Example

m.ask("Relative risk with confidence interval: a = 20, b = 80, c = 10, d = 90, level = 95%")
→ RR = 2, lower = 0.986563, upper = 4.05448
Standardized mortality (incidence) ratio with exact Poisson intervalbmed_smr_exact_ci

The standardized mortality or incidence ratio observed/expected with the exact (Garwood) Poisson confidence interval at the stated level.

\mathrm{SMR} = \frac{O}{E},\quad P(X \ge O;\lambda_L) = \tfrac{\alpha}{2},\ P(X \le O;\lambda_U) = \tfrac{\alpha}{2}

Inputs

  • observed observed number of deaths or cases (0 to 1000) integer
  • expected expected number from reference rates
  • level confidence level (95% or 0.95)

Returns

  • SMR observed / expected
  • lower lower exact limit
  • upper upper exact limit

Applies when

  • observed count Poisson
  • expected count treated as known
  • exact (Garwood) limits
  • level stated

Example

m.ask("Standardized mortality ratio: observed = 25, expected = 18.4, level = 95%")
→ SMR = 1.3587, lower = 0.879276, upper = 2.0057

Medical-imaging physics 14

CT number in Hounsfield unitsbmed_hounsfield_units

The CT number HU = 1000 (mu - mu_water)/(mu_water - mu_air) of a material from its linear attenuation coefficient and those of water and air (air 0 by default, then 1000 (mu - mu_water)/mu_water).

HU = 1000\,\frac{\mu - \mu_{water}}{\mu_{water} - \mu_{air}}

Inputs

  • mu linear attenuation coefficient of the material [1/m]
  • mu_water linear attenuation coefficient of water [1/m]
  • mu_air linear attenuation coefficient of air (default 0) [1/m] optional

Returns

  • HU CT number in Hounsfield units
  • mu_rel mu/mu_water

Applies when

  • coefficients at the same effective energy
  • 0 <= mu_air < mu_water

Example

m.ask("Hounsfield units: mu = 0.38 1/cm, mu_water = 0.19 1/cm")
→ HU = 1000, mu_rel = 2
Diffusion MRI: apparent diffusion coefficient from signals at several b-valuesbmed_mri_adc_fit

The apparent diffusion coefficient and the b = 0 signal from diffusion-weighted signals at two or more b-values, by a least-squares fit of ln S against b (mono-exponential decay).

\ln S = \ln S_0 - b\cdot ADC

Inputs

  • b b-values in s/mm^2 vector
  • S signals at those b-values (any one unit) vector

Returns

  • ADC apparent diffusion coefficient, mm^2/s
  • S0 fitted signal at b = 0 (unit of S)

Applies when

  • mono-exponential decay S = S0 exp(-b ADC)
  • unweighted least squares on ln S
  • b in s/mm^2

Example

m.ask("ADC fit: b = [0, 1000], S = [1200, 420]")
→ ADC = 0.00104982, S0 = 1200
Imaging resolution: MTF of a Gaussian point-spread functionbmed_gaussian_psf_mtf

The modulation transfer function at a spatial frequency of an imaging system with a Gaussian point-spread function of stated FWHM, and the frequency at which the MTF falls to 50 %.

\mathrm{MTF}(f) = e^{-2\pi^2\sigma^2 f^2},\quad \sigma = \frac{\mathrm{FWHM}}{2\sqrt{2\ln 2}}

Inputs

  • fwhm full width at half maximum of the point-spread function [m]
  • f spatial frequency (cycles per length) [1/m]

Returns

  • MTF modulation transfer at f
  • f50 spatial frequency where the MTF is 0.5 [1/m]

Applies when

  • Gaussian, shift-invariant point-spread function
  • one dimension (a line-spread function)

Example

m.ask("Gaussian PSF MTF: fwhm = 0.5 mm, f = 1 1/mm")
→ MTF = 0.410686, f50 = 882.542 1/m
Larmor (precession) frequency in a magnetic fieldbmed_larmor_frequency

The Larmor frequency f = (gamma/2 pi) B of nuclear spins in a field B: protons by default (42.577478461 MHz/T, CODATA 2022), or another nucleus with its stated gamma/2 pi in MHz/T.

f = \frac{\gamma}{2\pi}\,B_0

Inputs

  • B magnetic flux density (T) [T]
  • gamma_bar reduced gyromagnetic ratio gamma/2 pi in MHz/T (default: the proton) optional

Returns

  • f Larmor frequency [Hz]
  • f_MHz Larmor frequency in MHz
  • omega angular Larmor frequency [rad/s]

Applies when

  • B > 0
  • bare nucleus (no chemical shielding)

Example

m.ask("Larmor frequency: B = 1.5 T")
→ f = 6.38662e+07 Hz, f_MHz = 63.8662, omega = 4.01283e+08 rad/s
MRI Ernst angle (the flip angle of the largest spoiled gradient-echo signal)bmed_mri_ernst_angle

The Ernst angle alpha_E = arccos(exp(-TR/T1)) that maximises the steady-state signal of a spoiled gradient-echo sequence, and that largest signal as a fraction of M0 (T2* decay excluded).

\alpha_E = \arccos\left(e^{-TR/T_1}\right)

Inputs

  • TR repetition time [s]
  • T1 longitudinal relaxation time [s]

Returns

  • alpha Ernst angle [rad]
  • alpha_deg Ernst angle in degrees
  • S_rel signal at the Ernst angle, fraction of M0 (no T2* decay)

Applies when

  • ideal spoiling, steady state
  • TR, T1 > 0

Example

m.ask("Ernst angle: TR = 10 ms, T1 = 1000 ms")
→ alpha = 0.141186 rad, alpha_deg = 8.08935, S_rel = 0.0707104
MRI inversion recovery: longitudinal magnetisation at TI and the null pointbmed_mri_inversion_recovery

The longitudinal magnetisation (fraction of M0, signed) at inversion time TI in a repeated inversion-recovery sequence with repetition time TR, and the inversion time that nulls the tissue.

\frac{M_z(TI)}{M_0} = 1 - 2e^{-TI/T_1} + e^{-TR/T_1},\quad TI_{null} = T_1\ln\frac{2}{1 + e^{-TR/T_1}}

Inputs

  • T1 longitudinal relaxation time [s]
  • TR repetition time [s]
  • TI inversion time [s]

Returns

  • Mz_ratio Mz/M0 at TI (negative before the null)
  • TI_null inversion time of zero signal [s]

Applies when

  • ideal 180 degree inversion and 90 degree readout at TI
  • readout leaves Mz = 0
  • steady state, TI < TR

Example

m.ask("Inversion recovery: T1 = 250 ms, TR = 2000 ms, TI = 150 ms")
→ Mz_ratio = -0.0972878, TI_null = 0.173203 s
MRI multi-echo T2 estimate (log-linear fit)bmed_mri_t2_fit

The transverse relaxation time T2 and the extrapolated signal at TE = 0 from signals at several echo times, by a least-squares fit of ln S against TE.

\ln S = \ln S_0 - \frac{TE}{T_2}

Inputs

  • TE echo times in ms vector
  • S signals at those echo times (any one unit) vector

Returns

  • T2 transverse relaxation time, ms
  • S0 fitted signal at TE = 0 (unit of S)

Applies when

  • mono-exponential decay S = S0 exp(-TE/T2)
  • unweighted least squares on ln S
  • TE in ms

Example

m.ask("Multi-echo T2 fit: TE = [10, 30, 50, 80, 120], S = [905, 740, 605, 445, 300]")
→ T2 = 99.4459, S0 = 999.81
MRI spin-echo signal from T1, T2, TR and TE (simplified model)bmed_mri_spin_echo_signal

The steady-state spin-echo signal S = M0 (1 - exp(-TR/T1)) exp(-TE/T2) of a tissue with relaxation times T1 and T2, for repetition time TR and echo time TE.

S = M_0\left(1 - e^{-TR/T_1}\right)e^{-TE/T_2}

Inputs

  • M0 equilibrium magnetisation (relative proton density)
  • TR repetition time [s]
  • TE echo time [s]
  • T1 longitudinal relaxation time [s]
  • T2 transverse relaxation time [s]

Returns

  • S signal in the units of M0

Applies when

  • 90 degree excitations every TR, transverse magnetisation spoiled before each
  • ideal refocusing without effect on Mz (TE << TR)
  • TE < TR

Example

m.ask("Spin-echo signal: M0 = 1, TR = 500 ms, TE = 15 ms, T1 = 900 ms, T2 = 100 ms")
→ S = 0.366874
MRI spoiled gradient-echo signal (Ernst equation)bmed_mri_spoiled_gradient_echo

The steady-state signal of a spoiled gradient-echo sequence with flip angle alpha, repetition time TR and echo time TE for a tissue with T1 and T2*.

S = M_0 \sin\alpha\,\frac{1 - E_1}{1 - E_1\cos\alpha}\,e^{-TE/T_2^*},\quad E_1 = e^{-TR/T_1}

Inputs

  • M0 equilibrium magnetisation (relative proton density)
  • TR repetition time [s]
  • TE echo time [s]
  • T1 longitudinal relaxation time [s]
  • T2star effective transverse relaxation time T2* [s]
  • alpha flip angle [rad]

Returns

  • S signal in the units of M0

Applies when

  • ideal spoiling of transverse magnetisation before each pulse
  • steady state
  • 0 < alpha <= 90 deg, TE < TR

Example

m.ask("Spoiled gradient-echo signal: M0 = 1, TR = 10 ms, TE = 3 ms, T1 = 1000 ms, T2star = 40 ms, alpha = 8 deg")
→ S = 0.065597
Signal-to-noise ratio gained by signal averagingbmed_snr_averaging

The signal-to-noise ratio after averaging N acquisitions with independent noise, SNR_N = SNR_1 sqrt(N), or the smallest number of averages that reaches a target SNR.

SNR_N = SNR_1\sqrt{N}

Inputs

  • SNR1 signal-to-noise ratio of one acquisition
  • N number of averages (give N or SNR_target) integer optional
  • SNR_target target SNR (give N or SNR_target) optional

Returns

  • SNR SNR after averaging
  • gain SNR gain sqrt(N)
  • N number of averages

Applies when

  • independent, zero-mean noise of equal variance in every acquisition
  • an identical signal

Example

m.ask("SNR averaging: SNR1 = 10, N = 16")
→ SNR = 40, gain = 4, N = 16
Ultrasound reflection and transmission at a tissue interface (normal incidence)bmed_ultrasound_interface

The intensity reflection and transmission coefficients and the pressure amplitude coefficients of an ultrasound wave meeting a flat interface between two media at normal incidence.

R = \left(\frac{Z_2 - Z_1}{Z_2 + Z_1}\right)^2,\quad T = \frac{4 Z_1 Z_2}{(Z_1 + Z_2)^2}

Inputs

  • Z1 acoustic impedance of the first medium [kg/(m^2*s)]
  • Z2 acoustic impedance of the second medium [kg/(m^2*s)]

Returns

  • R intensity reflection coefficient
  • T intensity transmission coefficient
  • r_p pressure reflection coefficient
  • t_p pressure transmission coefficient

Applies when

  • normal incidence on a flat interface
  • lossless media, plane waves

Example

m.ask("Ultrasound interface reflection: Z1 = 1.63 MRayl, Z2 = 7.8 MRayl")
→ R = 0.428102, T = 0.571898, r_p = 0.654295, t_p = 1.65429
Ultrasound transmission through a matching layer (normal incidence)bmed_ultrasound_matching_layer

The intensity transmission coefficient from a transducer (impedance Z1) through a matching layer (impedance Zm, thickness d, sound speed c_m) into tissue (Z2) at frequency f, and the layer's phase thickness.

T = \frac{4 Z_1 Z_2}{(Z_1 + Z_2)^2\cos^2 kd + \left(Z_m + \frac{Z_1 Z_2}{Z_m}\right)^2\sin^2 kd}

Inputs

  • Z1 impedance of the source medium (transducer) [kg/(m^2*s)]
  • Zm impedance of the matching layer [kg/(m^2*s)]
  • Z2 impedance of the load medium (tissue) [kg/(m^2*s)]
  • d layer thickness [m]
  • c_m sound speed in the layer [m/s]
  • f frequency [Hz]

Returns

  • T intensity transmission coefficient
  • kd phase thickness of the layer (rad)

Applies when

  • normal incidence, plane waves, lossless layers
  • semi-infinite source and load media

Example

m.ask("Ultrasound matching layer: Z1 = 30 MRayl, Zm = 6.9 MRayl, Z2 = 1.6 MRayl, d = 0.15 mm, c_m = 2400 m/s, f = 4 MHz")
→ T = 0.999983, kd = 1.5708
Ultrasound wavelength in tissuebmed_ultrasound_wavelength

The wavelength lambda = c/f of ultrasound of frequency f in a medium with speed of sound c (1540 m/s, the soft-tissue convention, by default), with the period and wavenumber.

\lambda = \frac{c}{f}

Inputs

  • f ultrasound frequency [Hz]
  • c speed of sound (default 1540 m/s) [m/s] optional

Returns

  • wavelength wavelength [m]
  • wavelength_mm wavelength in mm
  • period period 1/f [s]
  • k wavenumber 2 pi/lambda [1/m]

Applies when

  • f, c > 0
  • c = 1540 m/s unless stated

Example

m.ask("Ultrasound wavelength: f = 5 MHz")
→ wavelength = 0.000308 m, wavelength_mm = 0.308, period = 2e-07 s, k = 20400 1/m
X-ray attenuation through tissue layers (narrow monoenergetic beam)bmed_xray_attenuation_layers

The transmitted fraction and intensity of a narrow monoenergetic X-ray beam crossing successive tissue layers, from each layer's mass attenuation coefficient, density and thickness.

\frac{I}{I_0} = \exp\left(-\sum_i \left(\frac{\mu}{\rho}\right)_i \rho_i x_i\right)

Inputs

  • I0 incident intensity [W/m^2]
  • mu_rho mass attenuation coefficient of each layer, cm^2/g vector
  • rho density of each layer, g/cm^3 vector
  • x thickness of each layer, cm vector

Returns

  • T transmitted fraction
  • I transmitted intensity [W/m^2]

Applies when

  • narrow beam (no scatter reaching the detector)
  • one photon energy
  • units cm^2/g, g/cm^3, cm

Example

m.ask("X-ray attenuation through layers: I0 = 1000 W/m^2, mu_rho = [0.2, 0.5, 0.2], rho = [1, 1.85, 1], x = [2, 1, 3]")
→ T = 0.145876, I = 145.876 W/m^2

Neuron models 10

FitzHugh-Nagumo neuron model: fixed point and its stabilitybmed_fitzhugh_nagumo_fixed_point

The resting (fixed) point of the FitzHugh-Nagumo model v' = v - v^3/3 - w + I, w' = eps (v + a - b w), the trace and determinant of its Jacobian and whether it is stable (resting) or unstable (repetitive firing).

v - \frac{v^3}{3} - \frac{v + a}{b} + I = 0,\quad J = \begin{pmatrix}1 - v^2 & -1\\ \varepsilon & -\varepsilon b\end{pmatrix}

Inputs

  • a parameter a
  • b parameter b (0 < b < 1)
  • eps time-scale ratio eps (> 0)
  • I applied current (dimensionless)

Returns

  • v_star fixed-point v
  • w_star fixed-point w
  • trace trace of the Jacobian
  • determinant determinant of the Jacobian
  • stable true when the fixed point is stable

Applies when

  • dimensionless FitzHugh-Nagumo model
  • 0 < b < 1 (a unique fixed point)

Example

m.ask("FitzHugh-Nagumo fixed point: a = 0.7, b = 0.8, eps = 0.08, I = 0")
→ v_star = -1.19941, w_star = -0.62426, trace = -0.50258, determinant = 0.108069, stable = True
Goldman-Hodgkin-Katz current equation: ionic current density through a membranebmed_ghk_current_density

The current density carried by one ion species through a membrane of given permeability at a stated membrane potential, from the GHK current (constant-field) equation; outward current positive.

I = P z^2 \frac{F^2 V}{RT}\,\frac{[C]_i - [C]_o e^{-zFV/RT}}{1 - e^{-zFV/RT}}

Inputs

  • P membrane permeability to the ion [m/s]
  • z valence of the ion (+1, +2, -1, ...) integer
  • C_in inside concentration [mol/m^3]
  • C_out outside concentration [mol/m^3]
  • V membrane potential, inside relative to outside [V]
  • T absolute temperature (or degC) [K]

Returns

  • I current density, outward positive [A/m^2]

Applies when

  • constant field across the membrane
  • independent ion movement
  • outward current positive

Example

m.ask("GHK current density: P = 1e-8 m/s, z = 1, C_in = 140 mmol/L, C_out = 4 mmol/L, V = -20 mV, T = 310 K")
→ I = 0.0852825 A/m^2
Goldman-Hodgkin-Katz voltage equation: membrane potential from K, Na and Clbmed_ghk_voltage

The resting membrane potential of the Goldman-Hodgkin-Katz voltage equation from the relative permeabilities and the inside and outside concentrations of K+, Na+ and Cl-.

V_m = \frac{RT}{F}\ln\frac{P_K[K^+]_o + P_{Na}[Na^+]_o + P_{Cl}[Cl^-]_i}{P_K[K^+]_i + P_{Na}[Na^+]_i + P_{Cl}[Cl^-]_o}

Inputs

  • T absolute temperature (or degC) [K]
  • PK relative permeability to K+ (> 0)
  • PNa relative permeability to Na+
  • PCl relative permeability to Cl-
  • K_o outside K+ [mol/m^3]
  • K_i inside K+ [mol/m^3]
  • Na_o outside Na+ [mol/m^3]
  • Na_i inside Na+ [mol/m^3]
  • Cl_o outside Cl- [mol/m^3]
  • Cl_i inside Cl- [mol/m^3]

Returns

  • V_m membrane potential, inside relative to outside [V]

Applies when

  • steady state with zero net current
  • constant field in the membrane, independent ions
  • only K+, Na+ and Cl- permeate
  • only ratios of permeabilities matter

Example

m.ask("GHK voltage: T = 310 K, PK = 1, PNa = 0.04, PCl = 0.45, K_o = 4 mmol/L, K_i = 140 mmol/L, Na_o = 145 mmol/L, Na_i = 12 mmol/L, Cl_o = 116 mmol/L, Cl_i = 4 mmol/L")
→ V_m = -0.0750663 V
Hodgkin-Huxley model: potassium conductance after a voltage-clamp stepbmed_hh_potassium_conductance_clamp

The potassium conductance gK = gK_max n^4 and the gate n a time t after the membrane is stepped from a holding potential (at steady state) to a new clamped potential, in the Hodgkin-Huxley model.

n(t) = n_\infty - (n_\infty - n_0)e^{-t/\tau_n},\quad g_K = \bar g_K n^4

Inputs

  • gK_max maximal K conductance [S/m^2]
  • V_hold holding potential before the step [V]
  • V_step clamped potential after the step [V]
  • t time after the step [s]

Returns

  • g_K K conductance at time t [S/m^2]
  • n K gate n at time t

Applies when

  • ideal voltage clamp
  • gates at steady state at the holding potential
  • Hodgkin-Huxley 1952 rate functions

Example

m.ask("Hodgkin-Huxley potassium conductance: gK_max = 36 mS/cm^2, V_hold = -65 mV, V_step = 0 mV, t = 2 ms")
→ g_K = 104.172 S/m^2, n = 0.733436
Hodgkin-Huxley model: steady-state gating variables at a membrane potentialbmed_hh_gating_steady_state

The steady-state values of the Hodgkin-Huxley gating variables m, h and n at a clamped membrane potential, from the 1952 squid-axon rate functions.

x_\infty(V) = \frac{\alpha_x(V)}{\alpha_x(V) + \beta_x(V)}

Inputs

  • V clamped membrane potential [V]

Returns

  • m_inf Na activation at steady state
  • h_inf Na inactivation at steady state
  • n_inf K activation at steady state

Applies when

  • Hodgkin-Huxley 1952 rate functions, modern convention (rest near -65 mV), 6.3 degC
  • -150 mV <= V <= +100 mV

Example

m.ask("Hodgkin-Huxley gating steady state: V = -65 mV")
→ m_inf = 0.0529325, h_inf = 0.596121, n_inf = 0.317677
Hodgkin-Huxley model: zero-current steady (resting) membrane potentialbmed_hh_resting_potential

The membrane potential at which the steady-state Na, K and leak currents of the Hodgkin-Huxley model sum to zero (the resting potential), from the maximal conductances and reversal potentials.

\bar g_{Na} m_\infty^3 h_\infty (V - E_{Na}) + \bar g_K n_\infty^4 (V - E_K) + g_L (V - E_L) = 0

Inputs

  • gNa maximal Na conductance [S/m^2]
  • gK maximal K conductance [S/m^2]
  • gL leak conductance [S/m^2]
  • ENa Na reversal potential [V]
  • EK K reversal potential [V]
  • EL leak reversal potential [V]

Returns

  • V_rest zero-current steady-state potential [V]

Applies when

  • Hodgkin-Huxley 1952 rate functions (modern convention), gates at steady state
  • a unique zero-current potential between -120 and +60 mV (checked)
  • that state stable (Routh-Hurwitz test of the linearised model; otherwise refused)
  • EK < EL < ENa

Example

m.ask("Hodgkin-Huxley resting potential: gNa = 120 mS/cm^2, gK = 36 mS/cm^2, gL = 0.3 mS/cm^2, ENa = 50 mV, EK = -77 mV, EL = -54.387 mV")
→ V_rest = -0.0649964 V
Leaky integrate-and-fire neuron: firing rate under constant currentbmed_lif_firing_rate

The interspike interval and firing rate of a leaky integrate-and-fire neuron driven by a constant current, with reset and an absolute refractory period.

T = t_{ref} + \tau_m \ln\frac{V_\infty - V_{reset}}{V_\infty - V_{th}},\quad V_\infty = V_{rest} + R_m I

Inputs

  • tau_m membrane time constant [s]
  • R_m membrane resistance [ohm]
  • I constant input current [A]
  • V_rest resting potential [V]
  • V_th spike threshold [V]
  • V_reset reset potential [V]
  • t_ref absolute refractory period [s]

Returns

  • rate firing rate [Hz]
  • ISI interspike interval [s]

Applies when

  • V_rest + R I > V_th (otherwise no firing)
  • V_reset < V_th
  • deterministic constant input

Example

m.ask("LIF firing rate: tau_m = 20 ms, R_m = 100 Mohm, I = 0.3 nA, V_rest = -70 mV, V_th = -50 mV, V_reset = -70 mV, t_ref = 2 ms")
→ rate = 41.7149 Hz, ISI = 0.0239722 s
Passive cable (dendrite or axon): steady-state voltage along it and input resistancebmed_cable_steady_state

The steady-state voltage at distance x along a passive cylindrical cable held at V0 at x = 0, and the input resistance there, for a sealed end, a killed (short-circuited) end or a semi-infinite cable.

\lambda = \sqrt{\frac{R_m d}{4 R_i}},\quad V(x) = V_0\frac{\cosh((L - x)/\lambda)}{\cosh(L/\lambda)}\ \text{(sealed)}

Inputs

  • Rm specific membrane resistance [ohm*m^2]
  • Ri axial (cytoplasmic) resistivity [ohm*m]
  • d cable diameter [m]
  • x distance from the stimulated end [m]
  • V0 steady voltage at x = 0 (relative to rest) [V]
  • end far-end condition choice
  • L cable length (sealed or killed end only) [m] optional

Returns

  • V_x voltage at x (relative to rest) [V]
  • R_in input resistance at x = 0 [ohm]

Applies when

  • passive membrane, steady state
  • uniform cylinder
  • L only for a finite cable

Example

m.ask("Cable steady state: Rm = 20000 ohm*cm^2, Ri = 100 ohm*cm, d = 2 um, x = 300 um, V0 = 10 mV, end = sealed, L = 1 mm")
→ V_x = 0.00813418 V, R_in = 4.17952e+08 ohm
Passive membrane (leaky integrator): voltage at a time under constant currentbmed_lif_subthreshold_voltage

The membrane potential of a passive RC membrane (the subthreshold leaky integrate-and-fire neuron) a time t after a constant current starts, from its initial potential.

V(t) = V_\infty + (V_0 - V_\infty)e^{-t/\tau_m},\quad V_\infty = V_{rest} + R_m I

Inputs

  • tau_m membrane time constant [s]
  • R_m membrane resistance [ohm]
  • I constant input current [A]
  • V_rest resting potential [V]
  • V0 potential at t = 0 [V]
  • t time [s]

Returns

  • V membrane potential at time t [V]

Applies when

  • passive membrane, no spike or threshold
  • constant current from t = 0

Example

m.ask("Passive membrane voltage: tau_m = 20 ms, R_m = 100 Mohm, I = 0.15 nA, V_rest = -70 mV, V0 = -70 mV, t = 10 ms")
→ V = -0.064098 V
Postsynaptic potential of a passive membrane driven by an exponentially decaying synaptic currentbmed_postsynaptic_potential

The postsynaptic potential of a passive RC membrane receiving a synaptic current I0 exp(-t/tau_s) at t = 0: its value at time t, the time of its peak and the peak value.

V(t) = \frac{R I_0 \tau_s}{\tau_s - \tau_m}\left(e^{-t/\tau_s} - e^{-t/\tau_m}\right),\quad t_{peak} = \frac{\tau_m\tau_s}{\tau_s - \tau_m}\ln\frac{\tau_s}{\tau_m}

Inputs

  • tau_m membrane time constant [s]
  • tau_s synaptic current decay time constant [s]
  • R_m membrane resistance [ohm]
  • I0 peak synaptic current (negative for inward) [A]
  • t time after the synaptic event [s]

Returns

  • V_t potential change at time t [V]
  • t_peak time of the peak [s]
  • V_peak peak potential change [V]

Applies when

  • passive membrane starting at rest
  • current jumps to I0 and decays exponentially
  • tau_s != tau_m

Example

m.ask("Postsynaptic potential: tau_m = 20 ms, tau_s = 5 ms, R_m = 100 Mohm, I0 = 50 pA, t = 10 ms")
→ V_t = 0.000785326 V, t_peak = 0.00924196 s, V_peak = 0.000787451 V

Pharmacokinetic data analysis 4

Absolute bioavailability from IV and oral concentration profiles (a model calculation, not medical advice)bmed_pk_bioavailability_from_profiles

The absolute bioavailability F from the dose-normalised areas under an oral and an IV concentration-time profile (linear trapezoids from the first to the last sample).

F = \frac{AUC_{oral}\,D_{iv}}{AUC_{iv}\,D_{oral}}

Inputs

  • D_iv IV dose [kg]
  • t_iv IV sampling times (one time unit for both profiles) vector
  • C_iv IV concentrations (one concentration unit for both profiles) vector
  • D_oral oral dose [kg]
  • t_oral oral sampling times vector
  • C_oral oral concentrations vector

Returns

  • AUC_iv IV area (units of the lists)
  • AUC_oral oral area (units of the lists)
  • F absolute bioavailability (AUC_oral/D_oral)/(AUC_iv/D_iv)

Applies when

  • linear pharmacokinetics (dose-proportional areas)
  • both profiles sampled to a comparable end
  • areas to the last sample, no extrapolation
  • the same units in both profiles

Example

m.ask("Bioavailability from profiles: D_iv = 100 mg, t_iv = [0, 1, 2, 4, 8, 12], C_iv = [10, 8.2, 6.7, 4.5, 2, 0.9], D_oral = 200 mg, t_oral = [0, 1, 2, 4, 8, 12], C_oral = [0, 6.1, 8, 7.2, 3.9, 1.8]")
→ AUC_iv = 46.55, AUC_oral = 58.9, F = 0.632653
AUC from concentration-time data by the trapezoidal rulebmed_pk_auc_trapezoid

The area under a sampled concentration-time curve from the first to the last sample, by the linear trapezoidal rule or the linear-up/log-down rule (stated).

AUC = \sum_i \frac{(C_i + C_{i+1})\,\Delta t_i}{2}\quad\text{or}\quad \frac{(C_i - C_{i+1})\,\Delta t_i}{\ln(C_i/C_{i+1})}

Inputs

  • t sampling times, strictly increasing, in one time unit vector
  • C concentrations at those times, in one concentration unit vector
  • method linear trapezoids, or linear while rising and logarithmic while falling choice

Returns

  • AUC area from the first to the last sample, in (unit of C) x (unit of t)

Applies when

  • times strictly increasing
  • concentrations >= 0
  • log-down segments need both concentrations positive (otherwise linear)

Example

m.ask("AUC by the trapezoidal rule: t = [0, 0.5, 1, 2, 4, 6, 8, 12], C = [0, 4.2, 6.8, 7.9, 6.1, 4.3, 3, 1.5], method = linear")
→ AUC = 51.85
Elimination rate constant and half-life from concentration data (log-linear fit)bmed_pk_terminal_half_life_fit

The first-order elimination rate constant, half-life and back-extrapolated concentration from a straight-line least-squares fit of ln C against time (mono-exponential decline).

\ln C = \ln C_0 - k t,\quad t_{1/2} = \frac{\ln 2}{k}

Inputs

  • t sampling times, in one time unit (results are per that unit) vector
  • C concentrations at those times, in one concentration unit (C0 is in that unit) vector

Returns

  • k elimination rate constant, per time unit of t
  • t_half half-life, in the time unit of t
  • C0 back-extrapolated concentration at t = 0, in the unit of C

Applies when

  • mono-exponential decline over the sampled times
  • all concentrations positive
  • unweighted least squares on ln C
  • at least three points

Example

m.ask("Terminal half-life fit: t = [1, 2, 4, 6, 8, 12], C = [8.2, 6.9, 4.8, 3.4, 2.4, 1.2]")
→ k = 0.174805, t_half = 3.96526, C0 = 9.73505
Non-compartmental analysis of an IV bolus profile (AUC, lambda_z, half-life, clearance, Vz)bmed_pk_nca_iv_bolus

Non-compartmental parameters from a concentration-time profile after an IV bolus: AUC to the last sample (linear trapezoids), terminal rate constant from the last n points, half-life, AUC to infinity, clearance and terminal volume.

AUC_{0-\infty} = AUC_{0-t_{last}} + \frac{C_{last}}{\lambda_z},\quad CL = \frac{D}{AUC_{0-\infty}},\quad V_z = \frac{CL}{\lambda_z}

Inputs

  • D IV bolus dose [kg]
  • t sampling times in h, the first at 0 (measured or back-extrapolated C0) vector
  • C concentrations in mg/L at those times vector
  • n_terminal number of last points used for the terminal slope (3 to n - 1) integer

Returns

  • AUC_last AUC from 0 to the last sample, mg*h/L
  • lambda_z terminal rate constant, 1/h
  • t_half terminal half-life, h
  • AUC_inf AUC from 0 to infinity (observed C_last / lambda_z added), mg*h/L
  • CL clearance D / AUC_inf, L/h
  • Vz terminal volume CL / lambda_z, L

Applies when

  • linear trapezoidal rule
  • lambda_z by unweighted least squares on ln C of the last n points
  • extrapolation with the observed last concentration
  • times in h, concentrations in mg/L

Example

m.ask("Non-compartmental analysis of an IV bolus: D = 100 mg, t = [0, 0.25, 0.5, 1, 2, 4, 6, 8, 12, 24], C = [5, 4, 3.3, 2.44, 1.72, 1.25, 0.974, 0.766, 0.474, 0.112], n_terminal = 4")
→ AUC_last = 18.4825, lambda_z = 0.120166, t_half = 5.76825, AUC_inf = 19.4145, CL = 5.15078, Vz = 42.8639

Pharmacokinetic models 20

Area under the concentration curve of a one-compartment IV bolus (a model calculation, not medical advice)bmed_pk_auc_iv_bolus

The area under the plasma concentration-time curve from 0 to infinity and from 0 to t after an IV bolus in a one-compartment model.

AUC_{0-\infty} = \frac{D}{CL},\quad AUC_{0-t} = \frac{D}{CL}\left(1 - e^{-CL\,t/V}\right)

Inputs

  • D bolus dose [kg]
  • CL clearance [m^3/s]
  • V volume of distribution [m^3]
  • t end of the partial area [s]

Returns

  • AUC_inf area from 0 to infinity [kg*s/m^3]
  • AUC_0_t area from 0 to t [kg*s/m^3]

Applies when

  • one compartment
  • first-order elimination k = CL/V

Example

m.ask("AUC of an IV bolus: D = 500 mg, CL = 5 L/h, V = 40 L, t = 8 h")
→ AUC_inf = 360 kg*s/m^3, AUC_0_t = 227.563 kg*s/m^3
Constant infusion: time to reach a fraction of steady state (a model calculation, not medical advice)bmed_pk_time_to_steady_state_fraction

The time after the start of a constant-rate infusion at which a one-compartment model reaches a stated fraction of its steady-state concentration.

t_f = -\frac{\ln(1 - f)}{CL/V}

Inputs

  • CL clearance [m^3/s]
  • V volume of distribution [m^3]
  • f fraction of steady state (90% or 0.9)

Returns

  • t time to reach f of steady state [s]

Applies when

  • one compartment, first-order elimination
  • no drug at the start
  • 0 < f < 1

Example

m.ask("Time to fraction of steady state: CL = 5 L/h, V = 40 L, f = 90%")
→ t = 66314.5 s
Constant-rate IV infusion: concentration at a time and steady state (a model calculation, not medical advice)bmed_pk_infusion_concentration

The plasma concentration of a one-compartment model during a constant-rate intravenous infusion started at t = 0, and the steady-state concentration it approaches.

C(t) = \frac{R_0}{CL}\left(1 - e^{-CL\,t/V}\right),\quad C_{ss} = \frac{R_0}{CL}

Inputs

  • R0 infusion rate [kg/s]
  • CL clearance [m^3/s]
  • V volume of distribution [m^3]
  • t time since the start of the infusion [s]

Returns

  • C concentration at time t [kg/m^3]
  • C_ss steady-state concentration R0/CL [kg/m^3]

Applies when

  • one compartment, first-order elimination
  • infusion still running at t
  • no drug at t = 0

Example

m.ask("Infusion concentration: R0 = 50 mg/h, CL = 5 L/h, V = 40 L, t = 6 h")
→ C = 0.00527633 kg/m^3, C_ss = 0.01 kg/m^3
Effect-compartment model: effect-site concentration and its peak after an IV bolus (a model calculation, not medical advice)bmed_pk_effect_site_concentration

The effect-site concentration of a one-compartment model linked to an effect compartment (rate ke0) after an IV bolus, the time of its peak and the peak value.

C_e(t) = \frac{D}{V}\,\frac{k_{e0}}{k_{e0} - k}\left(e^{-k t} - e^{-k_{e0} t}\right),\quad t_{peak} = \frac{\ln(k_{e0}/k)}{k_{e0} - k}

Inputs

  • D bolus dose [kg]
  • V volume of distribution [m^3]
  • k elimination rate constant [1/s]
  • ke0 effect-site equilibration rate constant [1/s]
  • t time after the dose [s]

Returns

  • Ce effect-site concentration at time t [kg/m^3]
  • t_peak time of the effect-site peak [s]
  • Ce_peak peak effect-site concentration [kg/m^3]

Applies when

  • one compartment plus an effect compartment of negligible volume
  • ke0 != k

Example

m.ask("Effect-site concentration: D = 10 mg, V = 20 L, k = 0.3 1/h, ke0 = 2 1/h, t = 30 min")
→ Ce = 0.000289899 kg/m^3, t_peak = 4017.43 s, Ce_peak = 0.000357746 kg/m^3
Hepatic clearance: parallel-tube (sinusoidal) liver model (a model calculation, not medical advice)bmed_pk_hepatic_clearance_parallel_tube

The hepatic clearance and extraction ratio of the parallel-tube liver model, in which the concentration falls along the sinusoids, from blood flow, unbound fraction and intrinsic clearance.

CL_H = Q\left(1 - e^{-f_u CL_{int}/Q}\right)

Inputs

  • Q hepatic blood flow [m^3/s]
  • fu unbound fraction in blood (0 < fu <= 1)
  • CL_int intrinsic clearance of unbound drug [m^3/s]

Returns

  • CL_H hepatic clearance [m^3/s]
  • E extraction ratio

Applies when

  • plug flow along identical sinusoids, enzymes evenly distributed
  • linear elimination

Example

m.ask("Parallel-tube hepatic clearance: Q = 90 L/h, fu = 0.1, CL_int = 500 L/h")
→ CL_H = 1.06562e-05 m^3/s, E = 0.426247
Hepatic clearance: well-stirred liver model (a model calculation, not medical advice)bmed_pk_hepatic_clearance_well_stirred

The hepatic clearance and extraction ratio of the well-stirred (venous equilibrium) liver model from hepatic blood flow, unbound fraction and intrinsic clearance.

CL_H = \frac{Q\,f_u\,CL_{int}}{Q + f_u\,CL_{int}}

Inputs

  • Q hepatic blood flow [m^3/s]
  • fu unbound fraction in blood (0 < fu <= 1)
  • CL_int intrinsic clearance of unbound drug [m^3/s]

Returns

  • CL_H hepatic clearance [m^3/s]
  • E extraction ratio

Applies when

  • well-stirred liver: outflow concentration equals the liver concentration
  • linear elimination

Example

m.ask("Well-stirred hepatic clearance: Q = 90 L/h, fu = 0.1, CL_int = 500 L/h")
→ CL_H = 8.92857e-06 m^3/s, E = 0.357143
Infusion of fixed duration: concentration during and after it (a model calculation, not medical advice)bmed_pk_short_infusion

The plasma concentration of a one-compartment model at time t after the start of a constant-rate infusion lasting T_inf (during or after the infusion), and the concentration at the end of the infusion.

C(t) = \begin{cases}\frac{R_0}{CL}(1 - e^{-kt}) & t \le T\\ \frac{R_0}{CL}(1 - e^{-kT})\,e^{-k(t - T)} & t > T\end{cases}

Inputs

  • R0 infusion rate [kg/s]
  • T_inf duration of the infusion [s]
  • CL clearance [m^3/s]
  • V volume of distribution [m^3]
  • t time since the start of the infusion [s]

Returns

  • C concentration at time t [kg/m^3]
  • C_end concentration at the end of the infusion [kg/m^3]

Applies when

  • one compartment, first-order elimination
  • single infusion, no drug before it

Example

m.ask("Short infusion concentration: R0 = 200 mg/h, T_inf = 1 h, CL = 6 L/h, V = 30 L, t = 4 h")
→ C = 0.00331609 kg/m^3, C_end = 0.00604231 kg/m^3
Loading dose and maintenance infusion rate of a one-compartment model (model calculation, not a dosing recommendation)bmed_pk_loading_maintenance

For a one-compartment model, the bolus and the constant infusion rate that together hold the model concentration at a target value from the start (model calculation only, not a dosing recommendation).

LD = C_{target} V,\quad R_0 = C_{target}\,CL

Inputs

  • C_target target model concentration [kg/m^3]
  • V volume of distribution [m^3]
  • CL clearance [m^3/s]

Returns

  • LD loading bolus of the model [kg]
  • R0 maintenance infusion rate of the model [kg/s]

Applies when

  • one compartment, first-order elimination
  • bolus and infusion start together

Example

m.ask("Loading dose and maintenance rate model: C_target = 15 mg/L, V = 50 L, CL = 4 L/h")
→ LD = 0.00075 kg, R0 = 1.66667e-08 kg/s
Michaelis-Menten (saturable) elimination: concentration at a time (a model calculation, not medical advice)bmed_pk_michaelis_menten_concentration

The concentration a time t after an IV bolus in a one-compartment model with saturable Michaelis-Menten elimination, from the closed form with the Lambert W function.

C(t) = K_m\,W\!\left(\frac{C_0}{K_m}\exp\frac{C_0 - V_{max} t / V}{K_m}\right)

Inputs

  • C0 initial concentration [kg/m^3]
  • Vmax maximum elimination rate (amount per time) [kg/s]
  • Km Michaelis constant [kg/m^3]
  • V volume of distribution [m^3]
  • t time after the dose [s]

Returns

  • C concentration at time t [kg/m^3]

Applies when

  • one compartment
  • elimination rate Vmax C/(Km + C)
  • no other elimination

Example

m.ask("Michaelis-Menten concentration: C0 = 20 mg/L, Vmax = 500 mg/day, Km = 4 mg/L, V = 50 L, t = 2 day")
→ C = 0.0053069 kg/m^3
Michaelis-Menten elimination: steady-state concentration under a constant dosing rate (a model calculation, not medical advice)bmed_pk_michaelis_menten_steady_state

The steady-state concentration of a one-compartment model with Michaelis-Menten elimination given a constant dosing rate below Vmax.

C_{ss} = \frac{K_m R_0}{V_{max} - R_0}

Inputs

  • R0 constant dosing rate (amount per time) [kg/s]
  • Vmax maximum elimination rate [kg/s]
  • Km Michaelis constant [kg/m^3]

Returns

  • C_ss steady-state concentration [kg/m^3]

Applies when

  • Michaelis-Menten elimination only
  • R0 < Vmax (otherwise no steady state)

Example

m.ask("Michaelis-Menten steady state: R0 = 300 mg/day, Vmax = 500 mg/day, Km = 4 mg/L")
→ C_ss = 0.006 kg/m^3
Michaelis-Menten elimination: time to fall to a concentration (a model calculation, not medical advice)bmed_pk_michaelis_menten_time

The time for the concentration of a one-compartment model with Michaelis-Menten elimination to fall from C0 to C.

t = \frac{V}{V_{max}}\left[(C_0 - C) + K_m \ln\frac{C_0}{C}\right]

Inputs

  • C0 initial concentration [kg/m^3]
  • C target concentration (< C0) [kg/m^3]
  • Vmax maximum elimination rate [kg/s]
  • Km Michaelis constant [kg/m^3]
  • V volume of distribution [m^3]

Returns

  • t time to fall from C0 to C [s]

Applies when

  • one compartment
  • Michaelis-Menten elimination only
  • C < C0

Example

m.ask("Michaelis-Menten time to concentration: C0 = 20 mg/L, C = 10 mg/L, Vmax = 500 mg/day, Km = 4 mg/L, V = 50 L")
→ t = 110355 s
One-compartment IV bolus: concentration at a time (a model calculation, not medical advice)bmed_pk_iv_bolus_concentration

The plasma concentration of a one-compartment model a time t after an intravenous bolus dose, with first-order elimination; also the fraction of the dose remaining.

C(t) = \frac{D}{V}\,e^{-k t}

Inputs

  • D bolus dose [kg]
  • V volume of distribution [m^3]
  • k elimination rate constant [1/s]
  • t time after the dose [s]

Returns

  • C concentration at time t [kg/m^3]
  • fraction_remaining fraction of the dose still in the body

Applies when

  • one compartment, instantaneous mixing
  • first-order elimination
  • t >= 0

Example

m.ask("IV bolus concentration: D = 500 mg, V = 40 L, k = 0.1 1/h, t = 6 h")
→ C = 0.00686015 kg/m^3, fraction_remaining = 0.548812
Oral dose, first-order absorption: concentration at a time (Bateman function) (a model calculation, not medical advice)bmed_pk_oral_concentration

The plasma concentration and partial AUC of a one-compartment model with first-order absorption (rate ka) and elimination (rate k) after a single oral dose with bioavailability F.

C(t) = \frac{F D k_a}{V (k_a - k)}\left(e^{-k t} - e^{-k_a t}\right)

Inputs

  • F bioavailable fraction (0 < F <= 1; 80% or 0.8)
  • D oral dose [kg]
  • V volume of distribution [m^3]
  • ka absorption rate constant [1/s]
  • k elimination rate constant [1/s]
  • t time after the dose [s]

Returns

  • C concentration at time t [kg/m^3]
  • AUC_0_t area under the curve from 0 to t [kg*s/m^3]

Applies when

  • one compartment
  • first-order absorption and elimination
  • ka != k
  • no lag time

Example

m.ask("Oral dose concentration: F = 0.8, D = 250 mg, V = 35 L, ka = 1.2 1/h, k = 0.15 1/h, t = 3 h")
→ C = 0.00398566 kg/m^3, AUC_0_t = 37.7397 kg*s/m^3
Oral dose: time and height of the peak concentration (tmax, Cmax) (a model calculation, not medical advice)bmed_pk_oral_peak

The time of the peak plasma concentration and the peak concentration of a one-compartment model with first-order absorption after a single oral dose.

t_{max} = \frac{\ln(k_a/k)}{k_a - k},\quad C_{max} = \frac{F D}{V} e^{-k t_{max}}

Inputs

  • F bioavailable fraction (0 < F <= 1)
  • D oral dose [kg]
  • V volume of distribution [m^3]
  • ka absorption rate constant [1/s]
  • k elimination rate constant [1/s]

Returns

  • t_max time of the peak [s]
  • C_max peak concentration [kg/m^3]

Applies when

  • one compartment
  • first-order absorption and elimination
  • ka != k

Example

m.ask("Oral dose peak: F = 0.8, D = 250 mg, V = 35 L, ka = 1.2 1/h, k = 0.15 1/h")
→ t_max = 7129.51 s, C_max = 0.0042457 kg/m^3
Repeated IV bolus doses: concentration after the nth dose (a model calculation, not medical advice)bmed_pk_nth_dose_iv

The peak concentration just after the nth of equal IV bolus doses given every tau, and the concentration a time t later, in a one-compartment model (superposition).

C_n(t) = \frac{D}{V}\,\frac{1 - e^{-n k \tau}}{1 - e^{-k \tau}}\,e^{-k t}

Inputs

  • D each bolus dose [kg]
  • V volume of distribution [m^3]
  • k elimination rate constant [1/s]
  • tau dosing interval [s]
  • n number of the dose (1 = first) integer
  • t time after the nth dose (0 to tau) [s]

Returns

  • C_max_n concentration just after the nth dose [kg/m^3]
  • C concentration a time t after the nth dose [kg/m^3]

Applies when

  • equal doses at equal intervals
  • linear one-compartment model
  • 0 <= t <= tau

Example

m.ask("Concentration after the nth IV dose: D = 500 mg, V = 40 L, k = 0.1 1/h, tau = 8 h, n = 3, t = 2 h")
→ C_max_n = 0.0206403 kg/m^3, C = 0.0168989 kg/m^3
Repeated IV bolus dosing: steady-state peak, trough, average and accumulation factor (a model calculation, not medical advice)bmed_pk_steady_state_iv

The steady-state peak, trough and average concentrations and the accumulation factor of a one-compartment model given equal IV bolus doses every tau.

C_{max,ss} = \frac{D/V}{1 - e^{-k\tau}},\quad C_{min,ss} = C_{max,ss}\,e^{-k\tau},\quad \bar C_{ss} = \frac{D}{V k \tau}

Inputs

  • D each bolus dose [kg]
  • V volume of distribution [m^3]
  • k elimination rate constant [1/s]
  • tau dosing interval [s]

Returns

  • C_max_ss steady-state peak (just after a dose) [kg/m^3]
  • C_min_ss steady-state trough (just before a dose) [kg/m^3]
  • C_avg_ss average concentration over an interval at steady state [kg/m^3]
  • R_ac accumulation factor: steady-state peak over first-dose peak

Applies when

  • equal doses at equal intervals
  • linear one-compartment model

Example

m.ask("Steady state of repeated IV doses: D = 500 mg, V = 40 L, k = 0.1 1/h, tau = 8 h")
→ C_max_ss = 0.0226996 kg/m^3, C_min_ss = 0.0101996 kg/m^3, C_avg_ss = 0.015625 kg/m^3, R_ac = 1.81597
Repeated oral dosing: steady-state peak, its time and the trough (a model calculation, not medical advice)bmed_pk_steady_state_oral

The steady-state peak concentration, the time of the peak after a dose and the trough of a one-compartment model with first-order absorption given equal oral doses every tau.

C_{ss}(t) = \frac{F D k_a}{V (k_a - k)}\left[\frac{e^{-k t}}{1 - e^{-k\tau}} - \frac{e^{-k_a t}}{1 - e^{-k_a \tau}}\right]

Inputs

  • F bioavailable fraction (0 < F <= 1)
  • D each oral dose [kg]
  • V volume of distribution [m^3]
  • ka absorption rate constant [1/s]
  • k elimination rate constant [1/s]
  • tau dosing interval [s]

Returns

  • C_max_ss steady-state peak [kg/m^3]
  • t_max_ss time of the peak after a dose [s]
  • C_min_ss steady-state trough (at the dosing times) [kg/m^3]

Applies when

  • equal doses at equal intervals
  • linear one-compartment model, first-order absorption
  • ka != k
  • the steady-state peak lies inside the interval

Example

m.ask("Steady state of repeated oral doses: F = 0.8, D = 250 mg, V = 35 L, ka = 1.2 1/h, k = 0.15 1/h, tau = 8 h")
→ C_max_ss = 0.00639474 kg/m^3, t_max_ss = 5901.01 s, C_min_ss = 0.00281433 kg/m^3
Repeated short infusions: steady-state peak and trough (a model calculation, not medical advice)bmed_pk_intermittent_infusion_steady_state

The steady-state peak (end of infusion) and trough (end of interval) of a one-compartment model given infusions of duration T_inf at rate R0 every tau.

C_{max,ss} = \frac{R_0}{CL}\,\frac{1 - e^{-kT}}{1 - e^{-k\tau}},\quad C_{min,ss} = C_{max,ss}\,e^{-k(\tau - T)}

Inputs

  • R0 infusion rate [kg/s]
  • T_inf duration of each infusion [s]
  • tau dosing interval [s]
  • CL clearance [m^3/s]
  • V volume of distribution [m^3]

Returns

  • C_max_ss steady-state concentration at the end of an infusion [kg/m^3]
  • C_min_ss steady-state concentration at the end of an interval [kg/m^3]

Applies when

  • one compartment, first-order elimination
  • T_inf < tau
  • identical infusions

Example

m.ask("Intermittent infusion steady state: R0 = 1000 mg/h, T_inf = 1 h, tau = 8 h, CL = 6 L/h, V = 30 L")
→ C_max_ss = 0.0378542 kg/m^3, C_min_ss = 0.00933472 kg/m^3
Two-compartment IV bolus: macro-constants and concentration from micro-constants (a model calculation, not medical advice)bmed_pk_two_compartment_bolus

The hybrid rate constants alpha and beta, the coefficients A and B and the central concentration at time t of a two-compartment model after an IV bolus, from the volume V1 and the micro-constants k10, k12, k21.

C(t) = A e^{-\alpha t} + B e^{-\beta t},\quad \alpha\beta = k_{10}k_{21},\ \alpha + \beta = k_{10} + k_{12} + k_{21}

Inputs

  • D bolus dose [kg]
  • V1 central volume [m^3]
  • k10 elimination rate constant from the central compartment [1/s]
  • k12 transfer rate constant central to peripheral [1/s]
  • k21 transfer rate constant peripheral to central [1/s]
  • t time after the dose [s]

Returns

  • alpha fast (distribution) rate constant [1/s]
  • beta slow (terminal) rate constant [1/s]
  • A coefficient of exp(-alpha t) [kg/m^3]
  • B coefficient of exp(-beta t) [kg/m^3]
  • C central concentration at time t [kg/m^3]

Applies when

  • linear two-compartment model, elimination from the central compartment
  • alpha > beta

Example

m.ask("Two-compartment bolus: D = 100 mg, V1 = 10 L, k10 = 0.2 1/h, k12 = 0.5 1/h, k21 = 0.3 1/h, t = 4 h")
→ alpha = 0.000259969 1/s, beta = 1.78084e-05 1/s, A = 0.00729416 kg/m^3, B = 0.00270584 kg/m^3, C = 0.00226643 kg/m^3
Two-compartment model: micro-constants, clearance and Vss from a biexponential curve (a model calculation, not medical advice)bmed_pk_two_compartment_micro_constants

The central volume, the micro rate constants k10, k12, k21, the clearance and the steady-state volume of a two-compartment model from the biexponential fit C = A exp(-alpha t) + B exp(-beta t) of an IV bolus.

k_{21} = \frac{A\beta + B\alpha}{A + B},\quad k_{10} = \frac{\alpha\beta}{k_{21}},\quad k_{12} = \alpha + \beta - k_{21} - k_{10}

Inputs

  • D bolus dose [kg]
  • A coefficient of the fast exponential [kg/m^3]
  • alpha fast rate constant [1/s]
  • B coefficient of the slow exponential [kg/m^3]
  • beta slow rate constant [1/s]

Returns

  • V1 central volume [m^3]
  • k10 elimination rate constant [1/s]
  • k12 central to peripheral [1/s]
  • k21 peripheral to central [1/s]
  • CL clearance [m^3/s]
  • Vss volume of distribution at steady state [m^3]

Applies when

  • IV bolus, linear two-compartment model, elimination from the central compartment
  • alpha > beta > 0, A > 0, B > 0

Example

m.ask("Two-compartment micro-constants: D = 100 mg, A = 6 mg/L, alpha = 1.5 1/h, B = 2 mg/L, beta = 0.15 1/h")
→ V1 = 0.0125 m^3, k10 = 0.000128205 1/s, k12 = 0.000194712 1/s, k21 = 0.000135417 1/s, CL = 1.60256e-06 m^3/s, Vss = 0.0304734 m^3

Survival analysis 8

Cox proportional-hazards model with one covariate: hazard ratio (Efron ties)bmed_cox_hazard_ratio

The log hazard ratio, hazard ratio, its standard error and Wald confidence interval of a Cox proportional-hazards model with a single covariate, by maximum partial likelihood with Efron's handling of ties.

\ell(\beta) = \sum_j\left[\beta\sum_{i\in D_j}x_i - \sum_{l=0}^{d_j-1}\ln\left(\sum_{R_j}e^{\beta x} - \tfrac{l}{d_j}\sum_{D_j}e^{\beta x}\right)\right]

Inputs

  • times follow-up times vector
  • events 1 = event, 0 = censored vector
  • x covariate value of each subject (e.g. 1 = treated, 0 = control) vector
  • level confidence level (95% or 0.95)

Returns

  • beta log hazard ratio per unit of x
  • HR hazard ratio exp(beta)
  • se standard error of beta
  • HR_lower lower Wald limit of the hazard ratio
  • HR_upper upper Wald limit of the hazard ratio

Applies when

  • proportional hazards
  • Efron approximation for tied event times
  • a finite maximum (no monotone likelihood)
  • level stated

Example

m.ask("Cox hazard ratio: times = [6, 6, 6, 7, 10, 13, 16, 22, 23, 6, 9, 10, 11, 17, 19, 20, 25, 32, 32, 34, 35], events = [1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], x = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1], level = 95%")
→ beta = 0.0473228, HR = 1.04846, se = 0.673876, HR_lower = 0.279864, HR_upper = 3.92787
Exponential survival model: hazard rate, mean and median survival (maximum likelihood)bmed_exponential_survival_fit

The maximum-likelihood constant hazard of an exponential survival model from censored follow-up data, with the implied mean and median survival times.

\hat\lambda = \frac{d}{\sum_i t_i},\quad \tilde t = \frac{\ln 2}{\hat\lambda}

Inputs

  • times follow-up times, all positive (one time unit) vector
  • events 1 = event, 0 = censored vector

Returns

  • hazard events per unit time
  • mean mean survival 1/hazard
  • median median survival ln 2 / hazard

Applies when

  • constant hazard
  • non-informative censoring
  • at least one event

Example

m.ask("Exponential survival fit: times = [6, 6, 6, 7, 10, 13, 16, 22, 23, 6, 9, 10, 11, 17, 19, 20, 25, 32, 32, 34, 35], events = [1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]")
→ hazard = 0.0250696, mean = 39.8889, median = 27.6489
Hazard ratio of two exponential survival groups with Wald intervalbmed_exponential_hazard_ratio

The ratio of the maximum-likelihood constant hazards of two groups (group 1 relative to group 2) with the log-scale Wald confidence interval.

HR = \frac{d_1/\sum t_{1}}{d_2/\sum t_{2}},\quad \mathrm{SE}(\ln HR) = \sqrt{\tfrac1{d_1} + \tfrac1{d_2}}

Inputs

  • times1 follow-up times, group 1 (positive) vector
  • events1 1 = event, 0 = censored, group 1 vector
  • times2 follow-up times, group 2 (reference) vector
  • events2 1 = event, 0 = censored, group 2 vector
  • level confidence level (95% or 0.95)

Returns

  • HR hazard ratio group 1 / group 2
  • lower lower limit
  • upper upper limit

Applies when

  • constant hazard in each group
  • at least one event per group
  • level stated

Example

m.ask("Exponential hazard ratio: times1 = [6, 6, 6, 7, 10, 13, 16, 22, 23], events1 = [1, 1, 1, 1, 1, 1, 1, 1, 1], times2 = [6, 9, 10, 11, 17, 19, 20, 25, 32, 32, 34, 35], events2 = [1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0], level = 95%")
→ HR = 5.16055, lower = 1.58923, upper = 16.7573
Kaplan-Meier survival estimate at a time and median survivalbmed_km_survival_median

The Kaplan-Meier (product-limit) estimate of the survival probability at time t and the median survival time from follow-up times with event or censoring indicators.

\hat S(t) = \prod_{u_i \le t}\left(1 - \frac{d_i}{n_i}\right)

Inputs

  • times follow-up times (one time unit; results in that unit) vector
  • events 1 = event observed, 0 = censored, one per time vector
  • t time at which S(t) is reported

Returns

  • S_t Kaplan-Meier survival probability at t
  • median median survival: first time with S <= 0.5 (none when not reached)

Applies when

  • non-informative censoring
  • a censoring at an event time counts as at risk at that time

Example

m.ask("Kaplan-Meier survival: times = [6, 6, 6, 7, 10, 13, 16, 22, 23, 6, 9, 10, 11, 17, 19, 20, 25, 32, 32, 34, 35], events = [1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], t = 12")
→ S_t = 0.752941, median = 23
Kaplan-Meier survival with log(-log) (exponential Greenwood) confidence intervalbmed_km_confidence_interval

The Kaplan-Meier survival estimate at time t with its confidence interval on the log(-log) scale (Greenwood variance; the exponential Greenwood interval) at the stated level.

\hat S^{\exp\left(\pm z\,\sqrt{V}/|\ln\hat S|\right)},\quad V = \sum_{u_i \le t}\frac{d_i}{n_i(n_i - d_i)}

Inputs

  • times follow-up times (one time unit) vector
  • events 1 = event, 0 = censored vector
  • t time at which S(t) is reported
  • level confidence level (95% or 0.95)

Returns

  • S_t Kaplan-Meier estimate at t
  • lower lower confidence limit
  • upper upper confidence limit

Applies when

  • non-informative censoring
  • an event at or before t and S(t) > 0
  • level stated

Example

m.ask("Kaplan-Meier confidence interval: times = [6, 6, 6, 7, 10, 13, 16, 22, 23, 6, 9, 10, 11, 17, 19, 20, 25, 32, 32, 34, 35], events = [1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], t = 12, level = 95%")
→ S_t = 0.752941, lower = 0.5032, upper = 0.889362
Log-rank test comparing two survival curvesbmed_logrank_test

The log-rank (Mantel-Cox) chi-square statistic and p-value for equal survival in two groups from follow-up times and event indicators.

\chi^2 = \frac{\left(\sum_i (d_{1i} - e_{1i})\right)^2}{\sum_i v_i}

Inputs

  • times1 follow-up times, group 1 vector
  • events1 1 = event, 0 = censored, group 1 vector
  • times2 follow-up times, group 2 vector
  • events2 1 = event, 0 = censored, group 2 vector

Returns

  • chi_square log-rank chi-square (1 degree of freedom)
  • p_value two-sided p-value

Applies when

  • non-informative censoring
  • hypergeometric variance at each event time

Example

m.ask("Log-rank test: times1 = [6, 6, 6, 7, 10, 13, 16, 22, 23], events1 = [1, 1, 1, 1, 1, 1, 1, 1, 1], times2 = [1, 1, 2, 2, 3, 4, 4, 5, 5, 8], events2 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]")
→ chi_square = 13.85, p_value = 0.000197999
Nelson-Aalen cumulative hazard at a timebmed_nelson_aalen_hazard

The Nelson-Aalen estimate of the cumulative hazard at time t from follow-up times with event or censoring indicators.

\hat H(t) = \sum_{u_i \le t}\frac{d_i}{n_i}

Inputs

  • times follow-up times (one time unit) vector
  • events 1 = event, 0 = censored vector
  • t time at which H(t) is reported

Returns

  • H_t cumulative hazard at t

Applies when

  • non-informative censoring
  • tied events contribute d/n (no tie smoothing)

Example

m.ask("Nelson-Aalen cumulative hazard: times = [6, 6, 6, 7, 10, 13, 16, 22, 23, 6, 9, 10, 11, 17, 19, 20, 25, 32, 32, 34, 35], events = [1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], t = 12")
→ H_t = 0.268347
Restricted mean survival time from the Kaplan-Meier curvebmed_restricted_mean_survival_time

The restricted mean survival time up to tau: the area under the Kaplan-Meier survival curve from 0 to tau.

\mathrm{RMST}(\tau) = \int_0^{\tau}\hat S(t)\,dt

Inputs

  • times follow-up times (one time unit) vector
  • events 1 = event, 0 = censored vector
  • tau restriction time (in the unit of the times)

Returns

  • RMST restricted mean survival time, in the time unit

Applies when

  • non-informative censoring
  • the Kaplan-Meier step function integrated exactly

Example

m.ask("Restricted mean survival time: times = [6, 6, 6, 7, 10, 13, 16, 22, 23, 6, 9, 10, 11, 17, 19, 20, 25, 32, 32, 34, 35], events = [1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], tau = 20")
→ RMST = 16.1165
Questions

Frequently asked

What does biomedical-science-ai999x do?

Biomedical Science answers questions in biomedical science: pharmacokinetics and dosing models, epidemic models, diagnostic test statistics, survival analysis, biomechanics, neuron models and medical-imaging physics (quantitative only, no clinical advice). Each answer gives the value with its unit, the steps and the formula in LaTeX.

How do I install biomedical-science-ai999x?

With pip: pip install biomedical-science-ai999x. The same files are on Hugging Face (hf download AI999X/biomedical-science-ai999x --local-dir biomedical-science-ai999x) and GitHub.

Does it run offline?

Yes. It is a Python package that runs on an ordinary CPU without a network connection (Python >=3.10); no GPU and no API key are needed.

How many capabilities does biomedical-science-ai999x have?

86 capabilities in 9 topics, including Pharmacokinetic models, Medical-imaging physics, Biomechanics, Neuron models, Epidemic models.

Which field and tasks does it cover?

Field: Life Sciences. Tasks: Question Answering, Token Classification, Text Classification, Sentence Similarity, Feature Extraction.

What does an answer look like?

Asked "IV bolus concentration: D = 500 mg, V = 40 L, k = 0.1 1/h, t = 6 h", it answers: C = 0.00686015 kg/m^3, fraction_remaining = 0.548812.

What happens when a question cannot be answered?

It says so and names what is missing or out of range, instead of guessing a number.

More from AI999X

Explore every model.