Learn R Programming

BayesLogit (version 0.6.1)

logit: Default Bayesian Logistic Regression

Description

Run a Bayesian logistic regression.

Usage

logit(y, X, n=rep(1,length(y)),
      m0=rep(0, ncol(X)), P0=matrix(0, nrow=ncol(X), ncol=ncol(X)),
      samp=1000, burn=500)

Arguments

y

An N dimensional vector; \(y_i\) is the average response at \(x_i\).

X

An N x P dimensional design matrix; \(x_i\) is the ith row.

n

An N dimensional vector; n_i is the number of observations at each \(x_i\).

m0

A P dimensional prior mean.

P0

A PxP dimensional prior precision.

samp

The number of MCMC iterations saved.

burn

The number of MCMC iterations discarded.

Value

logit returns a list.

beta

A samp x P array; the posterior sample of the regression coefficients.

w

A samp x N' array; the posterior sample of the latent variable. WARNING: N' may be less than N if data is combined.

y

The response matrix--different than input if data is combined.

X

The design matrix--different than input if data is combined.

n

The number of samples at each observation--different than input if data is combined.

Details

Logistic regression is a classification mechanism. Given the binary data \(\{y_i\}\) and the p-dimensional predictor variables \(\{x_i\}\), one wants to forecast whether a future data point y* observed at the predictor x* will be zero or one. Logistic regression stipulates that the statistical model for observing a success=1 or failure=0 is governed by

$$ P(y^* = 1 | x^*, \beta) = (1 + \exp(-x^* \beta))^{-1}. $$

Instead of representing data as a collection of binary outcomes, one may record the average response \(y_i\) at each unique \(x_i\) given a total number of \(n_i\) observations at \(x_i\). We follow this method of encoding data.

References

Nicholas G. Polson, James G. Scott, and Jesse Windle. Bayesian inference for logistic models using Polya-Gamma latent variables. http://arxiv.org/abs/1205.0310

Nicholas Poslon and James G. Scott. Default Bayesian analysis for multi-way tables: a data-augmentation approach. http://arxiv.org/pdf/1109.4180

See Also

rpg, logit.EM, mlogit

Examples

Run this code
# NOT RUN {
## From UCI Machine Learning Repository.
data(spambase);

## A subset of the data.
sbase = spambase[seq(1,nrow(spambase),10),];

X = model.matrix(is.spam ~ word.freq.free + word.freq.1999, data=sbase);
y = sbase$is.spam;

## Run logistic regression.
output = logit(y, X, samp=1000, burn=100);

# }

Run the code above in your browser using DataLab