Package 'bltm'

Title: Bayesian Latent Threshold Modeling
Description: Fits latent threshold model for simulated data and describes how to adjust model using real data. Implements algorithm proposed by Nakajima and West (2013) <doi:10.1080/07350015.2012.747847>. This package has a function to generate data, a function to configure priors and a function to fit the model. Examples may be checked inside the demonstration files.
Authors: Julio Trecenti [cre], Fernando Tassinari [aut], Daniel Falbel [ctb]
Maintainer: Julio Trecenti <[email protected]>
License: MIT + file LICENSE
Version: 0.1.0
Built: 2024-11-11 05:15:01 UTC
Source: https://github.com/curso-r/bltm

Help Index


Create the prior parameters.

Description

Define the priors parameters to be used with ltm_mcmc().

Usage

create_prior_parameters(
  a_mu0 = 0,
  a_s0 = 0.1,
  n0 = 6,
  S0 = 0.06,
  v0 = 6,
  V0 = 0.06,
  m0 = 0,
  s0 = 1,
  a0 = 20,
  b0 = 1.5
)

Arguments

a_mu0

mean of alpha normal distribution.

a_s0

standard deviation of alpha's normal distribution.

n0

sig2 inverse gamma shape parameter.

S0

sig2 inverse gamma location parameter.

v0

sig_eta inverse gamma shape parameter.

V0

sig_eta inverse gamma location parameter.

m0

mu normal's mean parameter.

s0

mu normals standard deviation.

a0

a0 beta's shape parameter.

b0

a0 beta's location parameter.

Details

Considering the following priors:

  • alpha ~ N(mu0, s0)

  • sig2 ~ IG(n0/2, S0/2)

  • sig_eta ~ IG(v0/2, V0/2)

  • mu ~ N(m0, s0^2)

  • (phi+1)/2 ~ Beta(a0, b0)

Value

List containing the hyperparameters used to fit the model. The default parameters are the same of the simulation example of the paper.

References

Nakajima, Jouchi, and Mike West. "Bayesian analysis of latent threshold dynamic models." Journal of Business & Economic Statistics 31.2 (2013): 151-164.


MCMC LTM

Description

Given x and y performs the MCMC optimization.

Usage

ltm_mcmc(
  x,
  y,
  burnin = 2000,
  iter = 8000,
  K = 3,
  prior_par = create_prior_parameters()
)

Arguments

x

data points

y

response variable

burnin

number of burnin iterations

iter

number of iterations after burnin

K

parameter K

prior_par

List of parameters for prior distrributions. See create_prior_parameters().

Value

matrix containing the posterior samples. Each line is one sample after the burnin period and each column is one of the parameters of the model. Columns are named to find the parameters with ease.

References

Nakajima, Jouchi, and Mike West. "Bayesian analysis of latent threshold dynamic models." Journal of Business & Economic Statistics 31.2 (2013): 151-164.

Examples

# Generates 10 series, each one with 500 observations and 2 regressors.

d_sim <- ltm_sim(
  ns = 500, nk = 2, ni = 10,
  vmu = matrix(c(.5,.5), nrow = 2),
  mPhi = diag(2) * c(.99, .99),
  mSigs = c(.1,.1),
  dsig = .15,
  vd = matrix(c(.4,.4), nrow = 2),
  alpha = 0
)

# Fit model

fit_model <- ltm_mcmc(d_sim$mx, d_sim$vy, burnin = 0, iter = 2)

Simulate LTM model

Description

Simulate LTM model using many

Usage

ltm_sim(ns, nk, ni, vmu, mPhi, mSigs, dsig, vd, alpha)

Arguments

ns

number of times

nk

number of covariates

ni

number of series

vmu

vector mu

mPhi

phi diagonal matrix with the parameters

mSigs

sigma eta vector

dsig

general sigma

vd

threshold parameter

alpha

intercept

Value

List containing the generated y, x, beta and thresholded beta.

References

Nakajima, Jouchi, and Mike West. "Bayesian analysis of latent threshold dynamic models." Journal of Business & Economic Statistics 31.2 (2013): 151-164.

Examples

# Generates 10 series, each one with 500 observations and 2 regressors.

d_sim <- ltm_sim(
  ns = 500, nk = 2, ni = 10,
  vmu = matrix(c(.5,.5), nrow = 2),
  mPhi = diag(2) * c(.99, .99),
  mSigs = c(.1,.1),
  dsig = .15,
  vd = matrix(c(.4,.4), nrow = 2),
  alpha = 0
)

str(d_sim)