tglm.fit: Fit a Binary Regression under Independent Student-t Priors

Description Usage Arguments Details Value Author(s) References Examples

View source: R/tglm.fit.R

Description

Use Gibbs sampler with Polya-Gamma data augmentation to fit logistic and probit regression under independent Student-t priors (including Cauchy priors and normal priors as special cases).

Usage

1
2
3
4
5
tglm.fit(y, X, iter = 1e+05, thin = max(1, round(iter/2000)), 
         burnin = 0.5, method = "logistic", df = 1, slope.scale = 2.5, 
         intercept.scale = 10, save.latent = FALSE, 
         center.binary = TRUE, scale.continuous = TRUE, 
         beta.original = TRUE, track.time = TRUE, show.summary = TRUE)

Arguments

y

a numerical vector of length n. Binary responses.

X

an n by p matrix. Design matrix, not including the intercept.

iter

total number of iterations of MCMC.

thin

thinning; save one iteration in every thin number of iterations.

burnin

ratio between number of burnin iterations and total number of iterations.

method

"logistic" for logistic regression, or "probit" for probit regression.

df

degree freedom of the independent Student-t priors on both intercept and slopes. If Inf, use independent normal priors.

slope.scale

a scalar or a vector of length p. The scale (or standard deviation) parameter of the Student-t (or normal) priors on slopes.

intercept.scale

the scale (or sd) parameter of the Student-t (or normal) prior on the intercept.

save.latent

logical, indicating whether to save the MCMC samples for the latent variable z. Since latent variable is of length n, it takes a lot of space when n is large.

center.binary

logical, indicating whether to center binary predictors.

scale.continuous

logical, indicating whether to center and rescale the non-binary predictors.

beta.original

logical, indicating whether to post-process the posterior samples of beta to the orginal scale. This is only meaningful if predictors are centered/rescaled in the pre-processing step.

track.time

logical, indicating whether to show process time.

show.summary

logical, indicating whether to show summary of posterior inferences.

Details

See references.

Value

Beta

a (iter / thin + 1) by (p + 1) matrix. MCMC samples of beta (the first dimemsion is the intercept).

Gamma

a (iter / thin + 1) * (p + 1) matrix. MCMC samples of gamma.

Inference

a (p + 1) by 4 matrix. Sample posterior mean, stanard deviation, and 95% HDP interval for the intercept and coefficients.

Z

a (iter / thin + 1) * n matrix. MCMC samples of z. Only returned when save.latent == TRUE.

Author(s)

Yingbo Li

Maintainer: Yingbo Li <ybli@clemson.edu>

References

James H. Albert and Siddhartha Chib. (1993) "Bayesian Analysis of Binary and Polychotomous Response Data." Journal of the American statistical Association, 88(422), 669-679.

Nicholas G. Polson, James G. Scott, and Jesse Windle. (2013) "Bayesian Inference for Logistic Models Using Polya-Gamma Latent Variables." Journal of the American statistical Association, 108(504), 1339-1349.

Joyee Ghosh, Yingbo Li, and Robin Mitra. "On the Use of Cauchy Prior Distributions for Bayesian Logistic Regression." Working paper.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
## create a dataset for logistic regression
n = 200; p = 2; beta0 = c(0.5, 1, 2);
X = matrix(rnorm(n * p), ncol = p);
p = 1 / (1 + exp(- beta0[1] - X %*% beta0[-1]));
y = rbinom(n, 1, prob = p);

## Cauchy priors
results.cauchy = tglm.fit(y, X, iter = 1e3);

## Not run: ##
#### Student-t priors with df = 7
## results.t7 = tglm.fit(y, X, iter = 1e3, df = 7);
#### Normal priors 
##results.normal = tglm.fit(y, X, iter = 1e3, df = Inf);
#### Probit regression
##results.probit = tglm.fit(y, X, iter = 1e3, method = 'probit');
## End(Not run)

Example output

10% completed...
20% completed...
30% completed...
40% completed...
50% completed...
60% completed...
70% completed...
80% completed...
90% completed...
100% completed.

Time used (in second): 
   user  system elapsed 
  0.598   0.000   0.643 

Posterior inference: 
             Est    Std 95HPDlower 95HPDupper
intercept 0.5876 0.1959     0.2141     0.9514
X1        1.1876 0.2592     0.7234     1.7118
X2        1.8316 0.3208     1.2443     2.4582

tglm documentation built on May 29, 2017, 4:10 p.m.