star_MCMC_ispline: MCMC sampler for STAR with a monotone spline model for the...

View source: R/source_MCMC.R

star_MCMC_isplineR Documentation

MCMC sampler for STAR with a monotone spline model for the transformation

Description

Run the MCMC algorithm for STAR given

  1. a function to initialize model parameters; and

  2. a function to sample (i.e., update) model parameters.

The transformation is modeled as an unknown, monotone function using I-splines. The Robust Adaptive Metropolis (RAM) sampler is used for drawing the parameter of the transformation function.

Usage

star_MCMC_ispline(
  y,
  sample_params,
  init_params,
  lambda_prior = 1/2,
  y_max = Inf,
  nsave = 5000,
  nburn = 5000,
  nskip = 2,
  save_y_hat = FALSE,
  target_acc_rate = 0.3,
  adapt_rate = 0.75,
  stop_adapt_perc = 0.5,
  verbose = TRUE
)

Arguments

y

n x 1 vector of observed counts

sample_params

a function that inputs data y and a named list params containing

  1. mu: vector of conditional means (fitted values)

  2. sigma: the conditional standard deviation

  3. coefficients: a named list of parameters that determine mu

and outputs an updated list params of samples from the full conditional posterior distribution of coefficients and sigma (and updates mu)

init_params

an initializing function that inputs data y and initializes the named list params of mu, sigma, and coefficients

lambda_prior

the prior mean for the transformation g() is the Box-Cox function with parameter lambda_prior

y_max

a fixed and known upper bound for all observations; default is Inf

nsave

number of MCMC iterations to save

nburn

number of MCMC iterations to discard

nskip

number of MCMC iterations to skip between saving iterations, i.e., save every (nskip + 1)th draw

save_y_hat

logical; if TRUE, compute and save the posterior draws of the expected counts, E(y), which may be slow to compute

target_acc_rate

target acceptance rate (between zero and one)

adapt_rate

rate of adaptation in RAM sampler (between zero and one)

stop_adapt_perc

stop adapting at the proposal covariance at stop_adapt_perc*nburn

verbose

logical; if TRUE, print time remaining

Value

a list with the following elements:

  • coefficients: the posterior mean of the coefficients

  • fitted.values: the posterior mean of the conditional expectation of the counts y

  • post.coefficients: posterior draws of the coefficients

  • post.fitted.values: posterior draws of the conditional mean of the counts y

  • post.pred: draws from the posterior predictive distribution of y

  • post.g: draws from the posterior distribution of the transformation g

  • post.sigma: draws from the posterior distribution of sigma

  • post.sigma.gamma: draws from the posterior distribution of sigma.gamma, the prior standard deviation of the transformation g() coefficients

  • post.log.like.point: draws of the log-likelihood for each of the n observations

  • WAIC: Widely-Applicable/Watanabe-Akaike Information Criterion

  • p_waic: Effective number of parameters based on WAIC

Examples


## Not run: 
# Simulate data with count-valued response y:
sim_dat = simulate_nb_lm(n = 100, p = 5)
y = sim_dat$y; X = sim_dat$X

# STAR: unknown I-spline transformation
fit = star_MCMC_ispline(y = y,
                         sample_params = function(y, params) sample_params_lm(y, X, params),
                         init_params = function(y) init_params_lm(y, X))
# Posterior mean of each coefficient:
coef(fit)

# WAIC for STAR-np:
fit$WAIC

# MCMC diagnostics:
plot(as.ts(fit$post.coefficients[,1:3]))

# Posterior predictive check:
hist(apply(fit$post.pred, 1,
           function(x) mean(x==0)), main = 'Proportion of Zeros', xlab='');
abline(v = mean(y==0), lwd=4, col ='blue')


## End(Not run)

drkowal/rSTAR documentation built on July 5, 2023, 2:18 p.m.