## ----setup, include = FALSE---------------------------------------------------
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  message = FALSE,
  warning = FALSE
)

## ----load-package, eval = FALSE-----------------------------------------------
# library(Romeb)

## ----install-cran, eval = FALSE-----------------------------------------------
# install.packages("Romeb")

## ----simulate-data------------------------------------------------------------
set.seed(123)

n <- 100

dat <- data.frame(
  y0 = rnorm(n, mean = 0.0, sd = 1.0),
  y1 = rnorm(n, mean = 0.5, sd = 1.0),
  y2 = rnorm(n, mean = 1.0, sd = 1.0),
  aux1 = rnorm(n)
)

time <- c(0, 1, 2)

head(dat)

## ----complete-data-fit, eval = FALSE------------------------------------------
# fit_complete <- Romeb(
#   Missing_Type = "no missing",
#   data = dat,
#   time = time,
#   seed = 123,
#   outcome_vars = c("y0", "y1", "y2"),
#   chain = 1,
#   Niter = 6000,
#   burnIn = 3000,
#   n_adapt = 1000
# )
# 
# print(fit_complete)

## ----complete-data-output, eval = FALSE---------------------------------------
# names(fit_complete)
# 
# fit_complete$parameter_map
# fit_complete$model_info

## ----simulate-missing-data----------------------------------------------------
dat_miss <- dat

set.seed(456)
missing_id <- sample(seq_len(nrow(dat_miss)), size = 20)
dat_miss$y1[missing_id] <- NA

head(dat_miss)

## ----mar-fit, eval = FALSE----------------------------------------------------
# fit_mar <- Romeb(
#   Missing_Type = "MAR",
#   data = dat_miss,
#   time = time,
#   seed = 123,
#   outcome_vars = c("y0", "y1", "y2"),
#   chain = 1,
#   Niter = 6000,
#   burnIn = 3000,
#   n_adapt = 1000
# )
# 
# print(fit_mar)

## ----mcar-fit, eval = FALSE---------------------------------------------------
# fit_mcar <- Romeb(
#   Missing_Type = "MCAR",
#   data = dat_miss,
#   time = time,
#   seed = 123,
#   outcome_vars = c("y0", "y1", "y2"),
#   chain = 1,
#   Niter = 6000,
#   burnIn = 3000,
#   n_adapt = 1000
# )
# 
# print(fit_mcar)

## ----mnar-no-aux-fit, eval = FALSE--------------------------------------------
# fit_mnar <- Romeb(
#   Missing_Type = "MNAR",
#   data = dat_miss,
#   time = time,
#   seed = 123,
#   outcome_vars = c("y0", "y1", "y2"),
#   chain = 1,
#   Niter = 6000,
#   burnIn = 3000,
#   n_adapt = 1000
# )
# 
# print(fit_mnar)

## ----mnar-aux-fit, eval = FALSE-----------------------------------------------
# fit_mnar_aux <- Romeb(
#   Missing_Type = "MNAR",
#   data = dat_miss,
#   time = time,
#   seed = 123,
#   outcome_vars = c("y0", "y1", "y2"),
#   auxiliary_vars = "aux1",
#   chain = 1,
#   Niter = 6000,
#   burnIn = 3000,
#   n_adapt = 1000
# )
# 
# print(fit_mnar_aux)

## ----mnar-aux-fit-indices, eval = FALSE---------------------------------------
# fit_mnar_aux_idx <- Romeb(
#   Missing_Type = "MNAR",
#   data = dat_miss,
#   time = time,
#   seed = 123,
#   outcome_vars = 1:3,
#   auxiliary_vars = 4,
#   chain = 1,
#   Niter = 6000,
#   burnIn = 3000,
#   n_adapt = 1000
# )

## ----prior-example, eval = FALSE----------------------------------------------
# custom_priors <- list(
#   muLS_mean = c(0, 0),
#   muLS_prec = c(0.01, 0.01),
#   sigma_shape = 0.01,
#   sigma_rate = 0.01
# )
# 
# fit_custom_priors <- Romeb(
#   Missing_Type = "no missing",
#   data = dat,
#   time = time,
#   seed = 123,
#   outcome_vars = c("y0", "y1", "y2"),
#   priors = custom_priors,
#   chain = 1,
#   Niter = 6000,
#   burnIn = 3000,
#   n_adapt = 1000
# )
# 
# print(fit_custom_priors)

## ----aux-prior-example, eval = FALSE------------------------------------------
# custom_mnar_priors <- list(
#   missing_coef_mean = c(0, 0, 0),
#   missing_coef_prec = c(0.01, 0.01, 0.01),
#   aux_coef_mean = c(0),
#   aux_coef_prec = c(0.01)
# )
# 
# fit_custom_mnar <- Romeb(
#   Missing_Type = "MNAR",
#   data = dat_miss,
#   time = time,
#   seed = 123,
#   outcome_vars = c("y0", "y1", "y2"),
#   auxiliary_vars = "aux1",
#   priors = custom_mnar_priors,
#   chain = 1,
#   Niter = 6000,
#   burnIn = 3000,
#   n_adapt = 1000
# )

## ----inits-one-chain, eval = FALSE--------------------------------------------
# fit_with_inits <- Romeb(
#   Missing_Type = "no missing",
#   data = dat,
#   time = time,
#   seed = 123,
#   outcome_vars = c("y0", "y1", "y2"),
#   inits = list(
#     muLS = c(0, 0)
#   ),
#   chain = 1,
#   Niter = 6000,
#   burnIn = 3000,
#   n_adapt = 1000
# )

## ----inits-multiple-chains, eval = FALSE--------------------------------------
# fit_two_chains <- Romeb(
#   Missing_Type = "no missing",
#   data = dat,
#   time = time,
#   seed = 123,
#   outcome_vars = c("y0", "y1", "y2"),
#   inits = list(
#     list(muLS = c(0, 0)),
#     list(muLS = c(0.1, 0.1))
#   ),
#   chain = 2,
#   Niter = 6000,
#   burnIn = 3000,
#   n_adapt = 1000
# )

## ----output-structure, eval = FALSE-------------------------------------------
# names(fit_complete)

## ----mcmc-samples, eval = FALSE-----------------------------------------------
# coda::traceplot(fit_complete$samps_full[, "latent_intercept_mean"])
# coda::summary(fit_complete$samps_full)

## ----legacy-layout, eval = FALSE----------------------------------------------
# fit_legacy <- Romeb(
#   Missing_Type = "MNAR",
#   data = dat_miss[, c("aux1", "y0", "y1", "y2")],
#   time = time,
#   seed = 123,
#   K = 1,
#   chain = 1,
#   Niter = 6000,
#   burnIn = 3000,
#   n_adapt = 1000
# )

## ----session-info-------------------------------------------------------------
sessionInfo()

