| Title: | A General Framework for Bayesian Estimation Using the 'Tierney'-'Kadane' Approximation |
|---|---|
| Description: | Provides a distribution-independent framework for Bayesian estimation of arbitrary univariate probability models using the 'Tierney'-'Kadane' approximation ('Tierney' & 'Kadane', 1986 <doi:10.1080/01621459.1986.10478240>). Users specify the probability distribution, likelihood, prior distributions, and censoring mechanism, while the package automatically constructs the posterior distribution, computes posterior modes and Hessian matrices, approximates posterior expectations under several Bayesian loss functions, and returns Bayesian parameter estimates, posterior covariance matrices, credible intervals, diagnostic plots, and model comparison statistics. Supports complete, right-, left-, interval-, Type-I, Type-II, progressive Type-II, hybrid, and doubly censored data ('Lawless', 2003 <ISBN:978-0-471-37215-8>; 'Meeker' & 'Escobar', 1998 <ISBN:978-0-471-14328-4>; 'Balakrishnan' & 'Aggarwala', 2000 <ISBN:978-0-8176-4129-0>; 'Kundu' & 'Pradhan', 2009 <doi:10.1198/TECH.2009.0019>), making it a flexible tool for Bayesian reliability, survival, and lifetime data analysis. |
| Authors: | Shikhar Tyagi [aut, cre] (ORCID: <https://orcid.org/0000-0003-1606-0844>), Arvind Pandey [aut], Bhupendra Singh [aut], Vrijesh Tripathi [aut] |
| Maintainer: | Shikhar Tyagi <[email protected]> |
| License: | GPL (>= 3) |
| Version: | 0.1.0 |
| Built: | 2026-09-27 11:47:11 UTC |
| Source: | https://github.com/cran/TKApprox |
Computes the Akaike Information Criterion.
## S3 method for class 'tkfit' AIC(object, ...)## S3 method for class 'tkfit' AIC(object, ...)
object |
A tkfit object |
... |
Additional arguments (ignored) |
AIC value
Computes the Bayesian Information Criterion.
## S3 method for class 'tkfit' BIC(object, ...)## S3 method for class 'tkfit' BIC(object, ...)
object |
A tkfit object |
... |
Additional arguments (ignored) |
BIC value
Compute CAIC (Consistent AIC)
CAIC(object, ...) ## S3 method for class 'tkfit' CAIC(object, ...)CAIC(object, ...) ## S3 method for class 'tkfit' CAIC(object, ...)
object |
A tkfit object |
... |
Additional arguments (ignored) |
Numeric scalar value of Consistent Akaike Information Criterion (CAIC).
CAIC(tkfit): CAIC method for tkfit objects
Extracts the Bayes estimates from a tkfit object.
## S3 method for class 'tkfit' coef(object, ...)## S3 method for class 'tkfit' coef(object, ...)
object |
A tkfit object |
... |
Additional arguments (ignored) |
Named vector of Bayes estimates
Computes an approximation to the DIC using the TK framework.
DIC(object, ...) ## S3 method for class 'tkfit' DIC(object, ...)DIC(object, ...) ## S3 method for class 'tkfit' DIC(object, ...)
object |
A tkfit object |
... |
Additional arguments (ignored) |
Numeric scalar value of Deviance Information Criterion (DIC) approximation.
DIC(tkfit): DIC method for tkfit objects
Evaluates the log-posterior function created by tk_posterior.
eval_logposterior(log_post_fn, param)eval_logposterior(log_post_fn, param)
log_post_fn |
Log-posterior function from |
param |
Parameter vector |
Numeric value of the log-posterior
Computes the expected log-posterior using the TK approximation.
expected_logposterior(object, ...) ## S3 method for class 'tkfit' expected_logposterior(object, ...)expected_logposterior(object, ...) ## S3 method for class 'tkfit' expected_logposterior(object, ...)
object |
A tkfit object |
... |
Additional arguments (ignored) |
Numeric scalar value of expected log-posterior.
expected_logposterior(tkfit): Expected log-posterior method for tkfit objects
Compute HQIC (Hannan-Quinn Information Criterion)
HQIC(object, ...) ## S3 method for class 'tkfit' HQIC(object, ...)HQIC(object, ...) ## S3 method for class 'tkfit' HQIC(object, ...)
object |
A tkfit object |
... |
Additional arguments (ignored) |
Numeric scalar value of Hannan-Quinn Information Criterion (HQIC).
HQIC(tkfit): HQIC method for tkfit objects
Functions to construct log-likelihood contributions for various censoring schemes. These functions are used internally to build the complete log-likelihood from user-supplied density/mass functions and CDFs.
Numeric value of the log-likelihood for the specified data and parameters.
Computes the log-likelihood for complete (uncensored) data.
loglik_complete(data, pdf, param)loglik_complete(data, pdf, param)
data |
Numeric vector of observations |
pdf |
User-supplied density/mass function |
param |
Parameter vector |
Numeric value of the log-likelihood
pdf_exp <- function(x, param) dexp(x, rate = param[1]) loglik_complete(c(1.2, 2.3, 0.9), pdf_exp, c(1.0))pdf_exp <- function(x, param) dexp(x, rate = param[1]) loglik_complete(c(1.2, 2.3, 0.9), pdf_exp, c(1.0))
Dispatches to the appropriate likelihood function based on the censoring scheme.
loglik_dispatcher(data, censoring_scheme, pdf, cdf = NULL, param, ...)loglik_dispatcher(data, censoring_scheme, pdf, cdf = NULL, param, ...)
data |
Data (format depends on censoring scheme: vector, matrix, or data.frame) |
censoring_scheme |
Character string specifying the censoring scheme |
pdf |
User-supplied density/mass function |
cdf |
User-supplied CDF function (required for censored schemes) |
param |
Parameter vector |
... |
Additional arguments specific to censoring schemes (status, censoring_time, n, r, removals, etc.) |
Numeric value of the log-likelihood
pdf_exp <- function(x, param) dexp(x, rate = param[1]) cdf_exp <- function(x, param) pexp(x, rate = param[1]) loglik_dispatcher(c(1.2, 2.3), "complete", pdf_exp, cdf_exp, c(1.0))pdf_exp <- function(x, param) dexp(x, rate = param[1]) cdf_exp <- function(x, param) pexp(x, rate = param[1]) loglik_dispatcher(c(1.2, 2.3), "complete", pdf_exp, cdf_exp, c(1.0))
Computes the log-likelihood for doubly censored data.
loglik_doubly_censored(data, status, pdf, cdf, param)loglik_doubly_censored(data, status, pdf, cdf, param)
data |
Numeric vector of observations or censoring times |
status |
Numeric vector of censoring indicators (-1 = left-censored, 0 = observed, 1 = right-censored) |
pdf |
User-supplied density function |
cdf |
User-supplied CDF function |
param |
Parameter vector |
Numeric value of the log-likelihood
pdf_exp <- function(x, param) dexp(x, rate = param[1]) cdf_exp <- function(x, param) pexp(x, rate = param[1]) loglik_doubly_censored(c(0.5, 1.2, 2.0), c(-1, 0, 1), pdf_exp, cdf_exp, c(1.0))pdf_exp <- function(x, param) dexp(x, rate = param[1]) cdf_exp <- function(x, param) pexp(x, rate = param[1]) loglik_doubly_censored(c(0.5, 1.2, 2.0), c(-1, 0, 1), pdf_exp, cdf_exp, c(1.0))
Computes the log-likelihood for hybrid censored data.
loglik_hybrid_censored(data, censoring_time, r, n, pdf, cdf, param)loglik_hybrid_censored(data, censoring_time, r, n, pdf, cdf, param)
data |
Numeric vector of observed failure times |
censoring_time |
Type-I censoring time T |
r |
Target number of failures for Type-II censoring |
n |
Total number of items |
pdf |
User-supplied density function |
cdf |
User-supplied CDF function |
param |
Parameter vector |
Numeric value of the log-likelihood
pdf_exp <- function(x, param) dexp(x, rate = param[1]) cdf_exp <- function(x, param) pexp(x, rate = param[1]) loglik_hybrid_censored(c(0.5, 1.2), 2.0, 3, 5, pdf_exp, cdf_exp, c(1.0))pdf_exp <- function(x, param) dexp(x, rate = param[1]) cdf_exp <- function(x, param) pexp(x, rate = param[1]) loglik_hybrid_censored(c(0.5, 1.2), 2.0, 3, 5, pdf_exp, cdf_exp, c(1.0))
Computes the log-likelihood for interval-censored data. Data should be a matrix or data.frame with columns: lower, upper.
loglik_interval_censored(data, pdf, cdf, param)loglik_interval_censored(data, pdf, cdf, param)
data |
Matrix or data.frame with 2 columns: lower, upper |
pdf |
User-supplied density function |
cdf |
User-supplied CDF function |
param |
Parameter vector |
Numeric value of the log-likelihood
pdf_exp <- function(x, param) dexp(x, rate = param[1]) cdf_exp <- function(x, param) pexp(x, rate = param[1]) dat <- cbind(c(1, 2), c(1, 3)) loglik_interval_censored(dat, pdf_exp, cdf_exp, c(1.0))pdf_exp <- function(x, param) dexp(x, rate = param[1]) cdf_exp <- function(x, param) pexp(x, rate = param[1]) dat <- cbind(c(1, 2), c(1, 3)) loglik_interval_censored(dat, pdf_exp, cdf_exp, c(1.0))
Computes the log-likelihood for left-censored data. Status: 1 = observed, 0 = left-censored.
loglik_left_censored(data, status, pdf, cdf, param)loglik_left_censored(data, status, pdf, cdf, param)
data |
Numeric vector of observations or censoring times |
status |
Numeric vector of censoring indicators (1 = observed, 0 = censored) |
pdf |
User-supplied density function |
cdf |
User-supplied CDF function |
param |
Parameter vector |
Numeric value of the log-likelihood
pdf_exp <- function(x, param) dexp(x, rate = param[1]) cdf_exp <- function(x, param) pexp(x, rate = param[1]) loglik_left_censored(c(1.2, 2.3), c(1, 0), pdf_exp, cdf_exp, c(1.0))pdf_exp <- function(x, param) dexp(x, rate = param[1]) cdf_exp <- function(x, param) pexp(x, rate = param[1]) loglik_left_censored(c(1.2, 2.3), c(1, 0), pdf_exp, cdf_exp, c(1.0))
Computes the log-likelihood for progressive Type-II censored data.
loglik_progressive_type2_censored(data, removals, n, pdf, cdf, param)loglik_progressive_type2_censored(data, removals, n, pdf, cdf, param)
data |
Numeric vector of ordered failure times |
removals |
Numeric vector of removal counts at each failure time |
n |
Initial sample size |
pdf |
User-supplied density function |
cdf |
User-supplied CDF function |
param |
Parameter vector |
Numeric value of the log-likelihood
pdf_exp <- function(x, param) dexp(x, rate = param[1]) cdf_exp <- function(x, param) pexp(x, rate = param[1]) loglik_progressive_type2_censored(c(0.5, 1.2), c(1, 2), 5, pdf_exp, cdf_exp, c(1.0))pdf_exp <- function(x, param) dexp(x, rate = param[1]) cdf_exp <- function(x, param) pexp(x, rate = param[1]) loglik_progressive_type2_censored(c(0.5, 1.2), c(1, 2), 5, pdf_exp, cdf_exp, c(1.0))
Computes the log-likelihood for right-censored data. Status: 1 = observed, 0 = right-censored.
loglik_right_censored(data, status, pdf, cdf, param)loglik_right_censored(data, status, pdf, cdf, param)
data |
Numeric vector of observations or censoring times |
status |
Numeric vector of censoring indicators (1 = observed, 0 = censored) |
pdf |
User-supplied density function |
cdf |
User-supplied CDF function |
param |
Parameter vector |
Numeric value of the log-likelihood
pdf_exp <- function(x, param) dexp(x, rate = param[1]) cdf_exp <- function(x, param) pexp(x, rate = param[1]) loglik_right_censored(c(1.2, 2.3), c(1, 0), pdf_exp, cdf_exp, c(1.0))pdf_exp <- function(x, param) dexp(x, rate = param[1]) cdf_exp <- function(x, param) pexp(x, rate = param[1]) loglik_right_censored(c(1.2, 2.3), c(1, 0), pdf_exp, cdf_exp, c(1.0))
Computes the log-likelihood for Type-I (time) censored data.
loglik_type1_censored(data, censoring_time, pdf, cdf, param)loglik_type1_censored(data, censoring_time, pdf, cdf, param)
data |
Numeric vector of observations |
censoring_time |
Fixed censoring time T |
pdf |
User-supplied density function |
cdf |
User-supplied CDF function |
param |
Parameter vector |
Numeric value of the log-likelihood
pdf_exp <- function(x, param) dexp(x, rate = param[1]) cdf_exp <- function(x, param) pexp(x, rate = param[1]) loglik_type1_censored(c(1.2, 2.0, 2.0), 2.0, pdf_exp, cdf_exp, c(1.0))pdf_exp <- function(x, param) dexp(x, rate = param[1]) cdf_exp <- function(x, param) pexp(x, rate = param[1]) loglik_type1_censored(c(1.2, 2.0, 2.0), 2.0, pdf_exp, cdf_exp, c(1.0))
Computes the log-likelihood for Type-II censored data.
loglik_type2_censored(data, n, r, pdf, cdf, param)loglik_type2_censored(data, n, r, pdf, cdf, param)
data |
Numeric vector of the r ordered failure times |
n |
Total number of items |
r |
Number of observed failures |
pdf |
User-supplied density function |
cdf |
User-supplied CDF function |
param |
Parameter vector |
Numeric value of the log-likelihood
pdf_exp <- function(x, param) dexp(x, rate = param[1]) cdf_exp <- function(x, param) pexp(x, rate = param[1]) loglik_type2_censored(c(0.5, 1.2), 5, 2, pdf_exp, cdf_exp, c(1.0))pdf_exp <- function(x, param) dexp(x, rate = param[1]) cdf_exp <- function(x, param) pexp(x, rate = param[1]) loglik_type2_censored(c(0.5, 1.2), 5, 2, pdf_exp, cdf_exp, c(1.0))
Extracts the log-likelihood at the posterior mode.
## S3 method for class 'tkfit' logLik(object, ...)## S3 method for class 'tkfit' logLik(object, ...)
object |
A tkfit object |
... |
Additional arguments (ignored) |
Log-likelihood value
Dispatches to the appropriate prior function based on the prior family name.
logprior_dispatcher(param, prior_family, hyperparameters)logprior_dispatcher(param, prior_family, hyperparameters)
param |
Numeric vector of parameters |
prior_family |
Character string specifying the prior family |
hyperparameters |
List of hyperparameters for the prior |
Numeric value of the log-prior density
logprior_dispatcher(c(2, 3), "gamma", list(shape = 2, rate = 1))logprior_dispatcher(c(2, 3), "gamma", list(shape = 2, rate = 1))
Computes the log-prior density when each parameter has an independent prior.
logprior_independent(param, prior_spec)logprior_independent(param, prior_spec)
param |
Named numeric vector of parameters |
prior_spec |
List specifying prior for each parameter |
Numeric value of the total log-prior density
param_spec <- c(alpha = 2, beta = 3) prior_spec <- list( alpha = list(family = "gamma", hyperparameters = list(shape = 2, rate = 1)), beta = list(family = "normal", hyperparameters = list(mean = 0, sd = 10)) ) logprior_independent(param_spec, prior_spec)param_spec <- c(alpha = 2, beta = 3) prior_spec <- list( alpha = list(family = "gamma", hyperparameters = list(shape = 2, rate = 1)), beta = list(family = "normal", hyperparameters = list(mean = 0, sd = 10)) ) logprior_independent(param_spec, prior_spec)
Computes various model comparison statistics for a fitted tkfit object.
Numeric value or data frame containing model comparison statistics.
Computes a comprehensive table of model comparison statistics.
model_comparison_table(object)model_comparison_table(object)
object |
A tkfit object |
A data.frame containing model comparison statistics (Statistic, Value).
Compute Negative Log-Likelihood
neglogLik(object, ...) ## S3 method for class 'tkfit' neglogLik(object, ...)neglogLik(object, ...) ## S3 method for class 'tkfit' neglogLik(object, ...)
object |
A tkfit object |
... |
Additional arguments (ignored) |
Numeric scalar value of negative log-likelihood at posterior mode.
neglogLik(tkfit): Negative log-likelihood method for tkfit objects
Plots optimization convergence diagnostics.
plot_convergence(fit, ...)plot_convergence(fit, ...)
fit |
A tkfit object |
... |
Additional graphical parameters |
Invisibly returns NULL, called for side effects.
Plots credible intervals for each parameter.
plot_credible_intervals(fit, parameter_index = NULL, ...)plot_credible_intervals(fit, parameter_index = NULL, ...)
fit |
A tkfit object |
parameter_index |
Which parameter(s) to plot (NULL for all) |
... |
Additional graphical parameters |
Invisibly returns NULL, called for side effects.
Plots the likelihood surface or profile for model parameters.
plot_likelihood_surface(fit, n_points = 50, ...)plot_likelihood_surface(fit, n_points = 50, ...)
fit |
A tkfit object |
n_points |
Number of points for each dimension |
... |
Additional graphical parameters |
Invisibly returns NULL, called for side effects.
Plots the approximate posterior distribution for each parameter.
plot_posterior_approximation(fit, parameter_index = NULL, n_points = 100, ...)plot_posterior_approximation(fit, parameter_index = NULL, n_points = 100, ...)
fit |
A tkfit object |
parameter_index |
Which parameter(s) to plot (NULL for all) |
n_points |
Number of points for the curve |
... |
Additional graphical parameters |
Invisibly returns NULL, called for side effects.
Compares the prior and posterior distributions.
plot_prior_posterior(fit, parameter_index = NULL, n_points = 100, ...)plot_prior_posterior(fit, parameter_index = NULL, n_points = 100, ...)
fit |
A tkfit object |
parameter_index |
Which parameter(s) to plot (NULL for all) |
n_points |
Number of points for the curve |
... |
Additional graphical parameters |
Invisibly returns NULL, called for side effects.
Plots residuals from the fitted model.
plot_residuals(fit, type = "pearson", ...)plot_residuals(fit, type = "pearson", ...)
fit |
A tkfit object |
type |
Type of residuals ("pearson", "deviance") |
... |
Additional graphical parameters |
Invisibly returns NULL, called for side effects.
Plot Sensitivity of Estimates
plot_sensitivity_estimates(sensitivity, ...)plot_sensitivity_estimates(sensitivity, ...)
sensitivity |
A tksensitivity object |
... |
Additional graphical parameters |
Invisibly returns NULL, called for side effects.
Plot Sensitivity of Log-Posterior
plot_sensitivity_logposterior(sensitivity, ...)plot_sensitivity_logposterior(sensitivity, ...)
sensitivity |
A tksensitivity object |
... |
Additional graphical parameters |
Invisibly returns NULL, called for side effects.
Plot Sensitivity of Risk
plot_sensitivity_risk(sensitivity, ...)plot_sensitivity_risk(sensitivity, ...)
sensitivity |
A tksensitivity object |
... |
Additional graphical parameters |
Invisibly returns NULL, called for side effects.
Creates diagnostic plots for a fitted tkfit object.
## S3 method for class 'tkfit' plot(x, which = c(1, 2, 3, 4), ask = FALSE, ...)## S3 method for class 'tkfit' plot(x, which = c(1, 2, 3, 4), ask = FALSE, ...)
x |
A tkfit object |
which |
Which plots to display (1-6, or "all") |
ask |
Whether to prompt before showing each plot |
... |
Additional graphical parameters |
Invisibly returns the input x object of class "tkfit", called for side effects.
Creates plots showing the sensitivity of estimates to prior hyperparameters.
## S3 method for class 'tksensitivity' plot(x, which = c(1, 2), ask = FALSE, ...)## S3 method for class 'tksensitivity' plot(x, which = c(1, 2), ask = FALSE, ...)
x |
A tksensitivity object |
which |
Which plots to display (1-3, or "all") |
ask |
Whether to prompt before showing each plot |
... |
Additional graphical parameters |
Invisibly returns the input x object of class "tksensitivity", called for side effects.
Generates predictions from a fitted tkfit object.
## S3 method for class 'tkfit' predict(object, newdata = NULL, type = "density", ...)## S3 method for class 'tkfit' predict(object, newdata = NULL, type = "density", ...)
object |
A tkfit object |
newdata |
New data for prediction |
type |
Type of prediction ("density", "cdf", "survival") |
... |
Additional arguments (ignored) |
Predicted values
Print Model Comparison Table
print_model_comparison(object, ...)print_model_comparison(object, ...)
object |
A tkfit object |
... |
Additional arguments (ignored) |
Invisibly returns NULL, called for side effects.
Print Method for tkexpectation Objects
## S3 method for class 'tkexpectation' print(x, ...)## S3 method for class 'tkexpectation' print(x, ...)
x |
A tkexpectation object |
... |
Additional arguments (ignored) |
Invisibly returns the input x object of class "tkexpectation", called for side effects.
Print Method for tkfit Objects
## S3 method for class 'tkfit' print(x, ...)## S3 method for class 'tkfit' print(x, ...)
x |
A tkfit object |
... |
Additional arguments (ignored) |
Invisibly returns the input x object of class "tkfit", called for side effects.
Print Method for tkhessian Objects
## S3 method for class 'tkhessian' print(x, ...)## S3 method for class 'tkhessian' print(x, ...)
x |
A tkhessian object |
... |
Additional arguments (ignored) |
Invisibly returns the input x object of class "tkhessian", called for side effects.
Print Method for tkmode Objects
## S3 method for class 'tkmode' print(x, ...)## S3 method for class 'tkmode' print(x, ...)
x |
A tkmode object |
... |
Additional arguments (ignored) |
Invisibly returns the input x object of class "tkmode", called for side effects.
Print Method for tksensitivity Objects
## S3 method for class 'tksensitivity' print(x, ...)## S3 method for class 'tksensitivity' print(x, ...)
x |
A tksensitivity object |
... |
Additional arguments (ignored) |
Invisibly returns the input x object of class "tksensitivity", called for side effects.
Functions for computing log-prior densities for various prior distributions.
These functions are used internally by tk_posterior to construct
the log-posterior.
logprior_gamma(param, hyperparameters) logprior_normal(param, hyperparameters) logprior_beta(param, hyperparameters) logprior_uniform(param, hyperparameters) logprior_exponential(param, hyperparameters) logprior_lognormal(param, hyperparameters) logprior_weibull(param, hyperparameters) logprior_invgamma(param, hyperparameters)logprior_gamma(param, hyperparameters) logprior_normal(param, hyperparameters) logprior_beta(param, hyperparameters) logprior_uniform(param, hyperparameters) logprior_exponential(param, hyperparameters) logprior_lognormal(param, hyperparameters) logprior_weibull(param, hyperparameters) logprior_invgamma(param, hyperparameters)
param |
Numeric vector of parameters |
hyperparameters |
List of hyperparameters for the prior |
Numeric value of the log-prior density
logprior_gamma(): Gamma prior log-density
logprior_normal(): Normal prior log-density
logprior_beta(): Beta prior log-density
logprior_uniform(): Uniform prior log-density
logprior_exponential(): Exponential prior log-density
logprior_lognormal(): Log-Normal prior log-density
logprior_weibull(): Weibull prior log-density
logprior_invgamma(): Inverse Gamma prior log-density
Computes residuals from a fitted tkfit object.
## S3 method for class 'tkfit' residuals(object, type = "pearson", ...)## S3 method for class 'tkfit' residuals(object, type = "pearson", ...)
object |
A tkfit object |
type |
Type of residuals ("pearson", "deviance") |
... |
Additional arguments (ignored) |
Residual values
Summary Method for tkfit Objects
## S3 method for class 'tkfit' summary(object, ...)## S3 method for class 'tkfit' summary(object, ...)
object |
A tkfit object |
... |
Additional arguments (ignored) |
Invisibly returns the input object object of class "tkfit", called for side effects.
Computes the Tierney-Kadane approximation of E(g(theta) | x) for a given function g. This is the core computational engine for all Bayes estimators.
tk_expectation( log_post_fn, g, mode_result, hessian_result, initial_values_star = NULL, ... )tk_expectation( log_post_fn, g, mode_result, hessian_result, initial_values_star = NULL, ... )
log_post_fn |
Log-posterior function from |
g |
Function g(theta) for which to compute the expectation |
mode_result |
Result from |
hessian_result |
Result from |
initial_values_star |
Initial values for optimizing h*(theta) (defaults to mode) |
... |
Additional arguments passed to |
An object of class "tkexpectation" (a list) containing:
expectation |
Numeric scalar representing the Tierney-Kadane approximation of E(g(theta) | x). |
theta_hat |
Numeric vector, posterior mode of h(theta). |
theta_star |
Numeric vector, posterior mode of modified log-posterior h*(theta). |
h_theta_hat |
Numeric scalar, h(theta) evaluated at theta_hat. |
h_star_theta_star |
Numeric scalar, h*(theta) evaluated at theta_star. |
Sigma |
Curvature matrix (-H^-1) at theta_hat. |
Sigma_star |
Curvature matrix (-H*^-1) at theta_star. |
det_Sigma |
Determinant of Sigma. |
det_Sigma_star |
Determinant of Sigma_star. |
ratio |
Square root determinant ratio sqrt(|Sigma*| / |Sigma|). |
exponent |
Exponential factor n * (h*(theta_star) - h(theta_hat)). |
n |
Effective sample size. |
mode_result |
Full output from |
mode_star_result |
Full output from |
hessian_result |
Full output from |
hessian_star_result |
Full output from |
pdf_exp <- function(x, param) dexp(x, rate = param[1]) cdf_exp <- function(x, param) pexp(x, rate = param[1]) prior_spec <- list(rate = list(family = "gamma", hyperparameters = list(shape = 2, rate = 1))) data <- c(1.2, 2.3, 1.8, 3.1, 0.9) log_post <- tk_posterior(data, "complete", pdf_exp, cdf_exp, prior_spec) mode_result <- tk_mode(log_post, initial_values = c(1)) hessian_result <- tk_hessian(log_post, mode_result$mode) g_fn <- function(param) param[1] tk_exp <- tk_expectation(log_post, g_fn, mode_result, hessian_result)pdf_exp <- function(x, param) dexp(x, rate = param[1]) cdf_exp <- function(x, param) pexp(x, rate = param[1]) prior_spec <- list(rate = list(family = "gamma", hyperparameters = list(shape = 2, rate = 1))) data <- c(1.2, 2.3, 1.8, 3.1, 0.9) log_post <- tk_posterior(data, "complete", pdf_exp, cdf_exp, prior_spec) mode_result <- tk_mode(log_post, initial_values = c(1)) hessian_result <- tk_hessian(log_post, mode_result$mode) g_fn <- function(param) param[1] tk_exp <- tk_expectation(log_post, g_fn, mode_result, hessian_result)
Computes TK approximations for multiple functions g_i(theta) efficiently by reusing the posterior mode and Hessian.
tk_expectations(log_post_fn, g_list, mode_result, hessian_result, ...)tk_expectations(log_post_fn, g_list, mode_result, hessian_result, ...)
log_post_fn |
Log-posterior function from |
g_list |
List of functions g_i(theta) for which to compute expectations |
mode_result |
Result from |
hessian_result |
Result from |
... |
Additional arguments passed to |
Named vector of expectations
Performs Bayesian parameter estimation for user-specified univariate probability distributions using the Tierney-Kadane approximation.
tk_fit( data, censoring_scheme, pdf, cdf = NULL, prior_spec = NULL, loglik = NULL, initial_values, lower_bounds = NULL, upper_bounds = NULL, loss_function = "sel", loss_params = NULL, custom_g = NULL, optimization_method = "BFGS", hessian_method = "Richardson", analytic_hessian = NULL, true_parameter = NULL, ... )tk_fit( data, censoring_scheme, pdf, cdf = NULL, prior_spec = NULL, loglik = NULL, initial_values, lower_bounds = NULL, upper_bounds = NULL, loss_function = "sel", loss_params = NULL, custom_g = NULL, optimization_method = "BFGS", hessian_method = "Richardson", analytic_hessian = NULL, true_parameter = NULL, ... )
data |
Data (format depends on censoring scheme: vector, matrix, or data.frame) |
censoring_scheme |
Character string specifying the censoring scheme |
pdf |
User-supplied density/mass function |
cdf |
User-supplied CDF function (required for censored schemes) |
prior_spec |
List specifying prior for each parameter, or a single prior function |
loglik |
Optional user-supplied log-likelihood function |
initial_values |
Initial parameter values for optimization |
lower_bounds |
Lower bounds for parameters (optional) |
upper_bounds |
Upper bounds for parameters (optional) |
loss_function |
Loss function for Bayes estimation ("sel", "linex", "gel", "precautionary", "weighted-sel", "custom") |
loss_params |
List of parameters for the loss function (e.g., c for LINEX, q for GEL) |
custom_g |
Custom g(theta) function for custom loss |
optimization_method |
Optimization method ("BFGS", "L-BFGS-B", "Nelder-Mead", "nlminb", "maxLik", "trust") |
hessian_method |
Method for numerical differentiation ("Richardson", "simple") |
analytic_hessian |
Optional user-supplied analytic Hessian function |
true_parameter |
True parameter values (for bias calculation in simulation studies) |
... |
Additional arguments for censoring schemes (status, censoring_time, n, r, removals, etc.) |
An object of class "tkfit" (a list) containing:
posterior_mode |
Named numeric vector of posterior MAP estimates. |
bayes_estimates |
Named numeric vector of Tierney-Kadane Bayes estimates. |
loss_function |
Character string specifying the loss function used. |
loss_params |
List of specific parameters for the loss function (if any). |
covariance |
Numeric matrix of approximate posterior covariances. |
standard_errors |
Named numeric vector of posterior standard errors. |
credible_intervals |
Matrix containing 95% normal-approximation credible intervals. |
true_parameter |
Numeric vector of true parameter values if provided. |
bias |
Named numeric vector of estimation bias if true_parameter was provided. |
relative_bias |
Named numeric vector of relative bias if true_parameter was provided. |
log_posterior_at_mode |
Numeric scalar value of log-posterior at mode. |
log_likelihood_at_mode |
Numeric scalar value of log-likelihood at mode. |
prior_at_mode |
Numeric scalar value of log-prior density at mode. |
optimization_method |
Character string indicating optimizer used. |
convergence |
Integer status code from optimizer (0 = success). |
iterations |
Integer, number of iterations taken by optimizer. |
gradient_norm |
Numeric scalar, norm of gradient at posterior mode. |
hessian |
Hessian matrix of scaled log-posterior h(theta) at mode. |
Sigma |
Curvature matrix (-H^-1). |
hessian_result |
Full output list from |
data |
Input data. |
censoring_scheme |
Character string, censoring scheme used. |
pdf |
Probability density function used. |
cdf |
Cumulative distribution function used. |
prior_spec |
Prior specification supplied. |
loglik |
User-supplied log-likelihood function used (if any). |
initial_values |
Initial parameter values used. |
lower_bounds |
Lower bounds specified. |
upper_bounds |
Upper bounds specified. |
extra_args |
List of extra censoring arguments. |
n |
Effective sample size. |
execution_time |
Execution time in seconds. |
session_info |
Output from |
call |
Matched function call. |
pdf_exp <- function(x, param) dexp(x, rate = param[1]) cdf_exp <- function(x, param) pexp(x, rate = param[1]) prior_spec <- list(rate = list(family = "gamma", hyperparameters = list(shape = 2, rate = 1))) data <- c(1.2, 2.3, 1.8, 3.1, 0.9) fit <- tk_fit(data, "complete", pdf_exp, cdf_exp, prior_spec, initial_values = c(rate = 1), loss_function = "sel") summary(fit)pdf_exp <- function(x, param) dexp(x, rate = param[1]) cdf_exp <- function(x, param) pexp(x, rate = param[1]) prior_spec <- list(rate = list(family = "gamma", hyperparameters = list(shape = 2, rate = 1))) data <- c(1.2, 2.3, 1.8, 3.1, 0.9) fit <- tk_fit(data, "complete", pdf_exp, cdf_exp, prior_spec, initial_values = c(rate = 1), loss_function = "sel") summary(fit)
Computes the Hessian of the log-posterior at a given parameter value and derives the approximate posterior covariance matrix.
tk_hessian( log_post_fn, param, method = "Richardson", analytic_hessian = NULL, validate_analytic = TRUE )tk_hessian( log_post_fn, param, method = "Richardson", analytic_hessian = NULL, validate_analytic = TRUE )
log_post_fn |
Log-posterior function from |
param |
Parameter vector at which to evaluate the Hessian |
method |
Method for numerical differentiation ("Richardson", "simple") |
analytic_hessian |
Optional user-supplied analytic Hessian function |
validate_analytic |
Whether to validate analytic Hessian against numerical |
An object of class "tkhessian" (a list) containing:
hessian |
Hessian matrix of scaled log-posterior h(theta) evaluated at |
Sigma |
Curvature matrix (-H^-1). |
covariance |
Approximate posterior covariance matrix (Sigma / n). |
standard_errors |
Named numeric vector of posterior standard errors. |
parameter |
Parameter vector evaluated. |
method |
Numerical differentiation method used. |
validation |
Analytic Hessian validation results list, or |
pdf_exp <- function(x, param) dexp(x, rate = param[1]) cdf_exp <- function(x, param) pexp(x, rate = param[1]) prior_spec <- list(rate = list(family = "gamma", hyperparameters = list(shape = 2, rate = 1))) data <- c(1.2, 2.3, 1.8, 3.1, 0.9) log_post <- tk_posterior(data, "complete", pdf_exp, cdf_exp, prior_spec) mode_result <- tk_mode(log_post, initial_values = c(1)) hess_result <- tk_hessian(log_post, mode_result$mode)pdf_exp <- function(x, param) dexp(x, rate = param[1]) cdf_exp <- function(x, param) pexp(x, rate = param[1]) prior_spec <- list(rate = list(family = "gamma", hyperparameters = list(shape = 2, rate = 1))) data <- c(1.2, 2.3, 1.8, 3.1, 0.9) log_post <- tk_posterior(data, "complete", pdf_exp, cdf_exp, prior_spec) mode_result <- tk_mode(log_post, initial_values = c(1)) hess_result <- tk_hessian(log_post, mode_result$mode)
Computes Bayes estimators under different loss functions using the Tierney-Kadane approximation framework.
Dispatches to the appropriate loss function based on the loss type.
tk_loss(loss_type, log_post_fn, mode_result, hessian_result, ...)tk_loss(loss_type, log_post_fn, mode_result, hessian_result, ...)
loss_type |
Character string specifying the loss function ("sel", "linex", "gel", "precautionary", "weighted-sel", "custom") |
log_post_fn |
Log-posterior function from |
mode_result |
Result from |
hessian_result |
Result from |
... |
Additional arguments specific to the loss function (e.g. c for LINEX, q for GEL, g for custom) |
Named numeric vector of Bayes parameter estimates under specified loss.
Bayes estimate(s) under the specified loss function
Computes a Bayes estimator for a user-specified loss function.
tk_loss_custom( log_post_fn, mode_result, hessian_result, g, parameter_index = NULL, ... )tk_loss_custom( log_post_fn, mode_result, hessian_result, g, parameter_index = NULL, ... )
log_post_fn |
Log-posterior function from |
mode_result |
Result from |
hessian_result |
Result from |
g |
Function g(theta) for the expectation |
parameter_index |
Index of parameter to estimate (NULL for all parameters) |
... |
Additional arguments passed to |
Bayes estimate(s) under custom loss
pdf_exp <- function(x, param) dexp(x, rate = param[1]) cdf_exp <- function(x, param) pexp(x, rate = param[1]) prior_spec <- list(rate = list(family = "gamma", hyperparameters = list(shape = 2, rate = 1))) data <- c(1.2, 2.3, 1.8, 3.1, 0.9) log_post <- tk_posterior(data, "complete", pdf_exp, cdf_exp, prior_spec) mode_result <- tk_mode(log_post, initial_values = c(1)) hessian_result <- tk_hessian(log_post, mode_result$mode) g_fn <- function(param) log(param[1]) custom_estimate <- tk_loss_custom(log_post, mode_result, hessian_result, g_fn)pdf_exp <- function(x, param) dexp(x, rate = param[1]) cdf_exp <- function(x, param) pexp(x, rate = param[1]) prior_spec <- list(rate = list(family = "gamma", hyperparameters = list(shape = 2, rate = 1))) data <- c(1.2, 2.3, 1.8, 3.1, 0.9) log_post <- tk_posterior(data, "complete", pdf_exp, cdf_exp, prior_spec) mode_result <- tk_mode(log_post, initial_values = c(1)) hessian_result <- tk_hessian(log_post, mode_result$mode) g_fn <- function(param) log(param[1]) custom_estimate <- tk_loss_custom(log_post, mode_result, hessian_result, g_fn)
Computes the Bayes estimator under General Entropy Loss. Estimator: theta_hat = (E(theta^(-q) | x))^(-1/q)
tk_loss_gel( log_post_fn, mode_result, hessian_result, q = 0.5, parameter_index = NULL, ... )tk_loss_gel( log_post_fn, mode_result, hessian_result, q = 0.5, parameter_index = NULL, ... )
log_post_fn |
Log-posterior function from |
mode_result |
Result from |
hessian_result |
Result from |
q |
GEL shape parameter (q != 0) |
parameter_index |
Index of parameter to estimate (NULL for all parameters) |
... |
Additional arguments passed to |
Bayes estimate(s) under GEL
pdf_exp <- function(x, param) dexp(x, rate = param[1]) cdf_exp <- function(x, param) pexp(x, rate = param[1]) prior_spec <- list(rate = list(family = "gamma", hyperparameters = list(shape = 2, rate = 1))) data <- c(1.2, 2.3, 1.8, 3.1, 0.9) log_post <- tk_posterior(data, "complete", pdf_exp, cdf_exp, prior_spec) mode_result <- tk_mode(log_post, initial_values = c(1)) hessian_result <- tk_hessian(log_post, mode_result$mode) gel_estimate <- tk_loss_gel(log_post, mode_result, hessian_result, q = 0.5)pdf_exp <- function(x, param) dexp(x, rate = param[1]) cdf_exp <- function(x, param) pexp(x, rate = param[1]) prior_spec <- list(rate = list(family = "gamma", hyperparameters = list(shape = 2, rate = 1))) data <- c(1.2, 2.3, 1.8, 3.1, 0.9) log_post <- tk_posterior(data, "complete", pdf_exp, cdf_exp, prior_spec) mode_result <- tk_mode(log_post, initial_values = c(1)) hessian_result <- tk_hessian(log_post, mode_result$mode) gel_estimate <- tk_loss_gel(log_post, mode_result, hessian_result, q = 0.5)
Computes the Bayes estimator under LINEX (Linear-Exponential) loss. Estimator: theta_hat = -(1/c) * log E(exp(-c * theta) | x)
tk_loss_linex( log_post_fn, mode_result, hessian_result, c = 0.5, parameter_index = NULL, ... )tk_loss_linex( log_post_fn, mode_result, hessian_result, c = 0.5, parameter_index = NULL, ... )
log_post_fn |
Log-posterior function from |
mode_result |
Result from |
hessian_result |
Result from |
c |
LINEX shape parameter (c != 0) |
parameter_index |
Index of parameter to estimate (NULL for all parameters) |
... |
Additional arguments passed to |
Bayes estimate(s) under LINEX loss
pdf_exp <- function(x, param) dexp(x, rate = param[1]) cdf_exp <- function(x, param) pexp(x, rate = param[1]) prior_spec <- list(rate = list(family = "gamma", hyperparameters = list(shape = 2, rate = 1))) data <- c(1.2, 2.3, 1.8, 3.1, 0.9) log_post <- tk_posterior(data, "complete", pdf_exp, cdf_exp, prior_spec) mode_result <- tk_mode(log_post, initial_values = c(1)) hessian_result <- tk_hessian(log_post, mode_result$mode) linex_estimate <- tk_loss_linex(log_post, mode_result, hessian_result, c = 0.5)pdf_exp <- function(x, param) dexp(x, rate = param[1]) cdf_exp <- function(x, param) pexp(x, rate = param[1]) prior_spec <- list(rate = list(family = "gamma", hyperparameters = list(shape = 2, rate = 1))) data <- c(1.2, 2.3, 1.8, 3.1, 0.9) log_post <- tk_posterior(data, "complete", pdf_exp, cdf_exp, prior_spec) mode_result <- tk_mode(log_post, initial_values = c(1)) hessian_result <- tk_hessian(log_post, mode_result$mode) linex_estimate <- tk_loss_linex(log_post, mode_result, hessian_result, c = 0.5)
Computes the Bayes estimator under precautionary loss. Estimator: theta_hat = sqrt(E(theta^2 | x))
tk_loss_precautionary( log_post_fn, mode_result, hessian_result, parameter_index = NULL, ... )tk_loss_precautionary( log_post_fn, mode_result, hessian_result, parameter_index = NULL, ... )
log_post_fn |
Log-posterior function from |
mode_result |
Result from |
hessian_result |
Result from |
parameter_index |
Index of parameter to estimate (NULL for all parameters) |
... |
Additional arguments passed to |
Bayes estimate(s) under precautionary loss
pdf_exp <- function(x, param) dexp(x, rate = param[1]) cdf_exp <- function(x, param) pexp(x, rate = param[1]) prior_spec <- list(rate = list(family = "gamma", hyperparameters = list(shape = 2, rate = 1))) data <- c(1.2, 2.3, 1.8, 3.1, 0.9) log_post <- tk_posterior(data, "complete", pdf_exp, cdf_exp, prior_spec) mode_result <- tk_mode(log_post, initial_values = c(1)) hessian_result <- tk_hessian(log_post, mode_result$mode) precautionary_estimate <- tk_loss_precautionary(log_post, mode_result, hessian_result)pdf_exp <- function(x, param) dexp(x, rate = param[1]) cdf_exp <- function(x, param) pexp(x, rate = param[1]) prior_spec <- list(rate = list(family = "gamma", hyperparameters = list(shape = 2, rate = 1))) data <- c(1.2, 2.3, 1.8, 3.1, 0.9) log_post <- tk_posterior(data, "complete", pdf_exp, cdf_exp, prior_spec) mode_result <- tk_mode(log_post, initial_values = c(1)) hessian_result <- tk_hessian(log_post, mode_result$mode) precautionary_estimate <- tk_loss_precautionary(log_post, mode_result, hessian_result)
Computes the posterior mean (Bayes estimator under squared error loss).
tk_loss_sel( log_post_fn, mode_result, hessian_result, parameter_index = NULL, ... )tk_loss_sel( log_post_fn, mode_result, hessian_result, parameter_index = NULL, ... )
log_post_fn |
Log-posterior function from |
mode_result |
Result from |
hessian_result |
Result from |
parameter_index |
Index of parameter to estimate (NULL for all parameters) |
... |
Additional arguments passed to |
Bayes estimate(s) under SEL
pdf_exp <- function(x, param) dexp(x, rate = param[1]) cdf_exp <- function(x, param) pexp(x, rate = param[1]) prior_spec <- list(rate = list(family = "gamma", hyperparameters = list(shape = 2, rate = 1))) data <- c(1.2, 2.3, 1.8, 3.1, 0.9) log_post <- tk_posterior(data, "complete", pdf_exp, cdf_exp, prior_spec) mode_result <- tk_mode(log_post, initial_values = c(1)) hessian_result <- tk_hessian(log_post, mode_result$mode) sel_estimate <- tk_loss_sel(log_post, mode_result, hessian_result)pdf_exp <- function(x, param) dexp(x, rate = param[1]) cdf_exp <- function(x, param) pexp(x, rate = param[1]) prior_spec <- list(rate = list(family = "gamma", hyperparameters = list(shape = 2, rate = 1))) data <- c(1.2, 2.3, 1.8, 3.1, 0.9) log_post <- tk_posterior(data, "complete", pdf_exp, cdf_exp, prior_spec) mode_result <- tk_mode(log_post, initial_values = c(1)) hessian_result <- tk_hessian(log_post, mode_result$mode) sel_estimate <- tk_loss_sel(log_post, mode_result, hessian_result)
Computes the Bayes estimator under weighted squared error loss. Estimator: theta_hat = 1 / E(theta^(-1) | x)
tk_loss_weighted_sel( log_post_fn, mode_result, hessian_result, parameter_index = NULL, ... )tk_loss_weighted_sel( log_post_fn, mode_result, hessian_result, parameter_index = NULL, ... )
log_post_fn |
Log-posterior function from |
mode_result |
Result from |
hessian_result |
Result from |
parameter_index |
Index of parameter to estimate (NULL for all parameters) |
... |
Additional arguments passed to |
Bayes estimate(s) under weighted SEL
pdf_exp <- function(x, param) dexp(x, rate = param[1]) cdf_exp <- function(x, param) pexp(x, rate = param[1]) prior_spec <- list(rate = list(family = "gamma", hyperparameters = list(shape = 2, rate = 1))) data <- c(1.2, 2.3, 1.8, 3.1, 0.9) log_post <- tk_posterior(data, "complete", pdf_exp, cdf_exp, prior_spec) mode_result <- tk_mode(log_post, initial_values = c(1)) hessian_result <- tk_hessian(log_post, mode_result$mode) weighted_estimate <- tk_loss_weighted_sel(log_post, mode_result, hessian_result)pdf_exp <- function(x, param) dexp(x, rate = param[1]) cdf_exp <- function(x, param) pexp(x, rate = param[1]) prior_spec <- list(rate = list(family = "gamma", hyperparameters = list(shape = 2, rate = 1))) data <- c(1.2, 2.3, 1.8, 3.1, 0.9) log_post <- tk_posterior(data, "complete", pdf_exp, cdf_exp, prior_spec) mode_result <- tk_mode(log_post, initial_values = c(1)) hessian_result <- tk_hessian(log_post, mode_result$mode) weighted_estimate <- tk_loss_weighted_sel(log_post, mode_result, hessian_result)
Locates the posterior mode (MAP estimate) using numerical optimization. Supports multiple optimization backends with automatic fallback.
tk_mode( log_post_fn, initial_values, lower_bounds = NULL, upper_bounds = NULL, method = "BFGS", control = NULL, max_attempts = 3 )tk_mode( log_post_fn, initial_values, lower_bounds = NULL, upper_bounds = NULL, method = "BFGS", control = NULL, max_attempts = 3 )
log_post_fn |
Log-posterior function from |
initial_values |
Initial parameter values for optimization |
lower_bounds |
Lower bounds for parameters (optional) |
upper_bounds |
Upper bounds for parameters (optional) |
method |
Optimization method ("BFGS", "L-BFGS-B", "Nelder-Mead", "nlminb", "maxLik", "trust") |
control |
List of control parameters for the optimizer |
max_attempts |
Maximum number of optimization attempts with different methods |
An object of class "tkmode" (a list) containing:
mode |
Named numeric vector of MAP parameter estimates. |
convergence |
Integer status code from optimizer (0 = success). |
log_posterior |
Numeric scalar, log-posterior value evaluated at mode. |
iterations |
Integer, number of iterations taken. |
method |
Character string, optimization method used. |
message |
Warning or informational message string. |
gradient_norm |
Numeric scalar, norm of gradient at mode. |
gradient |
Numeric vector, gradient evaluated at mode. |
pdf_exp <- function(x, param) dexp(x, rate = param[1]) cdf_exp <- function(x, param) pexp(x, rate = param[1]) prior_spec <- list(rate = list(family = "gamma", hyperparameters = list(shape = 2, rate = 1))) data <- c(1.2, 2.3, 1.8, 3.1, 0.9) log_post <- tk_posterior(data, "complete", pdf_exp, cdf_exp, prior_spec) mode_result <- tk_mode(log_post, initial_values = c(1), method = "BFGS")pdf_exp <- function(x, param) dexp(x, rate = param[1]) cdf_exp <- function(x, param) pexp(x, rate = param[1]) prior_spec <- list(rate = list(family = "gamma", hyperparameters = list(shape = 2, rate = 1))) data <- c(1.2, 2.3, 1.8, 3.1, 0.9) log_post <- tk_posterior(data, "complete", pdf_exp, cdf_exp, prior_spec) mode_result <- tk_mode(log_post, initial_values = c(1), method = "BFGS")
Functions to create diagnostic and exploratory plots for Tierney-Kadane Bayesian estimation results.
Dispatches to plot.tkfit for graphical diagnostics.
tk_plot(x, ...)tk_plot(x, ...)
x |
A tkfit object |
... |
Additional arguments passed to plot.tkfit |
Invisibly returns the input object or NULL, called for side effects.
Invisibly returns the input x object of class "tkfit", called for side effects.
pdf_exp <- function(x, param) dexp(x, rate = param[1]) cdf_exp <- function(x, param) pexp(x, rate = param[1]) prior_spec <- list(rate = list(family = "gamma", hyperparameters = list(shape = 2, rate = 1))) data <- c(1.2, 2.3, 1.8, 3.1, 0.9) fit <- tk_fit(data, "complete", pdf_exp, cdf_exp, prior_spec, initial_values = c(rate = 1)) tk_plot(fit, which = 1)pdf_exp <- function(x, param) dexp(x, rate = param[1]) cdf_exp <- function(x, param) pexp(x, rate = param[1]) prior_spec <- list(rate = list(family = "gamma", hyperparameters = list(shape = 2, rate = 1))) data <- c(1.2, 2.3, 1.8, 3.1, 0.9) fit <- tk_fit(data, "complete", pdf_exp, cdf_exp, prior_spec, initial_values = c(rate = 1)) tk_plot(fit, which = 1)
Creates a function that computes the log-posterior density for a given parameter vector, combining the log-likelihood and log-prior.
tk_posterior( data, censoring_scheme, pdf, cdf = NULL, prior_spec = NULL, loglik = NULL, ... )tk_posterior( data, censoring_scheme, pdf, cdf = NULL, prior_spec = NULL, loglik = NULL, ... )
data |
Data (format depends on censoring scheme: vector, matrix, or data.frame) |
censoring_scheme |
Character string specifying the censoring scheme |
pdf |
User-supplied density/mass function |
cdf |
User-supplied CDF function (required for censored schemes) |
prior_spec |
List specifying prior for each parameter, or a single prior function |
loglik |
Optional user-supplied log-likelihood function |
... |
Additional arguments for censoring schemes (status, censoring_time, n, r, removals, etc.) |
A function that takes a parameter vector and returns the log-posterior h(theta) = (log L + log pi) / n
pdf_exp <- function(x, param) dexp(x, rate = param[1]) cdf_exp <- function(x, param) pexp(x, rate = param[1]) prior_spec <- list(rate = list(family = "gamma", hyperparameters = list(shape = 2, rate = 1))) data <- c(1.2, 2.3, 1.8, 3.1, 0.9) log_post <- tk_posterior(data, "complete", pdf_exp, cdf_exp, prior_spec) log_post(c(1.5))pdf_exp <- function(x, param) dexp(x, rate = param[1]) cdf_exp <- function(x, param) pexp(x, rate = param[1]) prior_spec <- list(rate = list(family = "gamma", hyperparameters = list(shape = 2, rate = 1))) data <- c(1.2, 2.3, 1.8, 3.1, 0.9) log_post <- tk_posterior(data, "complete", pdf_exp, cdf_exp, prior_spec) log_post(c(1.5))
Performs sensitivity analysis by varying prior hyperparameters and examining the impact on Bayes estimates, bias, variance, and risk.
tk_sensitivity( fit, parameter_name, hyperparameter_name, hyperparameter_values, loss_function = "sel", loss_params = NULL, ... )tk_sensitivity( fit, parameter_name, hyperparameter_name, hyperparameter_values, loss_function = "sel", loss_params = NULL, ... )
fit |
A tkfit object to use as the base model |
parameter_name |
Name of the parameter whose prior hyperparameters to vary |
hyperparameter_name |
Name of the hyperparameter to vary |
hyperparameter_values |
Vector of hyperparameter values to test |
loss_function |
Loss function to use for estimation |
loss_params |
Parameters for the loss function |
... |
Additional arguments passed to |
An object of class "tksensitivity" (a list) containing:
parameter_name |
Character string, target parameter name. |
hyperparameter_name |
Character string, varied hyperparameter name. |
hyperparameter_values |
Numeric vector of tested hyperparameter values. |
results |
Data frame summarizing estimates, standard errors, log-posterior, log-likelihood, and risk values. |
plot_data |
List containing structured data for diagnostic plotting. |
base_fit |
The base |
loss_function |
Character string of the loss function used. |
pdf_exp <- function(x, param) dexp(x, rate = param[1]) cdf_exp <- function(x, param) pexp(x, rate = param[1]) prior_spec <- list(rate = list(family = "gamma", hyperparameters = list(shape = 2, rate = 1))) data <- c(1.2, 2.3, 1.8, 3.1, 0.9) fit <- tk_fit(data, "complete", pdf_exp, cdf_exp, prior_spec, initial_values = c(rate = 1)) sensitivity <- tk_sensitivity(fit, "rate", "shape", c(1, 2, 5))pdf_exp <- function(x, param) dexp(x, rate = param[1]) cdf_exp <- function(x, param) pexp(x, rate = param[1]) prior_spec <- list(rate = list(family = "gamma", hyperparameters = list(shape = 2, rate = 1))) data <- c(1.2, 2.3, 1.8, 3.1, 0.9) fit <- tk_fit(data, "complete", pdf_exp, cdf_exp, prior_spec, initial_values = c(rate = 1)) sensitivity <- tk_sensitivity(fit, "rate", "shape", c(1, 2, 5))
Extracts the approximate posterior covariance matrix from a tkfit object.
## S3 method for class 'tkfit' vcov(object, ...)## S3 method for class 'tkfit' vcov(object, ...)
object |
A tkfit object |
... |
Additional arguments (ignored) |
Covariance matrix