bcgam {bcgam} | R Documentation |
Fitting Bayesian Constrained Generalised Additive Models
Description
bcgam
is used to fit generalised partial linear regression models using a Bayesian
approach, where shape and smoothness constraints are imposed on nonparametrically modelled predictors
through shape-restricted splines, and no constraints are imposed on optional parametrically modelled covariates.
Usage
bcgam(formula, family = gaussian(), data = NULL, nloop = 10000,
burnin = trunc(nloop/10))
Arguments
formula |
an object of class
|
family |
a description of the error distribution and link function to be used in the model. This accepts
only the following families: |
data |
an optional data frame, list or environment containing the variables in the model. The default is |
nloop |
length of the MCMC. The default is |
burnin |
a positive value, smaller than |
Details
We assume the additive model for each systematic component element given by
where is a vector
of variables to be modelled parametrically and
is a parameter vector. The functions
of the continuous predictors
are assumed to be smooth, and shape restrictions
such as monotonicity and/or convexity might be assumed. Generally, the vector
is approximated by
where for all
. The
's represent
the basis vectors used to approximate the
functions. The
consists of the
one vector and the vectors of the observed values of covariates to be modelled parametrically. In addition,
when
is assumed to be convex, the
vector is included as one of the
.
A Bayesian approach is considered for estimation and inference of the model above. As the
coefficients are constrained to be non-negative, then a gamma prior with hyperparameters
(shape)
and
(scale) is assumed for each
. The values
and
are
chosen in a way that a large variance can be combined with a small mean, so that it is close to a
non-informative gamma prior. Further, a normal prior distribution with mean zero and large variance
is considered for the
coefficients.
bcgam
makes use of the system "nimble" to set the Bayesian (hierarchical) model and compute the MCMC. Hence,
"nimble" has to be loaded in R
to be able to use bcgam
. Information about how to download
and install "nimble" can be found at https://r-nimble.org.
Value
bcgam
returns an object of class "bcgam".
The generic routines summary
and print
are used to obtain and print a summary
of the results. Further, 2D and 3D plots can be created using plot
and persp
, respectively.
An object of class "bcgam" is a list containing at least the following components:
coefs |
a vector of posterior means of the |
sd.coefs |
a vector of posterior standard errors of the |
etahat |
a vector of posterior means of the systematic component |
muhat |
a vector of posterior means of |
alpha.sims |
a matrix of posterior samples (after burn-in) of the |
beta.sims |
a matrix of posterior samples (after burn-in) of the |
sigma.sims |
a matrix of posterior samples (after burn-in) of |
eta.sims |
a matrix of posterior samples (after burn-in) of the systematic component |
mu.sims |
a matrix of posterior samples (after burn-in) of |
delta |
a matrix that contains the basis functions |
zmat |
a matrix that contains the vectors |
knots |
a list of the knots. |
shapes |
a list of numbers that indicate the shape categories. |
sps |
a character vector of the space parameter used to create the knots. |
nloop |
the length of the MCMC. |
burnin |
the burn-in value. |
family |
the family parameter. |
y |
the response variable. |
Author(s)
Cristian Oliva-Aviles and Mary C. Meyer
References
Meyer, M. C. (2008) Inference using shape-restricted regression splines. Annals of Applied Statistics 2(3), 1013-1033.
Meyer, M. C., Hackstadt, A. J., and Hoeting J. A. (2011) Bayesian estimation and inference for generalised partial linear models using shape-restricted splines. Journal of Nonparametric Statistics 23(4), 867-884.
See Also
Examples
## Not run:
## Example 1 (gaussian)
data(duncan)
bcgam.fit <- bcgam(income~sm.incr(prestige, space="E")+sm.conv(education)+type, data=duncan)
print(bcgam.fit)
summary(bcgam.fit)
plot(bcgam.fit, prestige, col=4)
persp(bcgam.fit, prestige, education, level=0.90)
## Example 2 (poisson)
set.seed(2018)
n<-50
x1<-sqrt(1:n)
z<-as.factor(rbinom(n, 1, 0.5))
log.eta<-x1/7+0.2*as.numeric(z)+rnorm(50, sd=0.6)
eta<-exp(log.eta)
y<-rpois(n,eta)
bcgam.fit <- bcgam(y~sm.conv(x1)+z, family="poisson")
summary(bcgam.fit)
predict(bcgam.fit, newdata=data.frame(x1=0.2, z="0"), interval="credible")
plot(bcgam.fit, x1, col=3, col.inter=4)
## End(Not run)