View source: R/BridgeChangeFixedPanel.R
BridgeFixedPanel | R Documentation |
Sparse Change Point Model with Fixed Effect
BridgeFixedPanel( formula, data, index, model, effect, 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 )
data |
Data.frame object. |
index |
String vector for unit and time index variables.
For example, |
model |
Model ( |
effect |
Effect ( |
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 |
alpha.MH |
If |
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
|
thin |
The thinning interval used in the simulation. The number of MCMC iterations must be divisible by this value. |
c0 |
Hyperparam |
d0 |
= 0.1 |
nu.shape |
=2.0 |
nu.rate |
=2.0 |
alpha |
= 1 |
fomula |
Inherited from |
burnin |
The number of burn-in iterations for the sampler. |
Jong Hee Park, and Soichiro Yamauchi syamauchi@princeton.edu
#################################### ## Alvarez et al. data #################################### library("pcse") set.seed(1999) data("agl") data = agl model = "within" index = c('country', 'year') effect = 'time' formula <- growth ~ lagg1 + opengdp + openex + openimp + leftc + central + inter ######################### ## inspection of residuals ######################### pdata <- pdata.frame(data, index) pm <- plm(formula, data = pdata, model = model, effect = effect) # ## plot of panel residuals 1 coplot(pm$residuals ~ pdata[,index[2]]|pdata[,index[1]], data=pdata, ## number=length(unique(pdata[,index[1]])), overlap=.1, col="brown", type="l", panel = panel.smooth, xlab="panel residuals by group and time") ## plot of panel residuals 2 coplot(pm$residuals ~ pdata[,index[2]]|pdata[,index[1]], type="b", data=pdata) ######################### ## 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 <- BridgeFixedPanel(formula=formula, data = data, model = model, index = index, effect = effect, mcmc=mcmc, verbose=verbose, Waic = TRUE, n.break = 0) agl.cp1 <- BridgeFixedPanel(formula=formula, data = data, model = model, index = index, effect = effect, mcmc=mcmc, verbose=verbose, Waic = TRUE, n.break = 1) agl.cp2 <- BridgeFixedPanel(formula=formula, data = data, model = model, index = index, effect = effect, 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"))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.