The hardware and bandwidth for this mirror is donated by METANET, the Webhosting and Full Service-Cloud Provider.
If you wish to report a bug, or if you are interested in having us mirror your free-software or open-source project, please feel free to contact us at mirror[@]metanet.ch.
TKApprox provides a distribution-independent framework for Bayesian estimation of arbitrary univariate probability models using the Tierney-Kadane approximation. This vignette provides a gentle introduction to the package’s main features and workflow.
The typical workflow in TKApprox follows these steps:
tk_fit() to perform Bayesian estimationLet’s start with a simple example using the exponential distribution.
## Tierney-Kadane Bayesian Estimation
## ===================================
##
## Censoring scheme: complete
## Sample size: 20
## Loss function: sel
## Optimization method: nlminb
## Convergence: 0
## Iterations: 7
## Execution time: 0.0377 seconds
##
## Posterior mode (MAP):
## rate
## 1.777306
##
## Bayes estimates (sel):
## rate
## 1.862275
##
## Standard errors:
## rate
## 0.38784
##
## 95% Credible intervals (normal approximation):
## 2.5 % 97.5 %
## rate 1.102123 2.622428
##
## Log-posterior at mode: -0.4461
## Log-likelihood at mode: -7.7207
##
## === Tierney-Kadane Bayesian Estimation Summary ===
##
## Model Information:
## -----------------
## Censoring scheme: complete
## Sample size: 20
## Number of parameters: 1
## Loss function: sel
##
## Optimization Results:
## --------------------
## Method: nlminb
## Convergence code: 0
## Iterations: 7
## Gradient norm: 0
## Execution time: 0.0377 seconds
##
## Parameter Estimates:
## --------------------
## Parameter Posterior_Mode Bayes_Estimate Std_Error CI_Lower CI_Upper
## rate 1.777306 1.862275 0.38784 1.102123 2.622428
##
## Model Fit Statistics:
## ---------------------
## Log-posterior at mode: -0.4461
## Log-likelihood at mode: -7.7207
## Prior contribution: -1.2022
##
## Posterior Covariance Matrix:
## ---------------------------
## rate
## rate 0.15042
## rate
## 1.862275
## rate
## rate 0.1504198
##
## === Model Comparison Statistics ===
##
## Statistic Value
## Log-Likelihood -7.7207187
## Negative Log-Likelihood 7.7207187
## AIC 17.4414374
## BIC 18.4371697
## CAIC 19.4371697
## HQIC 17.6358148
## DIC 17.4414374
## Expected Log-Posterior -0.4461463
## Number of Parameters 1.0000000
## Sample Size 20.0000000
TKApprox supports multiple Bayesian loss functions:
fit_sel <- 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"
)
coef(fit_sel)## rate
## 1.862275
TKApprox handles various censoring schemes. Here’s an example with right-censored data:
# Create right-censored data
status <- c(1, 1, 0, 1, 0, 1, 1, 0, 1, 1) # 1 = observed, 0 = censored
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)##
## === Tierney-Kadane Bayesian Estimation Summary ===
##
## Model Information:
## -----------------
## Censoring scheme: right-censored
## Sample size: 20
## Number of parameters: 1
## Loss function: sel
##
## Optimization Results:
## --------------------
## Method: BFGS
## Convergence code: 0
## Iterations: 1
## Gradient norm: 0
## Execution time: 0.01 seconds
##
## Parameter Estimates:
## --------------------
## Parameter Posterior_Mode Bayes_Estimate Std_Error CI_Lower CI_Upper
## rate 1 1 0.2236068 0.5617387 1.438261
##
## Model Fit Statistics:
## ---------------------
## Log-posterior at mode: -1e+10
## Log-likelihood at mode: -Inf
## Prior contribution: -1
##
## Posterior Covariance Matrix:
## ---------------------------
## rate
## rate 0.05
Examine how sensitive your estimates are to prior hyperparameters:
sensitivity <- tk_sensitivity(
fit = fit,
parameter_name = "rate",
hyperparameter_name = "shape",
hyperparameter_values = c(0.5, 1, 2, 5, 10)
)
print(sensitivity)## Prior Sensitivity Analysis
## ==========================
## Parameter: rate
## Hyperparameter: shape
## Loss function: sel
## Number of hyperparameter values tested: 5
##
## Results:
## hyperparameter_value log_posterior log_likelihood convergence iterations
## 0.5 0 0 0 0
## 1.0 0 0 0 0
## 2.0 0 0 0 0
## 5.0 0 0 0 0
## 10.0 0 0 0 0
## estimate_rate se_rate
## NA NA
## NA NA
## NA NA
## NA NA
## NA NA
## True parameter not available; cannot compute risk.
TKApprox works with models of any dimensionality. Here’s a two-parameter example with the Weibull distribution:
# Define Weibull distribution
pdf_weibull <- function(x, param) {
dweibull(x, shape = param[1], scale = param[2])
}
cdf_weibull <- function(x, param) {
pweibull(x, shape = param[1], scale = param[2])
}
# Independent priors
prior_spec_weibull <- list(
shape = list(family = "gamma", hyperparameters = list(shape = 2, rate = 1)),
scale = list(family = "gamma", hyperparameters = list(shape = 2, rate = 1))
)
# Generate Weibull data
set.seed(123)
data_weibull <- rweibull(20, shape = 2, scale = 1)
# Fit the model
fit_weibull <- tk_fit(
data = data_weibull,
censoring_scheme = "complete",
pdf = pdf_weibull,
cdf = cdf_weibull,
prior_spec = prior_spec_weibull,
initial_values = c(shape = 1.5, scale = 1),
loss_function = "sel"
)
summary(fit_weibull)##
## === Tierney-Kadane Bayesian Estimation Summary ===
##
## Model Information:
## -----------------
## Censoring scheme: complete
## Sample size: 20
## Number of parameters: 2
## Loss function: sel
##
## Optimization Results:
## --------------------
## Method: nlminb
## Convergence code: 0
## Iterations: 6
## Gradient norm: 1e-06
## Execution time: 0.1372 seconds
##
## Parameter Estimates:
## --------------------
## Parameter Posterior_Mode Bayes_Estimate Std_Error CI_Lower CI_Upper
## shape 1.7566163 1.7595973 0.3066255 1.158622 2.360572
## scale 0.9124234 0.9476932 0.1210758 0.710389 1.184997
##
## Model Fit Statistics:
## ---------------------
## Log-posterior at mode: -0.6901
## Log-likelihood at mode: -11.6046
## Prior contribution: -2.1973
##
## Posterior Covariance Matrix:
## ---------------------------
## shape scale
## shape 0.094019 0.011196
## scale 0.011196 0.014659
These binaries (installable software) and packages are in development.
They may not be fully stable and should be used with caution. We make no claims about them.