Learn R Programming

BAS (version 1.2.2)

bayesglm.fit: Fitting Generalized Linear Models and Bayesian marginal likelihood evaluation

Description

A version of glm.fit rewritten in C; also returns marginal likelihoods for Baysesian model comparison

Usage

bayesglm.fit(x, y, weights = rep(1, nobs), start = NULL, etastart = NULL, mustart = NULL, offset = rep(0, nobs), family = binomial(), coefprior = bic.prior(nobs), control = glm.control(), intercept = TRUE)

Arguments

x
design matrix
y
response
weights
optional vector of weights to be used in the fitting process. Should be NULL or a numeric vector.
start
starting value for coefficients in the linear predictor
etastart
starting values for the linear predictor
mustart
starting values for the vectors of means
offset
a priori known component to be included in the linear predictor
family
a description of the error distribution and link function for exponential family; currently only binomial() and poisson() with canonical links are implemented.
coefprior
function specifying prior distribution on coefficients with optionlal hyperparamters leading to marginal likelihood calculations; options include bic.prior(), aic.prior(), and ic.prior()
control
a list of parameters that control convergence in the fitting process. See the documentation for glm.control()
intercept
should an intercept be included in the null model?

Value

coefficients
MLEs
se
Standard errors of coefficients based on the sqrt of the diagonal of the inverse information matrix
mu
fitted mean
rank
numeric rank of the fitted linear model
deviance
minus twice the log likelihood evaluated at the MLEs
g
value of g in g-priors
shrinkage
shrinkage factor for coefficients in linear predictor
RegSS
quadratic form beta'I(beta)beta used in shrinkage
logmarglik
the log marginal or integrated log likelihood (up to a constant)

Details

C version of glm-fit. For different prior choices returns, marginal likelihood of model using a Laplace approximation.

References

glm

See Also

bic.prior

Examples

Run this code
require(MASS)
library(MASS)
Pima.tr
Y = as.numeric(Pima.tr$type) - 1
X = cbind(1, as.matrix(Pima.tr[,1:7]))
out = bayesglm.fit(X, Y, family=binomial(),coefprior=bic.prior(n=length(Y)))
out$coef
out$se
# using built in function
glm(type ~ ., family=binomial(), data=Pima.tr)

Run the code above in your browser using DataLab