gibbs_stcos: Gibbs Sampler for STCOS Model

View source: R/gibbs_stcos.R

gibbs_stcosR Documentation

Gibbs Sampler for STCOS Model

Description

Gibbs Sampler for STCOS Model

Usage

gibbs_stcos(
  z,
  v,
  H,
  S,
  Kinv,
  R,
  report_period = R + 1,
  burn = 0,
  thin = 1,
  init = NULL,
  fixed = NULL,
  hyper = NULL
)

## S3 method for class 'stcos_gibbs'
logLik(object, ...)

## S3 method for class 'stcos_gibbs'
DIC(object, ...)

## S3 method for class 'stcos_gibbs'
print(x, ...)

## S3 method for class 'stcos_gibbs'
fitted(object, H, S, ...)

## S3 method for class 'stcos_gibbs'
predict(object, H, S, ...)

Arguments

z

Vector which represents the outcome; assumed to be direct estimates from the survey.

v

Vector which represents direct variance estimates from the survey.

H

Matrix of overlaps between source and fine-level supports.

S

Design matrix for basis decomposition.

Kinv

The precision matrix \bm{K}^{-1} of the random coefficient \bm{\eta}

R

Number of MCMC reps.

report_period

Gibbs sampler will report progress each time this many iterations are completed.

burn

Number of the R draws to discard at the beginning of the chain.

thin

After burn-in period, save one out of every thin draws.

init

A list containing the following initial values for the MCMC: sig2mu, sig2xi, sig2K, muB, eta, xi. Any values which are not specified are set to arbitrary choices.

fixed

A list specifying which parameters to keep fixed in the MCMC. This can normally be left blank. If elements sig2mu, sig2xi, or sig2K are specified they should be boolean, where TRUE means fixed (i.e. not drawn). If elements muB, eta, or xi are specified, they should each be a vector of indicies; the specified indices are to be treated as fixed (i.e. not drawn).

hyper

A list containing the following hyperparameter values: a_sig2mu, a_sig2K, a_sig2xi, b_sig2mu, b_sig2K, b_sig2xi. Any hyperparameters which are not specified are set to a default value of 2.

object

A result from gibbs_stcos.

...

Additional arguments.

x

A result from gibbs_stcos.

Details

Fits the model

\bm{Z} = \bm{H} \bm{\mu}_B + \bm{S} \bm{\eta} + \bm{\xi} + \bm{\varepsilon}, \quad \bm{\varepsilon} \sim \textrm{N}(0, \bm{V}),

\bm{\eta} \sim \textrm{N}(\bm{0}, \sigma_K^2 \bm{K}), \quad \bm{\xi} \sim \textrm{N}(0, \sigma_{\xi}^2 \bm{I}),

\bm{\mu}_B \sim \textrm{N}(\bm{0}, \sigma_\mu^2 \bm{I}), \quad \sigma_\mu^2 \sim \textrm{IG}(a_\mu, b_\mu),

\sigma_K^2 \sim \textrm{IG}(a_K, b_K), \quad \sigma_\xi^2 \sim \textrm{IG}(a_\xi, b_\xi),

using a Gibbs sampler with closed-form draws.

Helper functions produce the following outputs:

  • logLik computes the log-likelihood for each saved draw.

  • DIC computes the Deviance information criterion for each saved draw.

  • print displays a summary of the draws.

  • fitted computes the mean E(Y_i) for each observation i = 1, \ldots, n, for each saved draw.

  • predict draws Y_i for each observation i = 1, \ldots, n, using the parameter values for each saved Gibbs sampler draw.

Value

gibbs_stcos returns an stcos object which contains draws from the sampler. Helper functions take this object as an input and produce various outputs (see details).

Examples

## Not run: 
demo = prepare_stcos_demo()
out = gibbs_stcos(demo$z, demo$v, demo$H, demo$S, solve(demo$K),
    R = 100, burn = 0, thin = 1)
print(out)
logLik(out)
DIC(out)
fitted(out, demo$H, demo$S)
predict(out, demo$H, demo$S)

## End(Not run)

stcos documentation built on Aug. 21, 2023, 5:13 p.m.

Related to gibbs_stcos in stcos...