Description Usage Arguments Value Note Author(s) Examples
Convenient and efficient functions for performing 2-level HB regressions analysis for multi-group data. The lowest level may belong to the GLM family while the prior level, which effects pooling, allows for linear regression on lower level covariates. Constraints on all or part of the parameter set maybe specified with ease. A rich set of methods is included to visualize and analyze results.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | hbglm(formula, data, formula.fixed = NULL,
family = "gaussian",
sampler.control = hbglm.sampler.control(),
model.control = hbglm.model.control(),
ncores = 1, print.level = 0, ...)
hbglm.sampler.control(num.samples = -1, samp.factor = 50,
sampler = c("slice"))
hbglm.model.control(constraints = NULL,
initializer = c("user", "regression"), user.init.val = NULL)
## S3 method for class 'hbglm'
print(x, digits = max(3, getOption("digits") -2),
width = getOption("width"), nburnin = 0, ...)
## S3 method for class 'hbglm'
predict(object, newdata = NULL, grpID.col = NULL,
type = c("link", "response", "ppp.mean", "ppp.dist"),
nburnin = 0, times = 0, print.level = 0, ...)
## S3 method for class 'hbglm'
coef(object, nburnin = 0, ...)
## S3 method for class 'hbglm'
summary(object, nburnin = 0, ...)
## S3 method for class 'hbglm'
print.summary(x, digits = max(3, getOption("digits") -2),
width = getOption("width"), ...)
|
formula |
formula object or string specifying the model to be estimated (see Note). |
data |
A data.frame object with data organized in the 'long' format or as a list of lists (see Note). |
formula.fixed |
formula specifying the fixed effects included in the model. |
family |
Name of a GLM family member. Currently allowed "gaussian", "binomial", "poisson" with standard link functions. |
sampler.control |
List to control MCMC sampling. |
model.control |
List to specify initial values, constraints. |
ncores |
Number of cores to run on. Currently fixed at 1. |
print.level |
Positive integer to print stuff while running. |
num.samples |
Number of MCMC samples to draw. Default '-1' will cause internal default values to kick-in. |
samp.factor |
Used in setting internal default for number of MCMC samples to draw. Must be a positive integer |
sampler |
Name of MCMC sampler to use. Currently fixed at the slice sampler. |
constraints |
User specified constraints. |
initializer |
How to obtain initial values. |
user.init.val |
User specified initial values. |
x, object |
A hbglm class object. |
width |
Printing control options. |
nburnin |
Number of burn-in samples. These samples, starting fromt the initial, are discarded from print, summary and predict. |
digits |
Printing control options. |
newdata |
Same format as data argument. Used in predction. |
grpID.col |
Name of column in data which has group information for each observation. |
type |
Used in predict. 'link' and 'response' are non-Bayesian predictions and return the avg response on the linear predictor and the response scale, respectively. They are computed by using model coefficients obtained by averaging MCMC samples. 'ppp.mean' return the distribution of means of the response posterior predcitive probability (PPP) distribution. 'ppp.dist' returns samples drawn from the full response PPP distribution. |
times |
Used in predict when type = 'ppp.dist' to specify number of samples desired from the response PPP distribution. When 0, a default internal value is used. |
... |
Currently unused. |
An object of class hbglm, with elements:
formula |
the model formula object |
formula.fixed |
the fixed effects formula object |
nsamples |
the number of samples drawn |
model.control |
list of model control args |
sampler.control |
list of sampler control args |
grpID.col |
Data column with grp ID information |
call |
the hbglm function call that user made, |
model |
List with number of parameters and model matrices |
family |
List with functions such as loglikelihood and inverse link for the GLM family. |
samples |
A list with the MCMC samples drawn; organized by coeff type. |
1. The data must be in the 'long' or the 'list' format. In 'list' format there must bebe 2 keys 'lower' and 'upper' specifying two data.frames for the lower and upper level models respectively. Lower level contains data related to the fixed and random effects, while upper level contains data about the groups. In 'long' the 'upper' and 'lower' level data must be consolidated in a single data.frame (the upper level data will have to suitably replicated).
2. The 'formula' argument should be specified in the format: responseVar ~ choice specific variables with generic coefficients | individual specific variables | choice specific variables with choice specific coefficients. These are the 3 available variable types.
3. Random effects are mandatory in the formula.
Asad Hasan, Alireza S. Mahani
1 2 3 4 5 6 7 8 9 10 11 | library(HBglm)
data("linear_list", package = "HBglm")
fm <- formula(y ~ x1 + x2 + x3 - 1 | z1 + z2 + z3 - 1 | grpID)
fm.fixed <- formula(y ~ f1 + f2)
samp.control = hbglm.sampler.control(num.samples = 20)
## Not run:
fit <- hbglm(fm, linear_list, formula.fixed = fm.fixed, family="gaussian",
sampler.control = samp.control, print.level=0)
print(fit)
## End(Not run)
|
2-level Hierarchical Bayesian Regression model estimation ..
Mean coeffcient values are:
beta (random eff)
x1 x2 x3
1 -0.0850907 -2.2585852 -2.246644235
2 -2.3549977 0.4231252 0.957216184
3 -0.1826344 -0.1170798 -0.009816962
4 0.9008816 2.3149467 0.887721489
5 0.4262071 -1.5951313 -3.706811638
alpha (fixed eff)
(Intercept) f1 f2
0.2638125 0.1414105 -0.4017317
tau
1 2 3 4 5
1.077133 0.974024 1.216256 1.185883 1.974440
theta (prior coeff)
x1 x2 x3
z1 -2.1535432 1.2341807 1.336635
z2 1.5056469 1.8298105 2.262980
z3 -0.8605801 -0.4958652 -1.918863
Sigma (prior Covariance)
x1 x2 x3
x1 1.3069760 0.4500396 -0.1537707
x2 0.4500396 1.5510669 0.0930031
x3 -0.1537707 0.0930031 0.9391468
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.