Description Usage Arguments Details Value References See Also Examples
View source: R/rNormal_Gamma_reg.R
rNormal_Gamma_reg
is used to generate iid samples from Bayesian linear models with a normal-gamma prior.
The model is specified by providing a data vector, a design matrix, and 4 prior constants.
1 2 3 4 5 6 7 8 9 |
n |
number of draws to generate. If |
y |
a vector of observations of length |
x |
a design matrix of dimension |
prior_list |
a list with the prior parameters (mu, Sigma, shape and rate) for the prior distribution. |
offset |
this can be used to specify an a priori known component to be included in the linear predictor during fitting. This should be |
weights |
an optional vector of ‘prior weights’ to be used in the fitting process. Should be NULL or a numeric vector. |
family |
a description of the error distribution and link
function to be used in the model. For |
The rNormal_Gamma_reg
function produces iid samples for Bayesian generalized linear
models from the gaussian family (identity link) with a conjugate multivariate normal-gamma prior
for the regression coefficients and the dispersion (variance).
See Raiffa and Schlaifer (1961) for details on conjugate priors.
Core required inputs for the function include the data vector, the design matrix and a prior specification. The function returns the simulated Bayesian coefficients and some associated outputs. The iid samples from the posterior density is genererated using standard simulation procedures for multivariate normal and gamma distributions.
rNormal_Gamma_reg
returns a object of class "rglmb"
. The function summary
(i.e., summary.rglmb
) can be used to obtain or print a summary of the results.
The generic accessor functions coefficients
, fitted.values
,
residuals
, and extractAIC
can be used to extract
various useful features of the value returned by rNormal_Gamma_reg
.
An object of class "rglmb"
is a list containing at least the following components:
coefficients |
a |
PostMode |
a vector of |
Prior |
A list with two components. The first being the prior mean vector and the second the prior precision matrix |
iters |
an |
famfunc |
an object of class |
Envelope |
an object of class |
dispersion |
an |
loglike |
a |
Dobson, A. J. (1990) An Introduction to Generalized Linear Models. London: Chapman and Hall.
Hastie, T. J. and Pregibon, D. (1992) Generalized linear models. Chapter 6 of Statistical Models in S eds J. M. Chambers and T. J. Hastie, Wadsworth & Brooks/Cole. McCullagh P. and Nelder, J. A. (1989) Generalized Linear Models. London: Chapman and Hall.
Nygren, K.N. and Nygren, L.M (2006) Likelihood Subgradient Densities. Journal of the American Statistical Association. vol.101, no.475, pp 1144-1156.
Raiffa, Howard and Schlaifer, R (1961) Applied Statistical Decision Theory. Boston: Clinton Press, Inc.
Venables, W. N. and Ripley, B. D. (2002) Modern Applied Statistics with S. New York: Springer.
pfamily
for the list of available pfamilies and how
they are specified. Each pfamily has a specific assigned simulation function. This
particular simulation function is the simulation function for the dNormal_Gamma
pfamily.
rglmb
and glmb
for functions that depend on
simulation functions.
Other family simulation functions:
rGamma_reg()
,
rNormal_reg()
,
rindependent_norm_gamma_reg()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | ## Annette Dobson (1990) "An Introduction to Generalized Linear Models".
## Page 9: Plant Weight Data.
ctl <- c(4.17,5.58,5.18,6.11,4.50,4.61,5.17,4.53,5.33,5.14)
trt <- c(4.81,4.17,4.41,3.59,5.87,3.83,6.03,4.89,4.32,4.69)
group <- gl(2, 10, 20, labels = c("Ctl","Trt"))
weight <- c(ctl, trt)
ps=Prior_Setup(weight ~ group)
mu=ps$mu
V=ps$Sigma
mu[1,1]=mean(weight)
Prior_Check(weight ~ group,family =gaussian(),
pfamily=dNormal(mu=mu,Sigma=V))
## Will move this step inside the Prior_Check
lm.D9 <- lm(weight ~ group,x=TRUE,y=TRUE)
disp_ML=sigma(lm.D9)^2
n_prior=2
shape=n_prior/2
rate= disp_ML*shape
lmb.D9=lmb(weight ~ group,dNormal_Gamma(mu,V/disp_ML,shape=shape,rate=rate))
summary(lmb.D9)
n<-10000
y<-lmb.D9$y
x<-as.matrix(lmb.D9$x)
prior_list=list(mu=mu,Sigma=V/disp_ML,shape=shape,rate=rate)
ngamma.D9=rNormal_Gamma_reg(n=1000,y=y,x=x,
prior_list=prior_list)
summary(ngamma.D9$coefficients)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.