ts.nnormal: Apply the normal-based Bayesian two-stage causal model with...

Description Usage Arguments Details Value Examples

View source: R/ts.nnormal.R

Description

The ts.nnormal function applies the normal-based Bayesian two-stage causal model to the continuous treatment data. The model best suits the normally-distributed outcome data that are complete or ignorably missing (i.e., missing completely at random or missing at random).

Usage

1
2
3
4
5
6
ts.nnormal(formula, data, advanced = FALSE, adv.model, b0 = 1,
  B0 = 1e-06, g0 = 0, G0 = 1e-06, u0 = 0.001, U0 = 0.001,
  e0 = 0.001, E0 = 0.001, beta.start = NULL, gamma.start = NULL,
  u.start = NULL, e.start = NULL, n.chains = 1,
  n.burnin = floor(n.iter/2), n.iter = 10000, n.thin = 1, DIC,
  debug = FALSE, codaPkg = FALSE)

Arguments

b0

The mean hyperparameter of the normal distribution (prior distribution) for the first-stage causal model coefficients, i.e., coefficients for the instrumental variables. This can either be a numerical value or a vector with dimensions equal to the number of coefficients for the instrumental variables. If this takes a numerical value, then that values will serve as the mean hyperparameter for all of the coefficients for the instrumental variables. Default value of 0 is equivalent to a noninformative prior for the normal distributions. Used when advanced=FALSE.

B0

The precision hyperparameter of the normal distribution (prior distribution) for the first stage causal model coefficients. This can either be a numerical value or a vector with dimensions equal to the number of coefficients for the instrumental variables. If this takes a numerical value, then that values will serve as the precision hyperparameter for all of the coefficients for the instrumental variables. Default value of 10E+6 is equivalent to a noninformative prior for the normal distributions. Used when advanced=FALSE.

g0

The mean hyperparameter of the normal distribution (prior distribution) for the second-stage causal model coefficients, i.e., coefficients for the treatment variable and other regression covariates). This can either be a numerical value if there is only one treatment variable in the model, or a if there is a treatment variable and multiple regression covariates, with dimensions equal to the total number of coefficients for the treatment variable and covariates. Default value of 0 is equivalent to a noninformative prior for the normal distributions. Used when advanced=FALSE.

G0

The precision hyperparameter of the normal distribution (prior distribution) for the second-stage causal model coefficients. This can either be a numerical value if there is only one treatment variable in the model, or a vector if there is a treatment variable and multiple regression covariates, with dimensions equal to the total number of coefficients for the treatment variable and covariates. Default value of 10E+6 is equivalent to a noninformative prior for the normal distributions. Used when advanced=FALSE.

u0

The location hyperparameter of the inverse Gamma distribution (prior for the variance of the normal distribution on the model residuals at the first stage). Default of 0.001 is equivalent to the noninformative prior for the inverse Gamma distribution.

U0

The shape hyperparameter of the inverse Gamma distribution (prior for the variance of the normal distribution on the model residuals at the first stage). Default of 0.001 is equivalent to the noninformative prior for the inverse Gamma distribution.

e0

The location hyperparameter of the inverse Gamma distribution (prior for the variance of the normal distribution on the model residuals at the second stage). Default of 0.001 is equivalent to the noninformative prior for the inverse Gamma distribution.

E0

The shape hyperparameter of the inverse Gamma distribution (prior for the the variance of the normal distribution on the model residuals at the second stage). Default of 0.001 is equivalent to the noninformative prior for the inverse Gamma distribution.

beta.start

The starting values for the first-stage causal model coefficients, i.e., coefficients for the instrumental variables. This can either be a numerical value or a column vector with dimensions equal to the number of first-stage coefficients. The default value of NA will use the OLS estimate of first-stage coefficients as the starting value. If this is a numerical value, that value will serve as the starting value mean for all the first-stage beta coefficients.

gamma.start

The starting values for the second-stage causal model coefficients, i.e., coefficients for the treatment variable and the model covariates. This can either be a numerical value or a column vector with dimensions equal to the number of second-stage coefficients. The default value of NA will use the OLS estimate of second-stage coefficients as the starting value. If this is a numerical value, that value will serve as the starting value mean for all the second-stage gamma coefficients.

u.start

The starting value for the precision hyperparameter of the inverse gamma distribution (prior for the variance of the normal distribution of the first-stage residual term). The default value of NA will use the inverse of the residual variance from the OLS estimate of the first-stage model.

e.start

The starting value for the precision hyperparameter of the inverse gamma distribution (prior for the variance of the normal distribution of the second-stage residual term). The default value of NA will use the inverse of the residual variance from the OLS estimate of the second-stage model.

n.chains

Number of Markov chains. The default is 1.

n.burnin

Length of burn in, i.e., number of iterations to discard at the beginning. Default is n.iter/2, that is, discarding the first half of the simulations.

n.iter

The number of total iterations per chain (including burnin). The default is 10000.

n.thin

Thinning rate. Must be a positive integer. The default is 1.

DIC

Logical; if TRUE (default), compute deviance, pD, and DIC. The rule pD=Dbar-Dhat is used.

codaPkg

Logical; if FALSE (default), an object is returned; if TRUE, file names of the output are returned.

Details

  1. Bayesian two-stage causal models are specified symbolically. A typical model has the form reponse ~ terms|instrumental_variables, where response is the (numeric) response vector and terms is a series of terms which specifies a linear predictor (i.e., the treatment variable and the covariates) for the response. The first specification in the term is always the treatment variable and the remaining specifications are always the covariates for the response.

  2. DIC is computed as mean(deviance)+pD.

  3. Prior distributions used in ALMOND.

    • Causal model coefficients at both stages: normal distributions.

    • Causal model residuals at both stages: normal distributions.

Value

If codaPkg=FALSE(default), returns an object containing summary statistics of the saved parameters, including

s1.intercept

Estimate of the intercept from the first stage.

s1.slopeP

Estimate of the pth slope from the first stage.

s2.intercept

Estimate of the intercept from the second stage.

s2.slopeP

Estimate of the pth slope from the second stage (the first slope is always the LATE).

var.e.s1

Estimate of the residual variance at the first stage.

var.e.s2

Estimate of the residual variance at the second stage.

DIC

Deviance Information Criterion.

If codaPkg=TRUE, the returned value is the path for the output file containing the Markov chain Monte Carlo output.

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
# Run the model
model1 <- ts.nnormal(readingIRT~relAge+gender+race+numsib+parentedu+ses|PredEnt,data=subECLSK)

# Run the model with the self-defined advanced feature
my.normal.model<- function(){
for (i in 1:N){
mu[i] <- beta0 + beta1*z[i]
x[i] ~ dnorm(mu[i], pre.u1)
muY[i] <- gamma0 + gamma1*mu[i]
y[i] ~ dnorm(muY[i], pre.u2)
}

beta0 ~ dnorm(0,1)
beta1 ~ dnorm(1, 1)
gamma0 ~ dnorm(0, 1)
gamma1 ~ dnorm(.5, 1)
pre.u1 ~ dgamma(.001, .001)
pre.u2 ~ dgamma(.001, .001)

s1.intercept <- beta0
s1.slope1 <- beta1
s2.intercept <- gamma0
s2.slope1 <- gamma1
var.e.s1 <- 1/pre.u1
var.e.s2 <- 1/pre.u2
}

model2 <- ts.nnormal(readingIRT~relAge+gender+race+numsib+parentedu+ses|PredEnt,data=subECLSK,
advanced=TRUE,adv.model=my.normal.model)

# Extract the model DIC
model1$DIC

# Extract the MCMC output
ts.nnormal(readingIRT~relAge+gender+race+numsib+parentedu+ses|PredEnt,data=subECLSK,codaPkg=TRUE)

dingjshi/ALMOND documentation built on June 18, 2020, 4:32 p.m.