## ----setup, include = FALSE---------------------------------------------------
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
if (requireNamespace("MYIS", quietly = TRUE)) {
  library(MYIS)
} else if (file.exists("../R")) {
  r_files <- list.files("../R", full.names = TRUE)
  lapply(r_files, source)
}

## ----example-complete---------------------------------------------------------
set.seed(123)
true_rate <- 1.8
sample_data <- rexp(100, rate = true_rate)

# User provides custom PDF function
my_pdf <- function(x, theta) {
  dexp(x, rate = theta[1])
}

# Run Moreau-Yosida MCMC Importance Sampling
fit <- my_is_estimate(
  pdf = my_pdf,
  data = sample_data,
  initial_theta = c(1.0),
  par_lower = 0.001,
  sampler = "mala",
  n_samples = 200,
  burnin = 50
)

# Print Summary
print(fit)

## ----example-censored---------------------------------------------------------
set.seed(456)
n <- 80
x_obs <- rexp(n, rate = 1.2)
c_times <- rexp(n, rate = 0.8)
t_obs <- pmin(x_obs, c_times)
delta <- as.numeric(x_obs <= c_times)

fit_censored <- my_is_estimate(
  pdf = my_pdf,
  data = t_obs,
  initial_theta = c(1.0),
  censoring = "right",
  censoring_params = list(delta = delta),
  par_lower = 0.001,
  sampler = "mala",
  n_samples = 200,
  burnin = 50
)

summary(fit_censored)

## ----example-plot, fig.width=7, fig.height=6----------------------------------
plot(fit_censored, type = "all")

