BridgeRandomPanel: Sparse Change Point Model with Random Effect

Description Usage Arguments Author(s) Examples

View source: R/BridgeChangeRandomPanel.R

Description

Sparse Change Point Model with Random Effect

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
BridgeRandomPanel(
  formula,
  data,
  random = NULL,
  index,
  standardize = TRUE,
  interaction = 1,
  a = NULL,
  b = NULL,
  n.break = 1,
  alpha.MH = FALSE,
  mcmc = 100,
  burn = 100,
  verbose = 100,
  thin = 1,
  c0 = 0.1,
  d0 = 0.1,
  r0 = 1,
  R0 = 1,
  nu.shape = 2,
  nu.rate = 2,
  alpha = 1,
  Waic = FALSE,
  marginal = FALSE
)

Arguments

data

Data.frame object.

index

String vector for unit and time index variables. For example, index = c("unit", "year").

interaction

If interaction = 1, no interaciton. If interaction = 2, only two-way interaciton. Interaction can be up to K, which is the rank of the model matrix.

a

a is the shape1 beta prior for transition probabilities. By default, the expected duration is computed and corresponding a and b values are assigned. The expected duration is the sample period divided by the number of states.

b

b is the shape2 beta prior for transition probabilities. By default, the expected duration is computed and corresponding a and b values are assigned. The expected duration is the sample period divided by the number of states.

n.break

Number of breaks. If n.break = 0, it simply runs random effect model with shrinkage prior on coefficients.

alpha.MH

If TRUE, alpha is updated by MH algorithm. By default, it is updated by griddy gibbs.

mcmc

The number of MCMC iterations after burn-in.

verbose

A switch which determines whether or not the progress of the sampler is printed to the screen. If verbose is greater than 0, the iteration number and the posterior density samples are printed to the screen every verboseth iteration.

thin

The thinning interval used in the simulation. The number of MCMC iterations must be divisible by this value.

c0

Hyperparam

d0

= 0.1

r0

= 1

R0

= 1

nu.shape

=2.0

nu.rate

=2.0

alpha

= 1

fomula

Inherited from lm. For example, Y ~ X + Z.

burnin

The number of burn-in iterations for the sampler.

Author(s)

Jong Hee Park, and Soichiro Yamauchi syamauchi@princeton.edu

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
####################################
## Alvarez et al. data
####################################
library("pcse")
set.seed(1999)
data("agl")
model = "within"
index = c('country', 'year')
model = 'within'
effect = 'time'
data = agl

#########################
## HMBB estimation
#########################
## Be aware that 100 runs are too short for analysis. 
mcmc = 100; burn = 100; verbose = 100; thin = 1;
formula <- growth ~ lagg1 + opengdp + openex + openimp + leftc + central + inter


agl.cp0 <- BridgeRandomPanel(formula=formula, data = data, index = index, 
                            mcmc=mcmc, , verbose=verbose, Waic = TRUE, 
                            n.break = 0)
agl.cp1 <- BridgeRandomPanel(formula=formula, data = data, index = index, 
                            mcmc=mcmc, , verbose=verbose, Waic = TRUE, 
                            n.break = 1)
agl.cp2 <- BridgeRandomPanel(formula=formula, data = data, index = index, 
                            mcmc=mcmc, , verbose=verbose, Waic = TRUE, 
                            n.break = 2)


## model selection by WAIC
waic <- WaicCompare(list(agl.cp0, agl.cp1, agl.cp2), print = TRUE)
plotWaic(waic)

par(mfrow=c(1, 2))
MCMCpack::plotState(agl.cp1, start=1970, legend.control =c(1970, 0.85), main="One break")
MCMCpack::plotState(agl.cp2, start=1970, legend.control =c(1970, 0.85), main="Two breaks")

####################################
## dotplot over time
## time-varying movements of selected covariates
####################################
## all covariates
dotplotRegime(agl.cp1, hybrid=FALSE, start = 1970, location.bar=12, x.location="default",
              text.cex=0.8, main="Time-varying Movements of All Covariates")

## label as a legend
dotplotRegime(agl.cp1, hybrid=FALSE, start = 1970, location.bar=12, x.location="legend",
              text.cex=0.8, main="Time-varying Movements of All Covariates")

## leftc only
## select works like grep()
dotplotRegime(agl.cp1, hybrid=FALSE, start = 1970, location.bar=12, x.location="static",
              text.cex=0.8, select="left", main=("Time-varying Movements of Left Party"))

soichiroy/BridgeChange documentation built on Feb. 14, 2022, 11:49 p.m.