## ----setup, include=FALSE-----------------------------------------------------
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.width = 7,
  fig.height = 4.5,
  message = FALSE,
  warning = FALSE
)

## ----packages-----------------------------------------------------------------
library(VCMoE)

## ----fit----------------------------------------------------------------------
sim <- simulate_vcmoe_gaussian(
  n = 90,
  k = 2,
  seed = 21,
  separation = 1.7,
  scenario = "well_separated"
)

fit <- vcmoe_fit(
  y ~ z1 | x1,
  data = sim$data,
  u = "u",
  k = 2,
  family = "gaussian",
  bandwidth = 0.40,
  u_grid = c(0.25, 0.50, 0.75),
  engine = "joint_path_em",
  control = list(
    maxit = 12,
    n_starts = 1,
    seed = 22,
    warn_ambiguous = FALSE
  )
)

fit$engine_id
head(predict(fit, type = "posterior"))

## ----diagnostics--------------------------------------------------------------
fit$diagnostics$joint_path_converged
fit$diagnostics$joint_path_assignment
tail(fit$diagnostics$joint_path_trace)

## ----inference, eval=FALSE----------------------------------------------------
# band <- vcmoe_confband(fit, strict = FALSE)
# 
# boot <- vcmoe_bootstrap(
#   fit,
#   data = sim$data,
#   B = 200,
#   seed = 23
# )
# 
# test <- vcmoe_glrt(
#   fit,
#   data = sim$data,
#   test = "coefficient",
#   coefficient_set = "expert",
#   component = 1,
#   term = "z1",
#   calibration = "none"
# )
# 
# selection <- vcmoe_select_bandwidth(
#   y ~ z1 | x1,
#   data = sim$data,
#   u = "u",
#   family = "gaussian",
#   bandwidth_grid = c(0.30, 0.40, 0.50),
#   folds = 3,
#   u_grid = c(0.25, 0.50, 0.75),
#   engine = "joint_path_em"
# )

