Bayesian reanalysis of EMPACT-MI
import pymc3 as pm
import numpy as np
import arviz as az
# Empagliflozin after Acute Myocardial Infarction 24 https://www.nejm.org/doi/full/10.1056/NEJMoa2314051
log_or = np.log(0.9)
log_or_lower = np.log(0.76)
log_or_upper = np.log(1.06)
# The scale for the Cauchy distribution
cauchy_scale = 0.707
# Model setup
with pm.Model() as model:
# Prior distribution for the log-OR
log_or_prior = pm.Cauchy("log_OR", alpha=0, beta=cauchy_scale)
# Likelihood (normal approximation of the distribution of log-OR)
se_log_or = (log_or_upper - log_or_lower) / 3.92
likelihood = pm.Normal("likelihood", mu=log_or_prior, sigma=se_log_or, observed=np.array([log_or]))
# Sample from the posterior distribution
trace = pm.sample(500000, cores=1, tune=150000, chains=4)
# Convert log-OR samples to HR samples
hr_samples = np.exp(trace["log_OR"])
# Calculate the posterior probability that HR < 1
post_prob_hr_less_than_1 = np.mean(hr_samples < 1)
# Print the posterior probability
print("Posterior probability that HR < 1:", post_prob_hr_less_than_1)
# Calculate the 95% HDI
hdi_95 = az.hdi(trace, hdi_prob=0.95)
# Print the 95% HDI
print("95% HDI:")
print("Lower bound:", hdi_95["log_OR"][0])
print("Upper bound:", hdi_95["log_OR"][1])
# Calculate convergence diagnostics
summary = az.summary(trace, kind='diagnostics')
print(summary)
az.plot_trace(trace)
留言
張貼留言