| BRegression {Baldur} | R Documentation |
BRegression produces iid draws from the posterior density of a Bayesian Regression model with a multivariate normal prior for the regression coefficients and a separate independent Gamma prior for the data precision.
BRegression(y,X,mu,P,V0,n0,draws,Prec=FALSE,A=FALSE,maxiter=10000)
y |
n*1 Matrix with observed data values. |
X |
n*k Matrix with the values for the independent variables. |
mu |
k*1 Prior mean vector. |
P |
k*k Prior variance-covariance matrix (must be Positive Definite). If Prec=TRUE, this is instead treated as the prior precision matrix (inverse variance-covariance matrix). |
V0 |
Prior point estimate for data variance. |
n0 |
Number of prior "observations" for data variance. |
draws |
Numeric variable containing number of desired draws from the posterior density. Non-integer values are rounded to the nearest integer. |
Prec |
Optional logical argument with default Prec=FALSE. If argument is set to TRUE, the matrix P is treated as a prior precision matrix. |
A |
Optional logical argument with default A=FALSE. If argument is set to TRUE, the function returns not only the simulated draws from the posterior density but also a vector with information related to the acceptance rate for the underlying accept/reject procedure (see below). |
maxiter |
Maximum number of candidates to be used by accept/reject procedure before terminating. |
Makes use of the likelihood subgradient density accept/reject procedure of Nygren and Nygren (2006) in order to generate iid samples from the posterior density of a Bayesian Logit model with a multivariate normal prior.
author{ Kjell Nygren knygren@us.imshealth.com}
If A=FALSE, a matrix beta. If A=TRUE, a list containing the matrix beta and a matrix Accept.:
beta |
draws*k matrix with the iid draws for the model parameters. |
Accept |
draws*1 matrix with the number of candidates for each draw that were required before acceptance in the accept/reject procedure. |
Kjell Nygren knygren@us.imshealth.com
# Bayesian Regression using Pearson's Height Data for Father-Son pairs data(Height, package = "Baldur") m<-1078 nvars<-2 y<-matrix(Height$Son,nrow=m,ncol=1) X<-matrix(0,nrow=m,ncol=nvars) mu<-matrix(0,nrow=nvars,ncol=1) X[,1]<-1 X[,2]<-Height$Father[1:m] P<-100*diag(nvars) V0<-10 n0<-3 draws<-1000 set.seed(666) system.time(out<-BRegression(y, X, mu, P, V0, n0, draws)) mean(out$beta[,1]) mean(out$beta[,2]) mean(out$Var) sqrt(var(out$beta[,1])) sqrt(var(out$beta[,2])) sqrt(var(out$Var))