glib {BMA}  R Documentation 
Model uncertainty in generalized linear models using Bayes factors
Description
Function to evaluate Bayes factors and account for model uncertainty in generalized linear models.
Usage
glib(x, ...)
## S3 method for class 'matrix'
glib(x, y, n = rep(1, nrow(x)),
error = "poisson", link = "log", scale = 1,
models = NULL, phi = c(1, 1.65, 5), psi = 1,
nu = 0, pmw = rep(1, nrow(models)), glimest = TRUE,
glimvar = FALSE, output.priorvar = FALSE,
post.bymodel = TRUE, output.postvar = FALSE,
priormean = NULL, priorvar = NULL,
nbest = 150, call = NULL, ...)
## S3 method for class 'data.frame'
glib(x, y, n = rep(1, nrow(x)),
error = "poisson", link = "log", scale = 1,
models = NULL, phi = c(1, 1.65, 5),
psi = 1, nu = 0, pmw = rep(1, nrow(models)),
glimest = TRUE, glimvar = FALSE, output.priorvar = FALSE,
post.bymodel = TRUE, output.postvar = FALSE,
priormean = NULL, priorvar = NULL,
nbest = 150, call = NULL, ...)
## S3 method for class 'bic.glm'
glib(x, scale = 1, phi = 1, psi = 1, nu = 0,
glimest = TRUE, glimvar = FALSE, output.priorvar = FALSE,
post.bymodel = TRUE, output.postvar = FALSE,
priormean = NULL, priorvar = NULL, call = NULL, ...)
as.bic.glm(g, ...)
## S3 method for class 'glib'
as.bic.glm( g, index.phi=1, ...)
Arguments
x 
an 
g 
an object of type 
y 
a vector of values for the dependent variable 
n 
an optional vector of weights to be used. 
error 
a string indicating the error family to use. Currently "gaussian", "gamma", "inverse gaussian", "binomial" and "poisson" are implemented. 
link 
a string indicating the link to use. Currently "identity", "log", "logit", "probit", "sqrt", "inverse" and "loglog" are implemented. 
scale 
the scale factor for the model. May be either a numeric constant or a string specifying the estimation, either "deviance" or "pearson". The default value is 1 for "binomial" and "poisson" error structures, and "pearson" for the others. 
models 
an optional matrix representing the models to be averaged over.

phi 
a vector of phi values. Default: 
psi 
a scalar prior parameter. Default: 
nu 
a scalar prior parameter. Default: 0 
pmw 
a vector of prior model weights. These must be positive, but do not have to sum to one.
The prior model probabilities are given by 
glimest 
a logical value specifying whether to output estimates and standard errors for each model. 
glimvar 
a logical value specifying whether glim variance matrices are output for each model. 
output.priorvar 
a logical value specifying whether the prior variance is output for each model and value of phi combination. 
post.bymodel 
a logical value specifying whether to output the posterior mean and sd for each model and value of phi combination. 
output.postvar 
a logical value specifying whether to output the posterior variance matrix for each model and value of phi combination. 
priormean 
an optional vector of length p+1 containing a user specified prior mean on the variables (including the intercept), where p=number of independent variables. 
priorvar 
an optional matrix containing a user specified prior variance matrix, a (p+1) x (p+1) matrix. Default has the prior variance estimated as in Raftery(1996). 
nbest 
an integer giving the number of best models of each size to be returned by bic.glm if 
call 
the call to the function 
index.phi 
an index to the value of phi to use when converting a 
... 
unused 
Details
Function to evaluate Bayes factors and account for model
uncertainty in generalized linear models.
This also calculates posterior distributions from a set of reference
proper priors.
as.bic.glm
creates a 'bic.glm' object from a 'glib' object.
Value
glib
returns an object of type glib
, which is a list
containing the following items:
inputs 
a list echoing the inputs (x,y,n,error,link,models,phi,psi,nu) 
bf 
a list containing the model comparison results:

posterior 
a list containing the Bayesian model mixing results:

glim.est 
a list containing the GLIM estimates for the different models:

posterior.bymodel 
a list containing modelspecific posterior means and sds:

prior 
a list containing the prior distributions:

models 
an array containing the models used. 
glm.out 
an object of type 'bic.glm' containing the results of
any call to 
call 
the call to the function 
Note
The outputs controlled by glimvar, output.priorvar and output.postvar can take up a lot of space, which is why these control parameters are F by default.
Author(s)
Original Splus code developed by Adrian Raftery raftery@uw.edu and revised by Chris T. Volinsky. Translation to R by Ian S. Painter.
References
Raftery, A.E. (1988). Approximate Bayes factors for generalized linear models. Technical Report no. 121, Department of Statistics, University of Washington.
Raftery, Adrian E. (1995). Bayesian model selection in social research (with Discussion). Sociological Methodology 1995 (Peter V. Marsden, ed.), pp. 111196, Cambridge, Mass.: Blackwells.
Raftery, A.E. (1996). Approximate Bayes factors and accounting for model uncertainty in generalized linear models. Biometrika (83: 251266).
See Also
Examples
## Not run:
### Finney data
data(vaso)
x< vaso[,1:2]
y< vaso[,3]
n< rep(1,times=length(y))
finney.models< rbind(
c(1, 0),
c(0, 1),
c(1, 1))
finney.glib < glib (x,y,n, error="binomial", link="logit",
models=finney.models, glimvar=TRUE,
output.priorvar=TRUE, output.postvar=TRUE)
summary(finney.glib)
finney.bic.glm< as.bic.glm(finney.glib)
plot(finney.bic.glm,mfrow=c(2,1))
## End(Not run)
### Yates (teeth) data.
x< rbind(
c(0, 0, 0),
c(0, 1, 0),
c(1, 0, 0),
c(1, 1, 1))
y<c(4, 16, 1, 21)
n<c(1,1,1,1)
models< rbind(
c(1, 1, 0),
c(1, 1, 1))
glib.yates < glib ( x, y, n, models=models, glimvar=TRUE,
output.priorvar=TRUE, output.postvar=TRUE)
summary(glib.yates)
## Not run:
### logistic regression with no models specified
library("MASS")
data(birthwt)
y< birthwt$lo
x< data.frame(birthwt[,1])
x$race< as.factor(x$race)
x$ht< (x$ht>=1)+0
x< x[,9]
x$smoke < as.factor(x$smoke)
x$ptl< as.factor(x$ptl)
x$ht < as.factor(x$ht)
x$ui < as.factor(x$ui)
glib.birthwt< glib(x,y, error="binomial", link = "logit")
summary(glib.birthwt)
glm.birthwt< as.bic.glm(glib.birthwt)
imageplot.bma(glm.birthwt)
plot(glm.birthwt)
## End(Not run)