A General Framework for Bayesian Estimation Using the Tierney-Kadane Approximation
TKApprox provides a distribution-independent framework for Bayesian estimation of arbitrary univariate probability models using the Tierney-Kadane approximation. Users specify the probability distribution, likelihood, prior distributions, and censoring mechanism, while the package automatically constructs the posterior distribution, computes posterior modes and Hessians, approximates posterior expectations under several Bayesian loss functions, and returns Bayesian parameter estimates, posterior covariance matrices, credible intervals, diagnostic plots, and model comparison statistics.
numDeriv with optional analytic derivative supportsummary(),
print(), coef(), vcov(),
logLik(), AIC(), BIC(),
plot(), predict(),
residuals()# Install from CRAN (when available)
install.packages("TKApprox")
# Install development version from GitHub
devtools::install_github("yourusername/TKApprox")library(TKApprox)
# Define the exponential distribution
pdf_exp <- function(x, param) dexp(x, rate = param)
cdf_exp <- function(x, param) pexp(x, rate = param)
# Specify gamma prior for the rate parameter
prior_spec <- list(
rate = list(family = "gamma", hyperparameters = list(shape = 2, rate = 1))
)
# Generate some data
set.seed(123)
data <- rexp(20, rate = 1.5)
# Fit the model using squared error loss (posterior mean)
fit <- tk_fit(
data = data,
censoring_scheme = "complete",
pdf = pdf_exp,
cdf = cdf_exp,
prior_spec = prior_spec,
initial_values = c(rate = 1),
loss_function = "sel"
)
# View results
summary(fit)
# Plot diagnostics
plot(fit)
# Compute model comparison statistics
print_model_comparison(fit)# Define censoring indicators (1 = observed, 0 = right-censored)
status <- c(1, 1, 0, 1, 0, 1, 1, 0, 1, 1)
fit_censored <- tk_fit(
data = data,
censoring_scheme = "right-censored",
pdf = pdf_exp,
cdf = cdf_exp,
prior_spec = prior_spec,
initial_values = c(rate = 1),
loss_function = "sel",
status = status
)
summary(fit_censored)fit_linex <- tk_fit(
data = data,
censoring_scheme = "complete",
pdf = pdf_exp,
cdf = cdf_exp,
prior_spec = prior_spec,
initial_values = c(rate = 1),
loss_function = "linex",
loss_params = list(c = 0.5)
)
summary(fit_linex)sensitivity <- tk_sensitivity(
fit = fit,
parameter_name = "rate",
hyperparameter_name = "shape",
hyperparameter_values = c(0.5, 1, 2, 5, 10)
)
print(sensitivity)
plot(sensitivity)The package supports the following censoring schemes:
The following Bayesian loss functions are supported:
Supported prior families:
TKApprox follows the same design philosophy as UniIS, UniCensorEM, and UniLindleyApprox:
Contributions are welcome! Please read our contributing guidelines before submitting pull requests.
GPL (>= 3)
To cite this package, use:
citation("TKApprox")
Your Name
This package extends the design philosophy established in UniIS, UniCensorEM, and UniLindleyApprox packages.