## ----include = FALSE----------------------------------------------------------
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

## -----------------------------------------------------------------------------
library(UniLindleyApprox)

# Define probability functions for Exponential(rate)
dexp_custom <- function(x, theta) dexp(x, rate = theta[1])
pexp_custom <- function(x, theta) pexp(x, rate = theta[1])
sexp_custom <- function(x, theta) 1 - pexp(x, rate = theta[1])

# Gamma prior for rate parameter
logprior <- function(theta) dgamma(theta[1], shape = 2, rate = 1, log = TRUE)

# Simulated data
set.seed(42)
x <- rexp(50, rate = 2)

# Fit model using Lindley's approximation
fit <- lindley_fit(
  data = x,
  pdf = dexp_custom,
  cdf = pexp_custom,
  survival = sexp_custom,
  log_prior = logprior,
  theta0 = c(1.5),
  scheme = "complete",
  loss = "SELF"
)

# Print results
print(fit)
summary(fit)

## -----------------------------------------------------------------------------
# SELF Bayes estimate
b_self <- bayes_estimate(fit, loss = "SELF")

# LINEX Bayes estimate
b_linex <- bayes_estimate(fit, loss = "LINEX", a = 0.5)

# GELF Bayes estimate
b_gelf <- bayes_estimate(fit, loss = "GELF", q = 2)

cat("SELF Bayes Estimate: ", b_self, "\n")
cat("LINEX Bayes Estimate: ", b_linex, "\n")
cat("GELF Bayes Estimate: ", b_gelf, "\n")

## -----------------------------------------------------------------------------
cat("AIC: ", AIC(fit), "\n")
cat("BIC: ", BIC(fit), "\n")
cat("AICc: ", AICc(fit), "\n")
cat("HQIC: ", HQIC(fit), "\n")

