Title: | Bayesian Spectral Analysis Models using Gaussian Process Priors |
---|---|
Description: | Contains functions to perform Bayesian inference using a spectral analysis of Gaussian process priors. Gaussian processes are represented with a Fourier series based on cosine basis functions. Currently the package includes parametric linear models, partial linear additive models with/without shape restrictions, generalized linear additive models with/without shape restrictions, and density estimation model. To maximize computational efficiency, the actual Markov chain Monte Carlo sampling for each model is done using codes written in FORTRAN 90. This software has been developed using funding supported by Basic Science Research Program through the National Research Foundation of Korea (NRF) funded by the Ministry of Education (no. NRF-2016R1D1A1B03932178 and no. NRF-2017R1D1A3B03035235). |
Authors: | Seongil Jo [aut, cre], Taeryon Choi [aut], Beomjo Park [aut, cre], Peter J. Lenk [ctb] |
Maintainer: | Beomjo Park <[email protected]> |
License: | GPL (>= 2) |
Version: | 1.2.5 |
Built: | 2024-11-15 03:05:16 UTC |
Source: | https://github.com/cran/bsamGP |
This function fits a Bayesian quantile regression model.
blq(formula, data = NULL, p, mcmc = list(), prior = list(), marginal.likelihood = TRUE)
blq(formula, data = NULL, p, mcmc = list(), prior = list(), marginal.likelihood = TRUE)
formula |
an object of class “ |
data |
an optional data frame. |
p |
quantile of interest (default=0.5). |
mcmc |
a list giving the MCMC parameters.
The list includes the following integers (with default values in parentheses):
|
prior |
a list giving the prior information. The list includes the following parameters
(default values specify the non-informative prior):
|
marginal.likelihood |
a logical variable indicating whether the log marginal likelihood is calculated. The methods of Gelfand and Dey (1994) is used. |
This generic function fits a Bayesian quantile regression model.
Let and
be the response and the vector of parametric predictors, respectively.
Further, let
be the covariate related to the response, linearly.
The model is as follows.
where the error terms are a random sample from an asymmetric Laplace distribution,
,
which has the following probability density function:
where is the skew parameter,
is the scale parameter,
is
the location parameter, and
is the indication function.
The conjugate priors are assumed for and
:
An object of class blm
representing the Bayesian parametric linear model fit.
Generic functions such as print
and fitted
have methods to show the results of the fit.
The MCMC samples of the parameters in the model are stored in the list mcmc.draws
,
the posterior samples of the fitted values are stored in the list fit.draws
, and
the MCMC samples for the log marginal likelihood are saved in the list loglik.draws
.
The output list also includes the following objects:
post.est |
posterior estimates for all parameters in the model. |
lmarg |
log marginal likelihood using Gelfand-Dey method. |
rsquarey |
correlation between |
call |
the matched call. |
mcmctime |
running time of Markov chain from |
Gelfand, A. E. and Dey, K. K. (1994) Bayesian model choice: asymptotics and exact calculations. Journal of the Royal Statistical Society. Series B - Statistical Methodology, 56, 501-514.
Kozumi, H. and Kobayashi, G. (2011) Gibbs sampling methods for Bayesian quantile regression. Journal of Statistical Computation and Simulation, 81(11), 1565-1578.
##################### # Simulated example # ##################### # Simulate data set.seed(1) n <- 100 w <- runif(n) y <- 3 + 2*w + rald(n, scale = 0.8, p = 0.5) # Fit median regression fout <- blq(y ~ w, p = 0.5) # Summary print(fout); summary(fout) # fitted values fit <- fitted(fout) # Plots plot(fout)
##################### # Simulated example # ##################### # Simulate data set.seed(1) n <- 100 w <- runif(n) y <- 3 + 2*w + rald(n, scale = 0.8, p = 0.5) # Fit median regression fout <- blq(y ~ w, p = 0.5) # Summary print(fout); summary(fout) # fitted values fit <- fitted(fout) # Plots plot(fout)
This function fits a Bayesian linear regression model using scale invariant prior.
blr(formula, data = NULL, mcmc = list(), prior = list(), marginal.likelihood = TRUE)
blr(formula, data = NULL, mcmc = list(), prior = list(), marginal.likelihood = TRUE)
formula |
an object of class “ |
data |
an optional data frame. |
mcmc |
a list giving the MCMC parameters.
The list includes the following integers (with default values in parentheses):
|
prior |
a list giving the prior information. The list includes the following parameters
(default values specify the non-informative prior):
|
marginal.likelihood |
a logical variable indicating whether the log marginal likelihood is calculated. |
This generic function fits a Bayesian linear regression model using scale invariant prior.
Let and
be the response and the vector of parametric predictors, respectively.
The model for regression function is as follows.
where the error terms are a random sample from a normal distribution,
.
The conjugate priors are assumed for and
:
An object of class blm
representing the Bayesian spectral analysis model fit.
Generic functions such as print
and fitted
have methods to show the results of the fit.
The MCMC samples of the parameters in the model are stored in the list mcmc.draws
and
the posterior samples of the fitted values are stored in the list fit.draws
.
The output list also includes the following objects:
post.est |
posterior estimates for all parameters in the model. |
lmarg |
log marginal likelihood. |
rsquarey |
correlation between |
call |
the matched call. |
mcmctime |
running time of Markov chain from |
##################### # Simulated example # ##################### # Simulate data set.seed(1) n <- 100 w <- runif(n) y <- 3 + 2*w + rnorm(n, sd = 0.8) # Fit the model with default priors and mcmc parameters fout <- blr(y ~ w) # Summary print(fout); summary(fout) # Fitted values fit <- fitted(fout) # Plots plot(fout)
##################### # Simulated example # ##################### # Simulate data set.seed(1) n <- 100 w <- runif(n) y <- 3 + 2*w + rnorm(n, sd = 0.8) # Fit the model with default priors and mcmc parameters fout <- blr(y ~ w) # Summary print(fout); summary(fout) # Fitted values fit <- fitted(fout) # Plots plot(fout)
This function fits a semiparametric model, which consists of parametric and nonparametric components, for estimating density using a logistic Gaussian process.
bsad(x, xmin, xmax, nint, MaxNCos, mcmc = list(), prior = list(), smoother = c('geometric', 'algebraic'), parametric = c('none', 'normal', 'gamma', 'laplace'), marginal.likelihood = TRUE, verbose = FALSE)
bsad(x, xmin, xmax, nint, MaxNCos, mcmc = list(), prior = list(), smoother = c('geometric', 'algebraic'), parametric = c('none', 'normal', 'gamma', 'laplace'), marginal.likelihood = TRUE, verbose = FALSE)
x |
a vector giving the data from which the density estimate is to be computed. |
xmin |
minimum value of x. |
xmax |
maximum value of x. |
nint |
number of grid points for plots (need to be odd). The default is 201. |
MaxNCos |
maximum number of Fourier coefficients. |
mcmc |
a list giving the MCMC parameters.
The list includes the following integers (with default values in parentheses):
|
prior |
a list giving the prior information. The list includes the following parameters
(default values specify the non-informative prior):
|
smoother |
types of smoothing priors for Fourier coefficients. See Details. |
parametric |
specifying a distribution of the parametric part to be test. |
marginal.likelihood |
a logical variable indicating whether the log marginal likelihood is calculated. |
verbose |
a logical variable. If |
This generic function fits a semiparametric model, which consists of parametric and nonparametric, for density estimation (Lenk, 2003):
where is a zero mean, second-order Gaussian process with bounded, continuous covariance function. i.e.,
Using the Karhunen-Loeve Expansion, is represented as infinite series with random coefficients
where is the cosine basis,
.
For the random Fourier coefficients of the expansion, two smoother priors are assumed (optional),
The coefficient have the popular normal prior,
To complete the model specification, independent hyper priors are assumed,
Note that the posterior algorithm is based on computing a discrete version of the likelihood over a fine mesh on .
An object of class bsad
representing the Bayesian spectral analysis density estimation model fit.
Generic functions such as print
, fitted
and plot
have methods to show the results of the fit.
The MCMC samples of the parameters in the model are stored in the list mcmc.draws
,
the posterior samples of the fitted values are stored in the list fit.draws
, and
the MCMC samples for the log marginal likelihood are saved in the list loglik.draws
.
The output list also includes the following objects:
post.est |
posterior estimates for all parameters in the model. |
lmarg |
log marginal likelihood. |
ProbProbs |
posterior probability of models. |
call |
the matched call. |
mcmctime |
running time of Markov chain from |
Jo, S., Choi, T., Park, B. and Lenk, P. (2019). bsamGP: An R Package for Bayesian Spectral Analysis Models Using Gaussian Process Priors. Journal of Statistical Software, 90, 310-320.
Lenk, P. (2003) Bayesian semiparametric density estimation and model verification using a logistic Gaussian process. Journal of Computational and Graphical Statistics, 12, 548-565.
## Not run: ############################ # Old Faithful geyser data # ############################ data(faithful) attach(faithful) # mcmc parameters mcmc <- list(nblow = 10000, smcmc = 1000, nskip = 10, ndisp = 1000, kappaloop = 5) # fits BSAD model fout <- bsad(x = eruptions, xmin = 0, xmax = 8, nint = 501, mcmc = mcmc, smoother = 'geometric', parametric = 'gamma') # Summary print(fout); summary(fout) # fitted values fit <- fitted(fout) # predictive density plot plot(fit, ask = TRUE) detach(faithful) ## End(Not run)
## Not run: ############################ # Old Faithful geyser data # ############################ data(faithful) attach(faithful) # mcmc parameters mcmc <- list(nblow = 10000, smcmc = 1000, nskip = 10, ndisp = 1000, kappaloop = 5) # fits BSAD model fout <- bsad(x = eruptions, xmin = 0, xmax = 8, nint = 501, mcmc = mcmc, smoother = 'geometric', parametric = 'gamma') # Summary print(fout); summary(fout) # fitted values fit <- fitted(fout) # predictive density plot plot(fit, ask = TRUE) detach(faithful) ## End(Not run)
This function fits a Bayesian semiparametric quantile regression model to estimate shape-restricted functions using a spectral analysis of Gaussian process priors.
bsaq(formula, xmin, xmax, p, nbasis, nint, mcmc = list(), prior = list(), shape = c('Free', 'Increasing', 'Decreasing', 'IncreasingConvex', 'DecreasingConcave', 'IncreasingConcave', 'DecreasingConvex', 'IncreasingS', 'DecreasingS', 'IncreasingRotatedS','DecreasingRotatedS','InvertedU','Ushape', 'IncMultExtreme','DecMultExtreme'), nExtreme = NULL, marginal.likelihood = TRUE, spm.adequacy = FALSE, verbose = FALSE)
bsaq(formula, xmin, xmax, p, nbasis, nint, mcmc = list(), prior = list(), shape = c('Free', 'Increasing', 'Decreasing', 'IncreasingConvex', 'DecreasingConcave', 'IncreasingConcave', 'DecreasingConvex', 'IncreasingS', 'DecreasingS', 'IncreasingRotatedS','DecreasingRotatedS','InvertedU','Ushape', 'IncMultExtreme','DecMultExtreme'), nExtreme = NULL, marginal.likelihood = TRUE, spm.adequacy = FALSE, verbose = FALSE)
formula |
an object of class “ |
xmin |
a vector or scalar giving user-specific minimum values of x. The default values are minimum values of x. |
xmax |
a vector or scalar giving user-specific maximum values of x. The default values are maximum values of x. |
p |
quantile of interest (default=0.5). |
nbasis |
number of cosine basis functions. |
nint |
number of grid points where the unknown function is evaluated for plotting. The default is 200. |
mcmc |
a list giving the MCMC parameters.
The list includes the following integers (with default values in parentheses):
|
prior |
a list giving the prior information. The list includes the following parameters
(default values specify the non-informative prior):
|
shape |
a vector giving types of shape restriction. |
nExtreme |
a vector of extreme points for 'IncMultExtreme', 'DecMultExtreme' shape restrictions. |
marginal.likelihood |
a logical variable indicating whether the log marginal likelihood is calculated. The methods of Gelfand and Dey (1994) and Newton and Raftery (1994) are used. |
spm.adequacy |
a logical variable indicating whether the log marginal likelihood of linear model is calculated. The marginal likelihood gives the values of the linear regression model excluding the nonlinear parts. |
verbose |
a logical variable. If |
This generic function fits a Bayesian spectral analysis quantile regression model for estimating shape-restricted functions using Gaussian process priors. For enforcing shape-restrictions, the model assumed that the derivatives of the functions are squares of Gaussian processes.
Let and
be the response and the vector of parametric predictors, respectively.
Further, let
be the covariate related to the response through an unknown shape-restricted function.
The model for estimating shape-restricted functions is as follows.
where is an unknown shape-restricted function of the scalar
and
the error terms
are a random sample from an asymmetric Laplace distribution,
,
which has the following probability density function:
where is the skew parameter,
is the scale parameter,
is
the location parameter, and
is the indication function.
The prior of function without shape restriction is:
where is a second-order Gaussian process with mean function equal to zero and covariance function
for
. The Gaussian process is expressed with
the spectral representation based on cosine basis functions:
The shape-restricted functions are modeled by assuming the th derivatives of
are squares of Gaussian processes:
where is the squish function. For monotonic, monotonic convex, and concave functions,
, while
for
S
and U
shaped functions, is defined by
For the spectral coefficients of functions without shape constraints, the scale-invariant prior is used
(The intercept is included in ):
The priors for the spectral coefficients of shape restricted functions are:
To complete the model specification, the conjugate priors are assumed for and
:
An object of class bsam
representing the Bayesian spectral analysis model fit.
Generic functions such as print
, fitted
and plot
have methods to show the results of the fit.
The MCMC samples of the parameters in the model are stored in the list mcmc.draws
,
the posterior samples of the fitted values are stored in the list fit.draws
, and
the MCMC samples for the log marginal likelihood are saved in the list loglik.draws
.
The output list also includes the following objects:
post.est |
posterior estimates for all parameters in the model. |
lmarg.lm |
log marginal likelihood for linear quantile regression model. |
lmarg.gd |
log marginal likelihood using Gelfand-Dey method. |
lmarg.nr |
log marginal likelihood using Netwon-Raftery method, which is biased. |
rsquarey |
correlation between |
call |
the matched call. |
mcmctime |
running time of Markov chain from |
Jo, S., Choi, T., Park, B. and Lenk, P. (2019). bsamGP: An R Package for Bayesian Spectral Analysis Models Using Gaussian Process Priors. Journal of Statistical Software, 90, 310-320.
Lenk, P. and Choi, T. (2017) Bayesian Analysis of Shape-Restricted Functions using Gaussian Process Priors. Statistica Sinica, 27: 43-69.
Gelfand, A. E. and Dey, K. K. (1994) Bayesian model choice: asymptotics and exact calculations. Journal of the Royal Statistical Society. Series B - Statistical Methodology, 56, 501-514.
Kozumi, H. and Kobayashi, G. (2011) Gibbs sampling methods for Bayesian quantile regression. Journal of Statistical Computation and Simulation, 81(11), 1565-1578.
Newton, M. A. and Raftery, A. E. (1994) Approximate Bayesian inference with the weighted likelihood bootstrap (with discussion). Journal of the Royal Statistical Society. Series B - Statistical Methodology, 56, 3-48.
## Not run: ###################### # Increasing-concave # ###################### # Simulate data set.seed(1) n <- 200 x <- runif(n) y <- log(1 + 10*x) + rald(n, scale = 0.5, p = 0.5) # Number of cosine basis functions nbasis <- 50 # Fit the model with default priors and mcmc parameters fout1 <- bsaq(y ~ fs(x), p = 0.25, nbasis = nbasis, shape = 'IncreasingConcave') fout2 <- bsaq(y ~ fs(x), p = 0.5, nbasis = nbasis, shape = 'IncreasingConcave') fout3 <- bsaq(y ~ fs(x), p = 0.75, nbasis = nbasis, shape = 'IncreasingConcave') # fitted values fit1 <- fitted(fout1) fit2 <- fitted(fout2) fit3 <- fitted(fout3) # plots plot(x, y, lwd = 2, xlab = 'x', ylab = 'y') lines(fit1$xgrid, fit1$wbeta$mean[1] + fit1$fxgrid$mean, lwd=2, col=2) lines(fit2$xgrid, fit2$wbeta$mean[1] + fit2$fxgrid$mean, lwd=2, col=3) lines(fit3$xgrid, fit3$wbeta$mean[1] + fit3$fxgrid$mean, lwd=2, col=4) legend('topleft', legend = c('1st Quartile', '2nd Quartile', '3rd Quartile'), lwd = 2, col = 2:4, lty = 1) ## End(Not run)
## Not run: ###################### # Increasing-concave # ###################### # Simulate data set.seed(1) n <- 200 x <- runif(n) y <- log(1 + 10*x) + rald(n, scale = 0.5, p = 0.5) # Number of cosine basis functions nbasis <- 50 # Fit the model with default priors and mcmc parameters fout1 <- bsaq(y ~ fs(x), p = 0.25, nbasis = nbasis, shape = 'IncreasingConcave') fout2 <- bsaq(y ~ fs(x), p = 0.5, nbasis = nbasis, shape = 'IncreasingConcave') fout3 <- bsaq(y ~ fs(x), p = 0.75, nbasis = nbasis, shape = 'IncreasingConcave') # fitted values fit1 <- fitted(fout1) fit2 <- fitted(fout2) fit3 <- fitted(fout3) # plots plot(x, y, lwd = 2, xlab = 'x', ylab = 'y') lines(fit1$xgrid, fit1$wbeta$mean[1] + fit1$fxgrid$mean, lwd=2, col=2) lines(fit2$xgrid, fit2$wbeta$mean[1] + fit2$fxgrid$mean, lwd=2, col=3) lines(fit3$xgrid, fit3$wbeta$mean[1] + fit3$fxgrid$mean, lwd=2, col=4) legend('topleft', legend = c('1st Quartile', '2nd Quartile', '3rd Quartile'), lwd = 2, col = 2:4, lty = 1) ## End(Not run)
This function fits a Bayesian semiparametric quantile regression model to estimate shape-restricted functions using a spectral analysis of Gaussian process priors. The model assumes that the errors follow a Dirichlet process mixture model.
bsaqdpm(formula, xmin, xmax, p, nbasis, nint, mcmc = list(), prior = list(), egrid, ngrid = 500, shape = c('Free', 'Increasing', 'Decreasing', 'IncreasingConvex', 'DecreasingConcave', 'IncreasingConcave', 'DecreasingConvex', 'IncreasingS', 'DecreasingS', 'IncreasingRotatedS', 'DecreasingRotatedS', 'InvertedU', 'Ushape'), verbose = FALSE)
bsaqdpm(formula, xmin, xmax, p, nbasis, nint, mcmc = list(), prior = list(), egrid, ngrid = 500, shape = c('Free', 'Increasing', 'Decreasing', 'IncreasingConvex', 'DecreasingConcave', 'IncreasingConcave', 'DecreasingConvex', 'IncreasingS', 'DecreasingS', 'IncreasingRotatedS', 'DecreasingRotatedS', 'InvertedU', 'Ushape'), verbose = FALSE)
formula |
an object of class “ |
xmin |
a vector or scalar giving user-specific minimum values of x. The default values are minimum values of x. |
xmax |
a vector or scalar giving user-specific maximum values of x. The default values are maximum values of x. |
p |
quantile of interest (default=0.5). |
nbasis |
number of cosine basis functions. |
nint |
number of grid points where the unknown function is evaluated for plotting. The default is 200. |
mcmc |
a list giving the MCMC parameters.
The list includes the following integers (with default values in parentheses):
|
prior |
a list giving the prior information. The list includes the following parameters
(default values specify the non-informative prior):
|
egrid |
a vector giving grid points where the residual density estimate is evaluated. The default range is from -10 to 10. |
ngrid |
a vector giving number of grid points where the residual density estimate is evaluated. The default value is 500. |
shape |
a vector giving types of shape restriction. |
verbose |
a logical variable. If |
This generic function fits a Bayesian spectral analysis quantile regression model for estimating shape-restricted functions using Gaussian process priors. For enforcing shape-restrictions, the model assumes that the derivatives of the functions are squares of Gaussian processes. The model also assumes that the errors follow a Dirichlet process mixture model.
Let and
be the response and the vector of parametric predictors, respectively.
Further, let
be the covariate related to the response through an unknown shape-restricted function.
The model for estimating shape-restricted functions is as follows.
where is an unknown shape-restricted function of the scalar
and
the error terms
are a random sample from a Dirichlet process mixture of an asymmetric Laplace distribution,
, which has the following probability density function:
The prior of function without shape restriction is:
where is a second-order Gaussian process with mean function equal to zero and covariance function
for
. The Gaussian process is expressed with
the spectral representation based on cosine basis functions:
The shape-restricted functions are modeled by assuming the th derivatives of
are squares of Gaussian processes:
where is the squish function. For monotonic, monotonic convex, and concave functions,
, while
for
S
and U
shaped functions, is defined by
For the spectral coefficients of functions without shape constraints, the scale-invariant prior is used
(The intercept is included in ):
The priors for the spectral coefficients of shape restricted functions are:
To complete the model specification, the popular normal prior is assumed for :
An object of class bsam
representing the Bayesian spectral analysis model fit.
Generic functions such as print
, fitted
and plot
have methods to show the results of the fit.
The MCMC samples of the parameters in the model are stored in the list mcmc.draws
,
the posterior samples of the fitted values are stored in the list fit.draws
, and
the MCMC samples for the log marginal likelihood are saved in the list loglik.draws
.
The output list also includes the following objects:
post.est |
posterior estimates for all parameters in the model. |
lpml |
log pseudo marginal likelihood using Mukhopadhyay and Gelfand method. |
rsquarey |
correlation between |
imodmet |
the number of times to modify Metropolis. |
pmet |
proportion of |
call |
the matched call. |
mcmctime |
running time of Markov chain from |
Jo, S., Choi, T., Park, B. and Lenk, P. (2019). bsamGP: An R Package for Bayesian Spectral Analysis Models Using Gaussian Process Priors. Journal of Statistical Software, 90, 310-320.
Kozumi, H. and Kobayashi, G. (2011) Gibbs sampling methods for Bayesian quantile regression. Journal of Statistical Computation and Simulation, 81(11), 1565-1578.
Lenk, P. and Choi, T. (2017) Bayesian Analysis of Shape-Restricted Functions using Gaussian Process Priors. Statistica Sinica, 27, 43-69.
MacEachern, S. N. and Müller, P. (1998) Estimating mixture of Dirichlet process models. Journal of Computational and Graphical Statistics, 7, 223-238.
Mukhopadhyay, S. and Gelfand, A. E. (1997) Dirichlet process mixed generalized linear models. Journal of the American Statistical Association, 92, 633-639.
Neal, R. M. (2000) Markov chain sampling methods for Dirichlet process mixture models. Journal of Computational and Graphical Statistics, 9, 249-265.
## Not run: ###################### # Increasing-concave # ###################### # Simulate data set.seed(1) n <- 500 x <- runif(n) e <- c(rald(n/2, scale = 0.5, p = 0.5), rald(n/2, scale = 3, p = 0.5)) y <- log(1 + 10*x) + e # Number of cosine basis functions nbasis <- 50 # Fit the model with default priors and mcmc parameters fout1 <- bsaqdpm(y ~ fs(x), p = 0.25, nbasis = nbasis, shape = 'IncreasingConcave') fout2 <- bsaqdpm(y ~ fs(x), p = 0.5, nbasis = nbasis, shape = 'IncreasingConcave') fout3 <- bsaqdpm(y ~ fs(x), p = 0.75, nbasis = nbasis, shape = 'IncreasingConcave') # fitted values fit1 <- fitted(fout1) fit2 <- fitted(fout2) fit3 <- fitted(fout3) # plots plot(x, y, lwd = 2, xlab = 'x', ylab = 'y') lines(fit1$xgrid, fit1$wbeta$mean[1] + fit1$fxgrid$mean, lwd=2, col=2) lines(fit2$xgrid, fit2$wbeta$mean[1] + fit2$fxgrid$mean, lwd=2, col=3) lines(fit3$xgrid, fit3$wbeta$mean[1] + fit3$fxgrid$mean, lwd=2, col=4) legend('topleft',legend=c('1st Quartile','2nd Quartile','3rd Quartile'), lwd=2, col=2:4, lty=1) ## End(Not run)
## Not run: ###################### # Increasing-concave # ###################### # Simulate data set.seed(1) n <- 500 x <- runif(n) e <- c(rald(n/2, scale = 0.5, p = 0.5), rald(n/2, scale = 3, p = 0.5)) y <- log(1 + 10*x) + e # Number of cosine basis functions nbasis <- 50 # Fit the model with default priors and mcmc parameters fout1 <- bsaqdpm(y ~ fs(x), p = 0.25, nbasis = nbasis, shape = 'IncreasingConcave') fout2 <- bsaqdpm(y ~ fs(x), p = 0.5, nbasis = nbasis, shape = 'IncreasingConcave') fout3 <- bsaqdpm(y ~ fs(x), p = 0.75, nbasis = nbasis, shape = 'IncreasingConcave') # fitted values fit1 <- fitted(fout1) fit2 <- fitted(fout2) fit3 <- fitted(fout3) # plots plot(x, y, lwd = 2, xlab = 'x', ylab = 'y') lines(fit1$xgrid, fit1$wbeta$mean[1] + fit1$fxgrid$mean, lwd=2, col=2) lines(fit2$xgrid, fit2$wbeta$mean[1] + fit2$fxgrid$mean, lwd=2, col=3) lines(fit3$xgrid, fit3$wbeta$mean[1] + fit3$fxgrid$mean, lwd=2, col=4) legend('topleft',legend=c('1st Quartile','2nd Quartile','3rd Quartile'), lwd=2, col=2:4, lty=1) ## End(Not run)
This function fits a Bayesian semiparametric regression model to estimate shape-restricted functions using a spectral analysis of Gaussian process priors.
bsar(formula, xmin, xmax, nbasis, nint, mcmc = list(), prior = list(), shape = c('Free', 'Increasing', 'Decreasing', 'IncreasingConvex', 'DecreasingConcave', 'IncreasingConcave', 'DecreasingConvex', 'IncreasingS', 'DecreasingS', 'IncreasingRotatedS','DecreasingRotatedS','InvertedU','Ushape', 'IncMultExtreme','DecMultExtreme'), nExtreme = NULL, marginal.likelihood = TRUE, spm.adequacy = FALSE, verbose = FALSE)
bsar(formula, xmin, xmax, nbasis, nint, mcmc = list(), prior = list(), shape = c('Free', 'Increasing', 'Decreasing', 'IncreasingConvex', 'DecreasingConcave', 'IncreasingConcave', 'DecreasingConvex', 'IncreasingS', 'DecreasingS', 'IncreasingRotatedS','DecreasingRotatedS','InvertedU','Ushape', 'IncMultExtreme','DecMultExtreme'), nExtreme = NULL, marginal.likelihood = TRUE, spm.adequacy = FALSE, verbose = FALSE)
formula |
an object of class “ |
xmin |
a vector or scalar giving user-specific minimum values of x. The default values are minimum values of x. |
xmax |
a vector or scalar giving user-specific maximum values of x. The default values are maximum values of x. |
nbasis |
number of cosine basis functions. |
nint |
number of grid points where the unknown function is evaluated for plotting. The default is 200. |
mcmc |
a list giving the MCMC parameters.
The list includes the following integers (with default values in parentheses):
|
prior |
a list giving the prior information. The list includes the following parameters
(default values specify the non-informative prior):
|
shape |
a vector giving types of shape restriction. |
nExtreme |
a vector of extreme points for 'IncMultExtreme', 'DecMultExtreme' shape restrictions. |
marginal.likelihood |
a logical variable indicating whether the log marginal likelihood is calculated. The methods of Gelfand and Dey (1994) and Newton and Raftery (1994) are used. |
spm.adequacy |
a logical variable indicating whether the log marginal likelihood of linear model is calculated. The marginal likelihood gives the values of the linear regression model excluding the nonlinear parts. |
verbose |
a logical variable. If |
This generic function fits a Bayesian spectral analysis regression model (Lenk and Choi, 2015) for estimating shape-restricted functions using Gaussian process priors. For enforcing shape-restrictions, they assumed that the derivatives of the functions are squares of Gaussian processes.
Let and
be the response and the vector of parametric predictors, respectively.
Further, let
be the covariate related to the response through an unknown shape-restricted function.
The model for estimating shape-restricted functions is as follows.
where is an unknown shape-restricted function of the scalar
and
the error terms
are a random sample from a normal distribution,
.
The prior of function without shape restriction is:
where is a second-order Gaussian process with mean function equal to zero and covariance function
for
. The Gaussian process is expressed with
the spectral representation based on cosine basis functions:
The shape-restricted functions are modeled by assuming the th derivatives of
are squares of Gaussian processes:
where is the squish function. For monotonic, monotonic convex, and concave functions,
, while
for
S
and U
shaped functions, is defined by
For the spectral coefficients of functions without shape constraints, the scale-invariant prior is used
(The intercept is included in ):
The priors for the spectral coefficients of shape restricted functions are:
To complete the model specification, the conjugate priors are assumed for and
:
An object of class bsam
representing the Bayesian spectral analysis model fit.
Generic functions such as print
, fitted
and plot
have methods to show the results of the fit.
The MCMC samples of the parameters in the model are stored in the list mcmc.draws
,
the posterior samples of the fitted values are stored in the list fit.draws
, and
the MCMC samples for the log marginal likelihood are saved in the list loglik.draws
.
The output list also includes the following objects:
post.est |
posterior estimates for all parameters in the model. |
lmarg.lm |
log marginal likelihood for linear regression model. |
lmarg.gd |
log marginal likelihood using Gelfand-Dey method. |
lmarg.nr |
log marginal likelihood using Netwon-Raftery method, which is biased. |
rsquarey |
correlation between |
call |
the matched call. |
mcmctime |
running time of Markov chain from |
Jo, S., Choi, T., Park, B. and Lenk, P. (2019). bsamGP: An R Package for Bayesian Spectral Analysis Models Using Gaussian Process Priors. Journal of Statistical Software, 90, 310-320.
Lenk, P. and Choi, T. (2017) Bayesian Analysis of Shape-Restricted Functions using Gaussian Process Priors. Statistica Sinica, 27, 43-69.
Gelfand, A. E. and Dey, K. K. (1994) Bayesian model choice: asymptotics and exact calculations. Journal of the Royal Statistical Society. Series B - Statistical Methodology, 56, 501-514.
Newton, M. A. and Raftery, A. E. (1994) Approximate Bayesian inference with the weighted likelihood bootstrap (with discussion). Journal of the Royal Statistical Society. Series B - Statistical Methodology, 56, 3-48.
## Not run: ########################################## # Increasing Convex to Concave (S-shape) # ########################################## # simulate data f <- function(x) 5*exp(-10*(x - 1)^4) + 5*x^2 set.seed(1) n <- 100 x <- runif(n) y <- f(x) + rnorm(n, sd = 1) # Number of cosine basis functions nbasis <- 50 # Fit the model with default priors and mcmc parameters fout <- bsar(y ~ fs(x), nbasis = nbasis, shape = 'IncreasingConvex', spm.adequacy = TRUE) # Summary print(fout); summary(fout) # Trace plots plot(fout) # fitted values fit <- fitted(fout) # Plot plot(fit, ask = TRUE) ############################################# # Additive Model # # Monotone-Increasing and Increasing-Convex # ############################################# # Simulate data f1 <- function(x) 2*pi*x + sin(2*pi*x) f2 <- function(x) exp(6*x - 3) n <- 200 x1 <- runif(n) x2 <- runif(n) x <- cbind(x1, x2) y <- 5 + f1(x1) + f2(x2) + rnorm(n, sd = 0.5) # Number of cosine basis functions nbasis <- 50 # MCMC parameters mcmc <- list(nblow0 = 1000, nblow = 10000, nskip = 10, smcmc = 5000, ndisp = 1000, maxmodmet = 10) # Prior information xmin <- apply(x, 2, min) xmax <- apply(x, 2, max) xrange <- xmax - xmin prior <- list(iflagprior = 0, theta0_m0 = 0, theta0_s0 = 100, tau2_m0 = 1, tau2_v0 = 100, w0 = 2, beta_m0 = numeric(1), beta_v0 = diag(100,1), sigma2_m0 = 1, sigma2_v0 = 1000, alpha_m0 = 3, alpha_s0 = 50, iflagpsi = 1, psifixed = 1000, omega_m0 = (xmin + xmax)/2, omega_s0 = (xrange)/8) # Fit the model with user specific priors and mcmc parameters fout <- bsar(y ~ fs(x1) + fs(x2), nbasis = nbasis, mcmc = mcmc, prior = prior, shape = c('Increasing', 'IncreasingS')) # Summary print(fout); summary(fout) ## End(Not run)
## Not run: ########################################## # Increasing Convex to Concave (S-shape) # ########################################## # simulate data f <- function(x) 5*exp(-10*(x - 1)^4) + 5*x^2 set.seed(1) n <- 100 x <- runif(n) y <- f(x) + rnorm(n, sd = 1) # Number of cosine basis functions nbasis <- 50 # Fit the model with default priors and mcmc parameters fout <- bsar(y ~ fs(x), nbasis = nbasis, shape = 'IncreasingConvex', spm.adequacy = TRUE) # Summary print(fout); summary(fout) # Trace plots plot(fout) # fitted values fit <- fitted(fout) # Plot plot(fit, ask = TRUE) ############################################# # Additive Model # # Monotone-Increasing and Increasing-Convex # ############################################# # Simulate data f1 <- function(x) 2*pi*x + sin(2*pi*x) f2 <- function(x) exp(6*x - 3) n <- 200 x1 <- runif(n) x2 <- runif(n) x <- cbind(x1, x2) y <- 5 + f1(x1) + f2(x2) + rnorm(n, sd = 0.5) # Number of cosine basis functions nbasis <- 50 # MCMC parameters mcmc <- list(nblow0 = 1000, nblow = 10000, nskip = 10, smcmc = 5000, ndisp = 1000, maxmodmet = 10) # Prior information xmin <- apply(x, 2, min) xmax <- apply(x, 2, max) xrange <- xmax - xmin prior <- list(iflagprior = 0, theta0_m0 = 0, theta0_s0 = 100, tau2_m0 = 1, tau2_v0 = 100, w0 = 2, beta_m0 = numeric(1), beta_v0 = diag(100,1), sigma2_m0 = 1, sigma2_v0 = 1000, alpha_m0 = 3, alpha_s0 = 50, iflagpsi = 1, psifixed = 1000, omega_m0 = (xmin + xmax)/2, omega_s0 = (xrange)/8) # Fit the model with user specific priors and mcmc parameters fout <- bsar(y ~ fs(x1) + fs(x2), nbasis = nbasis, mcmc = mcmc, prior = prior, shape = c('Increasing', 'IncreasingS')) # Summary print(fout); summary(fout) ## End(Not run)
This function fits a Bayesian spectral analysis regression model for Big data.
bsarBig(formula, nbasis, nint, mcmc = list(), prior = list(), verbose = FALSE)
bsarBig(formula, nbasis, nint, mcmc = list(), prior = list(), verbose = FALSE)
formula |
an object of class “ |
nbasis |
number of cosine basis functions. |
nint |
number of grid points where the unknown function is evaluated for plotting. The default is 500. |
mcmc |
a list giving the MCMC parameters.
The list includes the following integers (with default values in parentheses):
|
prior |
a list giving the prior information. The list includes the following parameters
(default values specify the non-informative prior):
|
verbose |
a logical variable. If |
The MCMC samples of the parameters in the model are stored in the list mcmc.draws
and
the posterior samples of the fitted values are stored in the list fit.draws
.
The output list also includes the following objects:
post.est |
posterior estimates for all parameters in the model. |
call |
the matched call. |
mcmctime |
running time of Markov chain from |
# Ttrue function ftrue <- function(x){ ft <- 7*exp(-3*x) + 2*exp(-70*(x-.6)^2) - 2 + 5*x return(ft) } # Generate data set.seed(1) nobs <- 100000 # Number of observations sigmat <- .5 # True sigma nxgrid <- 500 # number of grid points: approximate likelihood & plots xdata <- runif(nobs) # Generate x values fobst <- ftrue(xdata) # True f at observations ydata <- fobst + sigmat*rnorm(nobs) # Compute grid on 0 to 1 xdelta <- 1/nxgrid xgrid <- seq(xdelta/2, 1-xdelta/2, xdelta) xgrid <- matrix(xgrid,nxgrid) fxgridt <- ftrue(xgrid) # True f on xgrid # Fit data fout <- bsarBig(ydata ~ xdata, nbasis = 50, nint = nxgrid, verbose = TRUE) # Plots smcmc <- fout$mcmc$smcmc t <- 1:smcmc par(mfrow=c(2,2)) matplot(t, fout$mcmc.draws$theta, type = "l", main = "Theta", xlab = "Iteration", ylab = "Draw") plot(t, fout$mcmc.draws$sigma, type = "l", main = "Sigma", xlab = "Iteration", ylab = "Draw") matplot(t, fout$mcmc.draws$tau, type = "l", main = "Tau", xlab = "Iteration", ylab = "Draw") matplot(t, fout$mcmc.draws$gamma, type = "l", main = "Gamma", xlab = "Iteration", ylab = "Draw") dev.new() matplot(fout$fit.draws$xgrid, cbind(fxgridt, fout$post.est$fhatm, fout$post.est$fhatq), type = "l", main = "Regression Function", xlab = "X", ylab = "Y") # Compute RMISE for regression function sse <- (fout$post.est$fhatm - fxgridt)^2 rmise <- intgrat(sse, 1/nxgrid) rmise <- sqrt(rmise) rmise
# Ttrue function ftrue <- function(x){ ft <- 7*exp(-3*x) + 2*exp(-70*(x-.6)^2) - 2 + 5*x return(ft) } # Generate data set.seed(1) nobs <- 100000 # Number of observations sigmat <- .5 # True sigma nxgrid <- 500 # number of grid points: approximate likelihood & plots xdata <- runif(nobs) # Generate x values fobst <- ftrue(xdata) # True f at observations ydata <- fobst + sigmat*rnorm(nobs) # Compute grid on 0 to 1 xdelta <- 1/nxgrid xgrid <- seq(xdelta/2, 1-xdelta/2, xdelta) xgrid <- matrix(xgrid,nxgrid) fxgridt <- ftrue(xgrid) # True f on xgrid # Fit data fout <- bsarBig(ydata ~ xdata, nbasis = 50, nint = nxgrid, verbose = TRUE) # Plots smcmc <- fout$mcmc$smcmc t <- 1:smcmc par(mfrow=c(2,2)) matplot(t, fout$mcmc.draws$theta, type = "l", main = "Theta", xlab = "Iteration", ylab = "Draw") plot(t, fout$mcmc.draws$sigma, type = "l", main = "Sigma", xlab = "Iteration", ylab = "Draw") matplot(t, fout$mcmc.draws$tau, type = "l", main = "Tau", xlab = "Iteration", ylab = "Draw") matplot(t, fout$mcmc.draws$gamma, type = "l", main = "Gamma", xlab = "Iteration", ylab = "Draw") dev.new() matplot(fout$fit.draws$xgrid, cbind(fxgridt, fout$post.est$fhatm, fout$post.est$fhatq), type = "l", main = "Regression Function", xlab = "X", ylab = "Y") # Compute RMISE for regression function sse <- (fout$post.est$fhatm - fxgridt)^2 rmise <- intgrat(sse, 1/nxgrid) rmise <- sqrt(rmise) rmise
This function fits a Bayesian semiparametric regression model to estimate shape-restricted functions using a spectral analysis of Gaussian process priors. The model assumes that the errors follow a Dirichlet process mixture model.
bsardpm(formula, xmin, xmax, nbasis, nint, mcmc = list(), prior = list(), egrid, ngrid, location = TRUE, shape = c('Free', 'Increasing', 'Decreasing', 'IncreasingConvex', 'DecreasingConcave', 'IncreasingConcave', 'DecreasingConvex', 'IncreasingS', 'DecreasingS', 'IncreasingRotatedS','DecreasingRotatedS','InvertedU','Ushape'), verbose = FALSE)
bsardpm(formula, xmin, xmax, nbasis, nint, mcmc = list(), prior = list(), egrid, ngrid, location = TRUE, shape = c('Free', 'Increasing', 'Decreasing', 'IncreasingConvex', 'DecreasingConcave', 'IncreasingConcave', 'DecreasingConvex', 'IncreasingS', 'DecreasingS', 'IncreasingRotatedS','DecreasingRotatedS','InvertedU','Ushape'), verbose = FALSE)
formula |
an object of class “ |
xmin |
a vector or scalar giving user-specific minimum values of x. The default values are minimum values of x. |
xmax |
a vector or scalar giving user-specific maximum values of x. The default values are maximum values of x. |
nbasis |
number of cosine basis functions. |
nint |
number of grid points where the unknown function is evaluated for plotting. The default is 200. |
mcmc |
a list giving the MCMC parameters.
The list includes the following integers (with default values in parentheses):
|
prior |
a list giving the prior information. The list includes the following parameters
(default values specify the non-informative prior):
|
egrid |
a vector giving grid points where the residual density estimate is evaluated. The default range is from -10 to 10. |
ngrid |
a vector giving number of grid points where the residual density estimate is evaluated. The default value is 500. |
location |
a logical value. If it is true, error density is modelled using location-scale mixture. |
shape |
a vector giving types of shape restriction. |
verbose |
a logical variable. If |
This generic function fits a Bayesian spectral analysis regression model for estimating shape-restricted functions using Gaussian process priors. For enforcing shape-restrictions, the model assumes that the derivatives of the functions are squares of Gaussian processes. The model also assumes that the errors follow a Dirichlet process mixture model.
Let and
be the response and the vector of parametric predictors, respectively.
Further, let
be the covariate related to the response through an unknown shape-restricted function.
The model for estimating shape-restricted functions is as follows.
where is an unknown shape-restricted function of the scalar
and
the error terms
are a random sample from a Dirichlet process mixture model,
1. scale mixture :
2. location-scale mixture :
The prior of function without shape restriction is:
where is a second-order Gaussian process with mean function equal to zero and covariance function
for
. The Gaussian process is expressed with
the spectral representation based on cosine basis functions:
The shape-restricted functions are modeled by assuming the th derivatives of
are squares of Gaussian processes:
where is the squish function. For monotonic, monotonic convex, and concave functions,
, while
for
S
and U
shaped functions, is defined by
For the spectral coefficients of functions without shape constraints, the scale-invariant prior is used
(The intercept is included in ):
The priors for the spectral coefficients of shape restricted functions are:
To complete the model specification, the popular normal prior is assumed for :
An object of class bsam
representing the Bayesian spectral analysis model fit.
Generic functions such as print
, fitted
and plot
have methods to show the results of the fit.
The MCMC samples of the parameters in the model are stored in the list mcmc.draws
,
the posterior samples of the fitted values are stored in the list fit.draws
, and
the MCMC samples for the log marginal likelihood are saved in the list loglik.draws
.
The output list also includes the following objects:
post.est |
posterior estimates for all parameters in the model. |
lpml |
log pseudo marginal likelihood using Mukhopadhyay and Gelfand method. |
imodmet |
the number of times to modify Metropolis. |
pmet |
proportion of |
call |
the matched call. |
mcmctime |
running time of Markov chain from |
Jo, S., Choi, T., Park, B. and Lenk, P. (2019). bsamGP: An R Package for Bayesian Spectral Analysis Models Using Gaussian Process Priors. Journal of Statistical Software, 90, 310-320.
Lenk, P. and Choi, T. (2017) Bayesian Analysis of Shape-Restricted Functions using Gaussian Process Priors. Statistica Sinica, 27, 43-69.
MacEachern, S. N. and Müller, P. (1998) Estimating mixture of Dirichlet process models. Journal of Computational and Graphical Statistics, 7, 223-238.
Mukhopadhyay, S. and Gelfand, A. E. (1997) Dirichlet process mixed generalized linear models. Journal of the American Statistical Association, 92, 633-639.
Neal, R. M. (2000) Markov chain sampling methods for Dirichlet process mixture models. Journal of Computational and Graphical Statistics, 9, 249-265.
## Not run: ##################### # Increasing-convex # ##################### # Simulate data set.seed(1) n <- 200 x <- runif(n) e <- c(rnorm(n/2, sd = 0.5), rnorm(n/2, sd = 3)) y <- exp(6*x - 3) + e # Number of cosine basis functions nbasis <- 50 # Fit the model with default priors and mcmc parameters fout <- bsardpm(y ~ fs(x), nbasis = nbasis, shape = 'IncreasingConvex') # Summary print(fout); summary(fout) # fitted values fit <- fitted(fout) # Plot plot(fit, ask = TRUE) ## End(Not run)
## Not run: ##################### # Increasing-convex # ##################### # Simulate data set.seed(1) n <- 200 x <- runif(n) e <- c(rnorm(n/2, sd = 0.5), rnorm(n/2, sd = 3)) y <- exp(6*x - 3) + e # Number of cosine basis functions nbasis <- 50 # Fit the model with default priors and mcmc parameters fout <- bsardpm(y ~ fs(x), nbasis = nbasis, shape = 'IncreasingConvex') # Summary print(fout); summary(fout) # fitted values fit <- fitted(fout) # Plot plot(fit, ask = TRUE) ## End(Not run)
This dataset includes minimal information of NCC-2012 meta data.
data("cadmium")
data("cadmium")
A data frame with 190 observations on the following 5 variables.
gender
a numeric vector with 1 : Female, 0 : Male, 0.5 : Unknown or both
ethnicity
a integer vector with 1 : Asian, 2 : Caucasian
Ucd_GM
a numeric vector of Geometric means of urinary cadmium
b2_GM
a numeric vector of Geometric means of Beta2-Microglobulin
isOld
a logical vector whether the observation is older than 50
Lee, Minjea, Choi, Taeryon; Kim, Jeongseon; Woo, Hae Dong (2013) Bayesian Analysis of Dose-Effect Relationship of Cadmium for Benchmark Dose Evaluation. Korean Journal of Applied Statistics, 26(3), 453–470.
## Not run: data(cadmium) ## End(Not run)
## Not run: data(cadmium) ## End(Not run)
The Elec.demand data consists of 288 quarterly observations in Ontario from 1971 to 1994.
data(Elec.demand)
data(Elec.demand)
A data frame with 288 observations on the following 7 variables.
date (yyyy-mm) from 1971 to 1994
electricity demand.
gross domestic product.
price of electricity.
price of natural gas.
the number of heating degree days relative to a reference temperature.
the number of cooling degree days relative to a reference temperature.
Yatchew, A. (2003). Semiparametric Regression for the Applied Econometrician. Cambridge University Press.
Engle, R. F., Granger, C. W. J., Rice, J. and Weiss, A. (1986). Semiparametric estimates of the relation between weather and electricity sales. Journal of the American Statistical Association, 81, 310-320.
Lenk, P. and Choi, T. (2017). Bayesian analysis of shape-restricted functions using Gaussian process priors. Statistica Sinica, 27, 43-69.
## Not run: data(Elec.demand) plot(Elec.demand) ## End(Not run)
## Not run: data(Elec.demand) plot(Elec.demand) ## End(Not run)
Computes pointwise posterior means and 95% credible intervals of the fitted Bayesian linear models.
## S3 method for class 'blm' fitted(object, alpha = 0.05, HPD = TRUE, ...)
## S3 method for class 'blm' fitted(object, alpha = 0.05, HPD = TRUE, ...)
object |
a |
alpha |
a numeric scalar in the interval (0,1) giving the |
HPD |
a logical variable indicating whether the |
... |
not used |
None.
A list containing posterior means and 95% credible intervals.
The output list includes the following objects:
wbeta |
posterior estimates for regression function. |
yhat |
posterior estimates for generalised regression function. |
Chen, M., Shao, Q. and Ibrahim, J. (2000) Monte Carlo Methods in Bayesian computation. Springer-Verlag New York, Inc.
## See examples for blq and blr
## See examples for blq and blr
Computes pointwise posterior means and % credible intervals of the fitted Bayesian spectral analysis density estimation model.
## S3 method for class 'bsad' fitted(object, alpha = 0.05, HPD = TRUE, ...)
## S3 method for class 'bsad' fitted(object, alpha = 0.05, HPD = TRUE, ...)
object |
a |
alpha |
a numeric scalar in the interval (0,1) giving the |
HPD |
a logical variable indicating whether the |
... |
not used |
None.
A list object of class fitted.bsad
containing posterior means and % credible intervals.
Generic function
plot
displays the results of the fit.
The output list includes the following objects:
fpar |
posterior estimates for parametric model. |
fsemi |
posterior estimates for semiparametric model. |
fsemiMaxKappa |
posterior estimates for semiparametric model with maximum number of basis. |
## See examples for bsad
## See examples for bsad
Computes pointwise posterior means and % credible intervals of the fitted Bayesian spectral analysis models.
## S3 method for class 'bsam' fitted(object, alpha = 0.05, HPD = TRUE, ...)
## S3 method for class 'bsam' fitted(object, alpha = 0.05, HPD = TRUE, ...)
object |
a |
alpha |
a numeric scalar in the interval (0,1) giving the |
HPD |
a logical variable indicating whether the |
... |
not used |
None.
A list object of class fitted.bsam
containing posterior means and % credible intervals.
Generic function
plot
displays the results of the fit.
The output list includes the following objects:
fxobs |
posterior estimates for unknown functions over observation. |
fxgrid |
posterior estimates for unknown functions over grid points. |
wbeta |
posterior estimates for parametric part. |
yhat |
posterior estimates for fitted values of response.
For |
## See examples for bsaq, bsaqdpm, bsar, and bsardpm
## See examples for bsaq, bsaqdpm, bsar, and bsardpm
Computes pointwise posterior means and % credible intervals of the fitted Bayesian spectral analysis models with Dirichlet process mixture error.
## S3 method for class 'bsamdpm' fitted(object, alpha = 0.05, HPD = TRUE, ...)
## S3 method for class 'bsamdpm' fitted(object, alpha = 0.05, HPD = TRUE, ...)
object |
a |
alpha |
a numeric scalar in the interval (0,1) giving the |
HPD |
a logical variable indicating whether the |
... |
not used |
None.
A list object of class fitted.bsamdpm
containing posterior means and 95% credible intervals.
Generic function plot
displays the results of the fit.
The output list includes the following objects:
edens |
posterior estimate for unknown error distribution over grid points. |
fxobs |
posterior estimates for unknown functions over observation. |
fxgrid |
posterior estimates for unknown functions over grid points. |
wbeta |
posterior estimates for parametric part. |
yhat |
posterior estimates for fitted values of response. |
## See examples for bsaqdpm and bsardpm
## See examples for bsaqdpm and bsardpm
A symbolic wrapper to indicate a nonparametric term in a formula argument to bsaq, bsaqdpm, bsar, bsardpm, and gbsar.
fs(x)
fs(x)
x |
a vector of the univariate covariate for nonparametric component |
## Not run: # fit x using a Fourier basis y ~ w + fs(x) # fit x1 and x2 using a Fourier basis y ~ fs(x1) + fs(x2) ## End(Not run)
## Not run: # fit x using a Fourier basis y ~ w + fs(x) # fit x1 and x2 using a Fourier basis y ~ fs(x1) + fs(x2) ## End(Not run)
This function fits a Bayesian generalized linear regression model.
gblr(formula, data = NULL, family, link, mcmc = list(), prior = list(), marginal.likelihood = TRUE, algorithm = c('AM', 'KS'), verbose = FALSE)
gblr(formula, data = NULL, family, link, mcmc = list(), prior = list(), marginal.likelihood = TRUE, algorithm = c('AM', 'KS'), verbose = FALSE)
formula |
an object of class “ |
data |
an optional data frame. |
family |
a description of the error distribution to be used in the model: The family contains bernoulli (“bernoulli”), poisson (“poisson”), negative-binomial (“negative.binomial”), poisson-gamma mixture (“poisson.gamma”). |
link |
a description of the link function to be used in the model. |
mcmc |
a list giving the MCMC parameters.
The list includes the following integers (with default values in parentheses):
|
prior |
a list giving the prior information. The list includes the following parameters
(default values specify the non-informative prior):
|
marginal.likelihood |
a logical variable indicating whether the log marginal likelihood is calculated. The methods of Gelfand and Dey (1994) is used. |
algorithm |
a description of the algorithm to be used in the fitting of the logistic model:
The algorithm contains the Gibbs sampler based on the Kolmogorov-Smirnov distribution ( |
verbose |
a logical variable. If |
This generic function fits a Bayesian generalized linear regression models.
Let and
be the response and the vector of parametric predictors, respectively.
The model is as follows.
where is a link function and
is a distribution of an exponential family.
For unknown coefficients, the following prior is assumed for :
The prior for the dispersion parameter of negative-binomial regression is
An object of class blm
representing the generalized Bayesian linear model fit.
Generic functions such as print
, fitted
and plot
have methods to show the results of the fit.
The MCMC samples of the parameters in the model are stored in the list mcmc.draws
,
the posterior samples of the fitted values are stored in the list fit.draws
, and
the MCMC samples for the log marginal likelihood are saved in the list loglik.draws
.
The output list also includes the following objects:
post.est |
posterior estimates for all parameters in the model. |
lmarg |
log marginal likelihood using Gelfand-Dey method. |
family |
the family object used. |
link |
the link object used. |
methods |
the method object used in the logit model. |
call |
the matched call. |
mcmctime |
running time of Markov chain from |
Albert, J. H. and Chib, S. (1993) Bayesian Analysis of Binary and Polychotomous Response Data. Journal of the American Statistical Association, 88, 669-679.
Holmes, C. C. and Held, L. (2006) Bayesian Auxiliary Variables Models for Binary and Multinomial Regression. Bayesian Analysis, 1, 145-168.
Gelfand, A. E. and Dey, K. K. (1994) Bayesian Model Choice: Asymptotics and Exact Calculations. Journal of the Royal Statistical Society. Series B - Statistical Methodology, 56, 501-514.
Roberts, G. O. and Rosenthal, J. S. (2009) Examples of Adaptive MCMC. Journal of Computational and Graphical Statistics, 18, 349-367.
############################ # Poisson Regression Model # ############################ # Simulate data set.seed(1) n <- 100 x <- runif(n) y <- rpois(n, exp(0.5 + x*0.4)) # Fit the model with default priors and mcmc parameters fout <- gblr(y ~ x, family = 'poisson', link = 'log') # Summary print(fout); summary(fout) # Plot plot(fout) # fitted values fitf <- fitted(fout)
############################ # Poisson Regression Model # ############################ # Simulate data set.seed(1) n <- 100 x <- runif(n) y <- rpois(n, exp(0.5 + x*0.4)) # Fit the model with default priors and mcmc parameters fout <- gblr(y ~ x, family = 'poisson', link = 'log') # Summary print(fout); summary(fout) # Plot plot(fout) # fitted values fitf <- fitted(fout)
This function fits a Bayesian generalized partial linear regression model to estimate shape-restricted functions using a spectral analysis of Gaussian process priors.
gbsar(formula, xmin, xmax, family, link, nbasis, nint, mcmc = list(), prior = list(), shape = c('Free','Increasing','Decreasing','IncreasingConvex','DecreasingConcave', 'IncreasingConcave','DecreasingConvex','IncreasingS','DecreasingS', 'IncreasingRotatedS','DecreasingRotatedS','InvertedU','Ushape'), marginal.likelihood = TRUE, algorithm = c('AM', 'KS'), verbose = FALSE)
gbsar(formula, xmin, xmax, family, link, nbasis, nint, mcmc = list(), prior = list(), shape = c('Free','Increasing','Decreasing','IncreasingConvex','DecreasingConcave', 'IncreasingConcave','DecreasingConvex','IncreasingS','DecreasingS', 'IncreasingRotatedS','DecreasingRotatedS','InvertedU','Ushape'), marginal.likelihood = TRUE, algorithm = c('AM', 'KS'), verbose = FALSE)
formula |
an object of class “ |
xmin |
a vector or scalar giving user-specific minimum values of x. The default values are minimum values of x. |
xmax |
a vector or scalar giving user-specific maximum values of x. The default values are maximum values of x. |
family |
a description of the error distribution to be used in the model: The family contains bernoulli (“bernoulli”), poisson (“poisson”), negative-binomial (“negative.binomial”), poisson-gamma mixture (“poisson.gamma”). |
link |
a description of the link function to be used in the model. |
nbasis |
number of cosine basis functions. |
nint |
number of grid points where the unknown function is evaluated for plotting. The default is 200. |
mcmc |
a list giving the MCMC parameters.
The list includes the following integers (with default values in parentheses):
|
prior |
a list giving the prior information. The list includes the following parameters
(default values specify the non-informative prior):
|
shape |
a vector giving types of shape restriction. |
marginal.likelihood |
a logical variable indicating whether the log marginal likelihood is calculated. The methods of Gelfand and Dey (1994) and Newton and Raftery (1994) are used. |
algorithm |
a description of the algorithm to be used in the fitting of the logistic model:
The algorithm contains the Gibbs sampler based on the Kolmogorov-Smirnov distribution ( |
verbose |
a logical variable. If |
This generic function fits a Bayesian generalized partial linear regression models for estimating shape-restricted functions using Gaussian process priors. For enforcing shape-restrictions, they assumed that the derivatives of the functions are squares of Gaussian processes.
Let and
be the response and the vector of parametric predictors, respectively.
Further, let
be the covariate related to the response through an unknown shape-restricted function.
The model for estimating shape-restricted functions is as follows.
where is a link function and
is an unknown nonlinear function of the scalar
.
The prior of function without shape restriction is:
where is a second-order Gaussian process with mean function equal to zero and covariance function
for
. The Gaussian process is expressed with
the spectral representation based on cosine basis functions:
The shape-restricted functions are modeled by assuming the th derivatives of
are squares of Gaussian processes:
where is the squish function. For monotonic, monotonic convex, and concave functions,
, while
for
S
and U
shaped functions, is defined by
For the spectral coefficients of functions without shape constraints, the following prior is used
(The intercept is included in ):
The priors for the spectral coefficients of shape restricted functions are:
To complete the model specification, the following prior is assumed for :
An object of class bsam
representing the Bayesian spectral analysis model fit.
Generic functions such as print
, fitted
and plot
have methods to show the results of the fit.
The MCMC samples of the parameters in the model are stored in the list mcmc.draws
,
the posterior samples of the fitted values are stored in the list fit.draws
, and
the MCMC samples for the log marginal likelihood are saved in the list loglik.draws
.
The output list also includes the following objects:
post.est |
posterior estimates for all parameters in the model. |
lmarg.gd |
log marginal likelihood using Gelfand-Dey method. |
lmarg.nr |
log marginal likelihood using Netwon-Raftery method, which is biased. |
family |
the family object used. |
link |
the link object used. |
call |
the matched call. |
mcmctime |
running time of Markov chain from |
Jo, S., Choi, T., Park, B. and Lenk, P. (2019). bsamGP: An R Package for Bayesian Spectral Analysis Models Using Gaussian Process Priors. Journal of Statistical Software, 90, 310-320.
Lenk, P. and Choi, T. (2017) Bayesian Analysis of Shape-Restricted Functions using Gaussian Process Priors. Statistica Sinica, 27, 43-69.
Roberts, G. O. and Rosenthal, J. S. (2009) Examples of Adaptive MCMC. Journal of Computational and Graphical Statistics, 18, 349-367.
Holmes, C. C. and Held, L. (2006) Bayesian Auxiliary Variables Models for Binary and Multinomial Regression. Bayesian Analysis, 1, 145-168.
Gelfand, A. E. and Dey, K. K. (1994) Bayesian model choice: asymptotics and exact calculations. Journal of the Royal Statistical Society. Series B - Statistical Methodology, 56, 501-514.
Newton, M. A. and Raftery, A. E. (1994) Approximate Bayesian inference with the weighted likelihood bootstrap (with discussion). Journal of the Royal Statistical Society. Series B - Statistical Methodology, 56, 3-48.
Albert, J. H. and Chib, S. (1993) Bayesian Analysis of Binary and Polychotomous Response Data. Journal of the American Statistical Association, 88, 669-679.
## Not run: ########################### # Probit Regression Model # ########################### # Simulate data set.seed(1) f <- function(x) 1.5 * sin(pi * x) n <- 1000 b <- c(1,-1) rho <- 0.7 u <- runif(n, min = -1, max = 1) x <- runif(n, min = -1, max = 1) w1 <- runif(n, min = -1, max = 1) w2 <- round(f(rho * x + (1 - rho) * u)) w <- cbind(w1, w2) y <- w %*% b + f(x) + rnorm(n) y <- (y > 0) # Number of cosine basis functions nbasis <- 50 # Fit the model with default priors and mcmc parameters fout <- gbsar(y ~ w1 + w2 + fs(x), family = "bernoulli", link = "probit", nbasis = nbasis, shape = 'Free') # Summary print(fout); summary(fout) # fitted values fit <- fitted(fout) # Plot plot(fit, ask = TRUE) ###################################### # Logistic Additive Regression Model # ###################################### # Wage-Union data data(wage.union); attach(wage.union) race[race==1 | race==2]=0 race[race==3]=1 y <- union w <- cbind(race,sex,south) x <- cbind(wage,education,age) # mcmc parameters mcmc <- list(nblow0 = 10000, nblow = 10000, nskip = 10, smcmc = 1000, ndisp = 1000, maxmodmet = 10) foutGBSAR <- gbsar(y ~ race + sex + south + fs(wage) + fs(education) + fs(age), family = 'bernoulli', link = 'logit', nbasis = 50, mcmc = mcmc, shape = c('Free','Decreasing','Increasing')) # fitted values fitGBSAR <- fitted(foutGBSAR) # Plot plot(fitGBSAR, ask = TRUE) ## End(Not run)
## Not run: ########################### # Probit Regression Model # ########################### # Simulate data set.seed(1) f <- function(x) 1.5 * sin(pi * x) n <- 1000 b <- c(1,-1) rho <- 0.7 u <- runif(n, min = -1, max = 1) x <- runif(n, min = -1, max = 1) w1 <- runif(n, min = -1, max = 1) w2 <- round(f(rho * x + (1 - rho) * u)) w <- cbind(w1, w2) y <- w %*% b + f(x) + rnorm(n) y <- (y > 0) # Number of cosine basis functions nbasis <- 50 # Fit the model with default priors and mcmc parameters fout <- gbsar(y ~ w1 + w2 + fs(x), family = "bernoulli", link = "probit", nbasis = nbasis, shape = 'Free') # Summary print(fout); summary(fout) # fitted values fit <- fitted(fout) # Plot plot(fit, ask = TRUE) ###################################### # Logistic Additive Regression Model # ###################################### # Wage-Union data data(wage.union); attach(wage.union) race[race==1 | race==2]=0 race[race==3]=1 y <- union w <- cbind(race,sex,south) x <- cbind(wage,education,age) # mcmc parameters mcmc <- list(nblow0 = 10000, nblow = 10000, nskip = 10, smcmc = 1000, ndisp = 1000, maxmodmet = 10) foutGBSAR <- gbsar(y ~ race + sex + south + fs(wage) + fs(education) + fs(age), family = 'bernoulli', link = 'logit', nbasis = 50, mcmc = mcmc, shape = c('Free','Decreasing','Increasing')) # fitted values fitGBSAR <- fitted(foutGBSAR) # Plot plot(fitGBSAR, ask = TRUE) ## End(Not run)
Trapezoidal rule is a technique for approximating the definite integral.
intgrat(f, delta)
intgrat(f, delta)
f |
Function values to be integrated. |
delta |
Spacing size. |
intgrat
returns the value of the intergral.
Simpson's rule is a method for numerical integration.
intsim(f, delta)
intsim(f, delta)
f |
Function values to be integrated. |
delta |
Spacing size. |
intsim
returns the value of the intergral.
The London.Mortality data consists of daily death occurrences from Jan. 1st, 1993 to Dec. 31st, 2006 and corresponding weather observations including temperature and humidity in London.
data(London.Mortality)
data(London.Mortality)
A data frame with 5113 observations on the following 7 variables.
date in YYYY-MM-DD.
Mean temperature.
Minimum dry-bulb temperature.
Maximum dry-bulb temperature.
Dew point.
Relative humidity.
the number of death occurences.
Office for National Statistics
British Atmospheric Data Centre
https://github.com/gasparrini/2015_gasparrini_Lancet_Rcodedata
Armstrong BG, Chalabi Z, Fenn B, Hajat S, Kovats S, Milojevic A, Wilkinson P (2011). Association of mortality with high temperatures in a temperate climate: England and Wales. Journal of Epidemiology & Community Health, 65(4), 340–345.
Gasparrini A, Armstrong B, Kovats S, Wilkinson P (2012). The effect of high temperatures on cause-specific mortality in England and Wales. Occupational and Environmental Medicine, 69(1), 56–61.
Gasparrini A, Guo Y, Hashizume M, Lavigne E, Zanobetti A, Schwartz J, Tobias A, Tong S, Rocklöv J, Forsberg B, et al.(2015). Mortality risk attributable to high and low ambient temperature: a multicountry observational study. The Lancet, 386(9991), 369-375.
## Not run: data(London.Mortality) ## End(Not run)
## Not run: data(London.Mortality) ## End(Not run)
This data set contains 314 observations on 14 variables.
data(plasma)
data(plasma)
age
Age (years).
sex
Sex (1=Male, 2=Female).
smoke
Smoking status (1=Never, 2=Former, 3=Current Smoker).
vmi
BMI values (weight/(height^2)).
vitas
Vitamin use (1=Yes,fairly often, 2=Yes, not often, 3=No).
calories
Number of calories consumed per day.
fat
Grams of fat consumed per day.
fiber
Grams of fiber consumed per day.
alcohol
Number of alcoholic drinks consumed per week.
cholesterol
Cholesterol consumed (mg per day).
beta diet
Dietary beta-carotene consumed (mcg per day).
reedit
Dietary retinol consumed (mcg per day).
betaplasma
Plasma beta-carotene (ng/ml).
retplasma
Plasma Retinol (ng/ml).
https://lib.stat.cmu.edu/datasets/Plasma_Retinol
Nierenberg, D. W., Stukel, T. A., Baron, J. A., Dain, B. J., and Greenberg, E. R. (1989). Determinants of plasma levels of beta-carotene and retinol. American Journal of Epidemiology, 130, 511-521.
Meyer, M. C., Hackstadt, A. J., and Hoeting, J. A. (2011). Bayesian estimation and inference for generalized partial linear models using shape-restricted splines. Journal of Nonparametric Statistics, 23(4), 867-884.
## Not run: data(plasma) ## End(Not run)
## Not run: data(plasma) ## End(Not run)
Plots the posterior samples for Bayesian linear models
## S3 method for class 'blm' plot(x, ...)
## S3 method for class 'blm' plot(x, ...)
x |
a |
... |
other options to pass to the plotting functions |
Returns a plot.
## See examples for blq and blr
## See examples for blq and blr
Plots the posterior samples for Bayesian semiparametric density estimation using a logistic Gaussian process.
## S3 method for class 'bsad' plot(x, ...)
## S3 method for class 'bsad' plot(x, ...)
x |
a |
... |
other options to pass to the plotting functions |
Returns a plot.
## See examples for bsad
## See examples for bsad
Plots the posterior samples for Bayesian spectral analysis models.
## S3 method for class 'bsam' plot(x, ...)
## S3 method for class 'bsam' plot(x, ...)
x |
a |
... |
other options to pass to the plotting functions |
Returns a plot.
## See examples for bsaq, bsaqdpm, bsar, and bsardpm
## See examples for bsaq, bsaqdpm, bsar, and bsardpm
Plots the posterior samples for Bayesian spectral analysis models with Dirichlet process mixture error.
## S3 method for class 'bsamdpm' plot(x, ...)
## S3 method for class 'bsamdpm' plot(x, ...)
x |
a |
... |
other options to pass to the plotting functions |
Returns a plot.
## See examples for bsaqdpm and bsardpm
## See examples for bsaqdpm and bsardpm
Plots the predictive density for Bayesian density estimation model using logistic Gaussian process
## S3 method for class 'fitted.bsad' plot(x, ggplot2, legend.position, nbins, ...)
## S3 method for class 'fitted.bsad' plot(x, ggplot2, legend.position, nbins, ...)
x |
a |
ggplot2 |
a logical variable. If |
legend.position |
the position of legends (“none”, “left”, “right”, “bottom”, “top”). It is used when |
nbins |
Number of bins used. Default is 30. |
... |
other options to pass to the plotting functions |
Returns a plot.
## See example for bsad
## See example for bsad
Plots the data and the fit for Bayesian spectral analysis models.
## S3 method for class 'fitted.bsam' plot(x, type, ask, ggplot2, legend.position, ...)
## S3 method for class 'fitted.bsam' plot(x, type, ask, ggplot2, legend.position, ...)
x |
a |
type |
the type of fitted plot. The default is on the scale of the response variable |
ask |
see. |
ggplot2 |
a logical variable. If |
legend.position |
the position of legends (“none”, “left”, “right”, “bottom”, “top”). It is used when |
... |
other options to pass to the plotting functions |
Returns a plot.
bsaq
, bsaqdpm
, bsar
, bsardpm
, fitted.bsam
## See examples for bsaq, bsaqdpm, bsar, and bsardpm
## See examples for bsaq, bsaqdpm, bsar, and bsardpm
Plots the data and the fit for Bayesian spectral analysis models with Dirichlet process mixture error.
## S3 method for class 'fitted.bsamdpm' plot(x, ask, ggplot2, legend.position, ...)
## S3 method for class 'fitted.bsamdpm' plot(x, ask, ggplot2, legend.position, ...)
x |
a |
ask |
see. |
ggplot2 |
a logical variable. If |
legend.position |
the position of legends (“none”, “left”, “right”, “bottom”, “top”). It is used when |
... |
other options to pass to the plotting functions |
Returns a plot.
bsaqdpm
, bsardpm
, fitted.bsamdpm
## See examples for bsaqdpm and bsardpm
## See examples for bsaqdpm and bsardpm
Computes predicted values of Bayesian linear models.
## S3 method for class 'blm' predict(object, newdata, alpha = 0.05, HPD = TRUE, ...)
## S3 method for class 'blm' predict(object, newdata, alpha = 0.05, HPD = TRUE, ...)
object |
a |
newdata |
an optional data matrix or vector with which to predict. If omitted, the fitted values are returned. |
alpha |
a numeric scalar in the interval (0,1) giving the |
HPD |
a logical variable indicating whether the |
... |
not used |
None.
A list containing posterior means and 95% credible intervals.
The output list includes the following objects:
wbeta |
posterior estimates for regression function. |
yhat |
posterior estimates for generalised regression function. |
Chen, M., Shao, Q. and Ibrahim, J. (2000) Monte Carlo Methods in Bayesian computation. Springer-Verlag New York, Inc.
## Not run: ##################### # Simulated example # ##################### # Simulate data set.seed(1) n <- 100 w <- runif(n) y <- 3 + 2*w + rnorm(n, sd = 0.8) # Fit the model with default priors and mcmc parameters fout <- blr(y ~ w) # Predict new <- rnorm(n) predict(fout, newdata = new) ## End(Not run)
## Not run: ##################### # Simulated example # ##################### # Simulate data set.seed(1) n <- 100 w <- runif(n) y <- 3 + 2*w + rnorm(n, sd = 0.8) # Fit the model with default priors and mcmc parameters fout <- blr(y ~ w) # Predict new <- rnorm(n) predict(fout, newdata = new) ## End(Not run)
Computes the predicted values of Bayesian spectral analysis models.
## S3 method for class 'bsam' predict(object, newp, newnp, alpha = 0.05, HPD = TRUE, type = "response", ...)
## S3 method for class 'bsam' predict(object, newp, newnp, alpha = 0.05, HPD = TRUE, type = "response", ...)
object |
a |
newp |
an optional data of parametric components with which to predict. If omitted, the fitted values are returned. |
newnp |
an optional data of nonparametric components with which to predict. If omitted, the fitted values are returned. |
alpha |
a numeric scalar in the interval (0,1) giving the |
HPD |
a logical variable indicating whether the |
type |
the type of prediction required. |
... |
not used |
None.
A list object of class predict.bsam
containing posterior means and % credible intervals.
The output list includes the following objects:
fxobs |
posterior estimates for unknown functions over observation. |
wbeta |
posterior estimates for parametric part. |
yhat |
posterior estimates for fitted values of either response or expectation of response.
For |
fxResid |
posterior estimates for fitted parametric residuals. Not applicable for |
## Not run: ########################################## # Increasing Convex to Concave (S-shape) # ########################################## # simulate data f <- function(x) 5*exp(-10*(x - 1)^4) + 5*x^2 set.seed(1) n <- 100 x <- runif(n) y <- f(x) + rnorm(n, sd = 1) # Number of cosine basis functions nbasis <- 50 # Fit the model with default priors and mcmc parameters fout <- bsar(y ~ fs(x), nbasis = nbasis, shape = 'IncreasingConvex', spm.adequacy = TRUE) # Prediction xnew <- runif(n) predict(fout, newnp = xnew) ## End(Not run)
## Not run: ########################################## # Increasing Convex to Concave (S-shape) # ########################################## # simulate data f <- function(x) 5*exp(-10*(x - 1)^4) + 5*x^2 set.seed(1) n <- 100 x <- runif(n) y <- f(x) + rnorm(n, sd = 1) # Number of cosine basis functions nbasis <- 50 # Fit the model with default priors and mcmc parameters fout <- bsar(y ~ fs(x), nbasis = nbasis, shape = 'IncreasingConvex', spm.adequacy = TRUE) # Prediction xnew <- runif(n) predict(fout, newnp = xnew) ## End(Not run)
Computes the predicted values of Bayesian spectral analysis models with Dirichlet process mixture errors.
## S3 method for class 'bsamdpm' predict(object, newp, newnp, alpha = 0.05, HPD = TRUE, ...)
## S3 method for class 'bsamdpm' predict(object, newp, newnp, alpha = 0.05, HPD = TRUE, ...)
object |
a |
newp |
an optional data of parametric components with which to predict. If omitted, the fitted values are returned. |
newnp |
an optional data of nonparametric components with which to predict. If omitted, the fitted values are returned. |
alpha |
a numeric scalar in the interval (0,1) giving the |
HPD |
a logical variable indicating whether the |
... |
not used |
None.
A list object of class predict.bsamdpm
containing posterior means and % credible intervals.
The output list includes the following objects:
fxobs |
posterior estimates for unknown functions over observation. |
wbeta |
posterior estimates for parametric part. |
yhat |
posterior estimates for fitted values of response. |
## Not run: ##################### # Increasing-convex # ##################### # Simulate data set.seed(1) n <- 200 x <- runif(n) e <- c(rnorm(n/2, sd = 0.5), rnorm(n/2, sd = 3)) y <- exp(6*x - 3) + e # Number of cosine basis functions nbasis <- 50 # Fit the model with default priors and mcmc parameters fout <- bsardpm(y ~ fs(x), nbasis = nbasis, shape = 'IncreasingConvex') # Prediction xnew <- runif(n) predict(fout, newnp = xnew) ## End(Not run)
## Not run: ##################### # Increasing-convex # ##################### # Simulate data set.seed(1) n <- 200 x <- runif(n) e <- c(rnorm(n/2, sd = 0.5), rnorm(n/2, sd = 3)) y <- exp(6*x - 3) + e # Number of cosine basis functions nbasis <- 50 # Fit the model with default priors and mcmc parameters fout <- bsardpm(y ~ fs(x), nbasis = nbasis, shape = 'IncreasingConvex') # Prediction xnew <- runif(n) predict(fout, newnp = xnew) ## End(Not run)
Density for and random values from a three-parameter asymmetric Laplace distribution.
rald(n, location=0, scale=1, p=0.5)
rald(n, location=0, scale=1, p=0.5)
n |
Number of random values to be generated. |
location |
Location parameter. |
scale |
Scale parameter. |
p |
Skewness parameter. |
This generic function generates a random variable from an asymmetric Laplace distribution (ALD). The ALD has the following probability density function:
where is the skew parameter,
is the scale parameter,
is the location parameter, and
is the indication function. The range of
is
.
rald
gives out a vector of random numbers generated by
the asymmetric Laplace distribution.
Koenker, R. and Machado, J. (1999). Goodness of fit and related inference processes for quantile regression. Journal of the American Statistical Association, 94(3), 1296-1309.
Yu, K. and Zhang, J. (2005). A Three-parameter asymmetric Laplace distribution and its extension. Communications in Statistics - Theory and Methods, 34, 1867-1879.
This data set contains 108 observations on 6 variables.
data(traffic)
data(traffic)
ln_number
logarithm of the number of monthly automobile accidents in the state of Michigan.
month
months from January 1st, 1979 to Decembe 31st, 1987.
ln_unemp
logarithm of unemployment rate
spring
indicator for spring season.
summer
indicator for summer season.
fall
indicator for fall season.
Lenk (1999) Bayesian inference for semiparametric regression using a Fourier representation. Journal of the Royal Statistical Society: Series B, 61(4), 863-879.
## Not run: data(traffic) pairs(traffic) ## End(Not run)
## Not run: data(traffic) pairs(traffic) ## End(Not run)
This data set contains 534 observations on 11 variables.
data(wage.union)
data(wage.union)
education
number of years of education.
south
indicator of living in southern region of U.S.A.
sex
gender indicator: 0=male,1=female.
experience
number of years of work experience.
union
indicator of trade union membership: 0=non-member, 1=member.
wage
wages in dollars per hour.
age
age in years.
race
1=black, 2=Hispanic, 3=white.
occupation
1=management, 2=sales, 3=clerical, 4=service, 5=professional, 6=other.
sector
0=other, 1=manufacturing, 2=construction.
married
indicator of being married: 0=unmarried, 1=married.
Berndt, E.R. (1991) The Practice of Econometrics. New York: Addison-Wesley.
Ruppert, D., Wand, M.P. and Carroll, R.J. (2003) Semiparametric Regression. Cambridge University Press.
## Not run: data(wage.union) pairs(wage.union) ## End(Not run)
## Not run: data(wage.union) pairs(wage.union) ## End(Not run)