Title: | Fit Multivariate Response Generalized Additive Models using Hamiltonian Monte Carlo |
---|---|
Description: | The 'bayesGAM' package is designed to provide a user friendly option to fit univariate and multivariate response Generalized Additive Models (GAM) using Hamiltonian Monte Carlo (HMC) with few technical burdens. The functions in this package use 'rstan' (Stan Development Team 2020) to call 'Stan' routines that run the HMC simulations. The 'Stan' code for these models is already pre-compiled for the user. The programming formulation for models in 'bayesGAM' is designed to be familiar to analysts who fit statistical models in 'R'. Carpenter, B., Gelman, A., Hoffman, M. D., Lee, D., Goodrich, B., Betancourt, M., ... & Riddell, A. (2017). Stan: A probabilistic programming language. Journal of statistical software, 76(1). Stan Development Team. 2018. RStan: the R interface to Stan. R package version 2.17.3. <https://mc-stan.org/> Neal, Radford (2011) "Handbook of Markov Chain Monte Carlo" ISBN: 978-1420079418. Betancourt, Michael, and Mark Girolami. "Hamiltonian Monte Carlo for hierarchical models." Current trends in Bayesian methodology with applications 79.30 (2015): 2-4. Thomas, S., Tu, W. (2020) "Learning Hamiltonian Monte Carlo in R" <arXiv:2006.16194>, Gelman, A., Carlin, J. B., Stern, H. S., Dunson, D. B., Vehtari, A., & Rubin, D. B. (2013) "Bayesian Data Analysis" ISBN: 978-1439840955, Agresti, Alan (2015) "Foundations of Linear and Generalized Linear Models ISBN: 978-1118730034, Pinheiro, J., Bates, D. (2006) "Mixed-effects Models in S and S-Plus" ISBN: 978-1441903174. Ruppert, D., Wand, M. P., & Carroll, R. J. (2003). Semiparametric regression (No. 12). Cambridge university press. ISBN: 978-0521785167. |
Authors: | Samuel Thomas [cre, aut], Wanzhu Tu [ctb], Trustees of Columbia University (R/rstanMethods.R) [cph] |
Maintainer: | Samuel Thomas <[email protected]> |
License: | GPL-3 |
Version: | 0.0.2 |
Built: | 2024-12-04 06:55:34 UTC |
Source: | CRAN |
Fit Bayesian multivariate generalized additive models using Stan
Stan Development Team (2020). RStan: the R interface to Stan. R package version 2.21.1. https://mc-stan.org
bayesGAM
fits a variety of regression models using Hamiltonian Monte CarloBased on glm
. bayesGAM
is used to fit a variety of statistical models, including linear models, generalized lienar models, mixed effect models with random intercept, and semiparametric regression models.
bayesGAM( formula, random = NULL, family = gaussian, data, offset, beta = list(), eps = list(), lambda = list(), a = list(), spcontrol = list(qr = TRUE, mvindep = FALSE, ...), store_plot_data = FALSE, method = "bayesGAMfit", ... )
bayesGAM( formula, random = NULL, family = gaussian, data, offset, beta = list(), eps = list(), lambda = list(), a = list(), spcontrol = list(qr = TRUE, mvindep = FALSE, ...), store_plot_data = FALSE, method = "bayesGAMfit", ... )
formula |
a |
random |
(optional) specify a random intercept in the form '~var' |
family |
distribution and link function for the model |
data |
(optional) data frame containing the variables in the model. |
offset |
Same as |
beta |
(optional) list of priors for the fixed effects parameters. Sensible priors are selected as a default. |
eps |
(optional) list of priors for the error term in linear regression. Sensible priors are selecteda as a default. |
lambda |
(optional) list of priors for random effects variance parameters. Sensible priors are selected as a default. |
a |
(optional) list of priors for the off diagonal of the LDLT decomposed covariance matrix for multivariate response models. Vague normal priors are used as a default. |
spcontrol |
a list of control parameters for fitting the model in STAN. See 'details' |
store_plot_data |
a logical indicator for storing the plot data frame after simulation. Defaults to |
method |
default currently set to 'bayesGAMfit'. |
... |
Arguments passed to |
Similar to glm
, models are typically specified by formula.
The formula typically takes the form response ~ terms
, where the response is numeric
and terms specify the linear predictor for the response. The terms may be numeric variables or factors.
The link function for the Generalized Linear Model is specified with a family
object.
Currently, this package supports gaussian, binomial, and poisson families with all available link functions.
The list spcontrol
currently supports additional parameters to facilitate fitting models.
qr
is a logical indicator specifying whether the design matrix should be transformed via QR decomposition prior to HMC sampling.
QR decomposition often improves the efficiency with which HMC samples, as the MCMC chain navigates an orthogonal
space more easily than highly correlated parameters.
mvindep
is a logical indicator for multivariate response models with random intercepts. This indicates whether
the multivariate responses should be considered independent. Defaults to FALSE
An object of class bayesGAMfit
. Includes slots:
results
: stanfit
object returned by rstan::sampling
model
: glmModel
object
offset
: offset vector from the input parameter
spcontrol
: list of control parameters from input
Hastie, T. J. (1992) Generalized additive models. Chapter 7 of Statistical Models in S eds J. M. Chambers and T. J. Hastie, Wadsworth & Brooks/Cole.
Dobson, A. J. (1990) An Introduction to Generalized Linear Models. London: Chapman and Hall.
## Dobson (1990) Page 93: Randomized Controlled Trial : counts <- c(18,17,15,20,10,20,25,13,12) outcome <- gl(3,1,9) treatment <- gl(3,3) fpois<- bayesGAM(counts ~ outcome + treatment, family = poisson(), spcontrol = list(qr = TRUE)) summary(fpois)
## Dobson (1990) Page 93: Randomized Controlled Trial : counts <- c(18,17,15,20,10,20,25,13,12) outcome <- gl(3,1,9) treatment <- gl(3,3) fpois<- bayesGAM(counts ~ outcome + treatment, family = poisson(), spcontrol = list(qr = TRUE)) summary(fpois)
rstan
as well as the design matrices and other data for the model.Returns object generated from model fit by bayesGAM
## S4 method for signature 'bayesGAMfit' show(object)
## S4 method for signature 'bayesGAMfit' show(object)
object |
Object of type |
results
Object of type stanfit
returned from calling rstan::sampling
model
Object of custom type glmModel
with the data and input parameters passed to rstan
offset
Optionally numeric offset for the generalized additive model
spcontrol
List of control parameters for bayesGAMfit
mcmcres
Matrix of MCMC results for all chains, if plot data is stored
pdata
Dataframe for default plot method, if plot data is stored.
Data from 200 subjects
bloodpressure
bloodpressure
A data frame with 2438 rows and 13 variables:
Subject identification number
birth weight (lbs)
current weight (lbs)
current height (cm)
current body mass index
current age (yrs)
diastolic blood pressure
systolic blood pressure
indicator of sex male
indicator of race black
indicator of race white
indicator that either parent had high blood pressure
indicator that either parent had diabetes
Data provided by Wanzhu Tu, Indiana University School of Medicine
Tu, W., Eckert, G. J., DiMeglio, L. A., Yu, Z., Jung, J., and Pratt, J. H. (2011). Intensified effect of adiposity on blood pressure in overweight and obese children. Hypertension, 58(5), 818-824.
Method for bayesGAMfit
objects. Extracts the specified quantile of the posterior.
The user may specify all or some of the parameters ,
,
,
,
,
.
## S4 method for signature 'bayesGAMfit' coefficients( object, params = c("beta", "eps", "lambda", "u", "sigma", "a"), FUN = median ) ## S4 method for signature 'bayesGAMfit' coef( object, params = c("beta", "eps", "lambda", "u", "sigma", "a"), FUN = median )
## S4 method for signature 'bayesGAMfit' coefficients( object, params = c("beta", "eps", "lambda", "u", "sigma", "a"), FUN = median ) ## S4 method for signature 'bayesGAMfit' coef( object, params = c("beta", "eps", "lambda", "u", "sigma", "a"), FUN = median )
object |
an object of class |
params |
character vector of the names of parameters to return
|
FUN |
function from which to estimate coefficients. Default is |
Numeric vector of parameter point estimates based on the given prob
, with a default of the median estimate.
require(stats); require(graphics) f <- bayesGAM(weight ~ np(height), data = women, family = gaussian, iter = 500, chains = 1) coef(f, params=c("beta", "eps"))
require(stats); require(graphics) f <- bayesGAM(weight ~ np(height), data = women, family = gaussian, iter = 500, chains = 1) coef(f, params=c("beta", "eps"))
create_bivariate_design
accepts two numeric vectors of equal length as inputs. From these inputs, a bivariate smoothing design matrix is produced using thin plate splines.
create_bivariate_design(X1, X2, num_knots = NULL, knots = NULL)
create_bivariate_design(X1, X2, num_knots = NULL, knots = NULL)
X1 |
numeric vector for first variable |
X2 |
numeric vector for second variable |
num_knots |
optional: number of knots |
knots |
optional: matrix of knot locations for bivariate smoothing |
list containing the design matrix Z
and matrix of knots
Ruppert, David, Matt P. Wand, and Raymond J. Carroll. Semiparametric Regression. No. 12. Cambridge university press, 2003. Section 13.5
Matt Wand (2018). SemiPar: Semiparametric Regression. R package version 1.0-4.2.
x1 <- rnorm(100) x2 <- rnorm(100) res <- create_bivariate_design(x1, x2) res$knots dim(res$Z)
x1 <- rnorm(100) x2 <- rnorm(100) res <- create_bivariate_design(x1, x2) res$knots dim(res$Z)
bayesGAM
Convenience function for extracting the pointwise log-likelihood matrix
or array from a model fit by bayesGAM
. Calls the extract_log_lik
method
from the loo
package
extract_log_lik_bgam(object, ...) ## S4 method for signature 'bayesGAMfit' extract_log_lik_bgam(object, ...)
extract_log_lik_bgam(object, ...) ## S4 method for signature 'bayesGAMfit' extract_log_lik_bgam(object, ...)
object |
Object of type |
... |
Additional parameters to pass to |
A matrix with the extracted log likelihood values post-warmup
Stan Development Team (2017). The Stan C++ Library, Version 2.16.0. https://mc-stan.org/
Stan Development Team (2017). RStan: the R interface to Stan, Version 2.16.1. https://mc-stan.org/
Vehtari A, Gabry J, Magnusson M, Yao Y, Gelman A (2019). “loo: Efficient leave-one-out cross-validation and WAIC for Bayesian models.” R package version 2.2.0, <URL: https://mc-stan.org/loo>.
Vehtari A, Gelman A, Gabry J (2017). “Practical Bayesian model evaluation using leave-one-out cross-validation and WAIC.” Statistics and Computing, 27, 1413-1432. doi:10.1007/s11222-016-9696-4 (URL: https://doi.org/10.1007/s11222-016-9696-4).
f <- bayesGAM(weight ~ np(height), data = women, family = gaussian, iter=500, chains = 1) ll <- extract_log_lik_bgam(f)
f <- bayesGAM(weight ~ np(height), data = women, family = gaussian, iter=500, chains = 1) ll <- extract_log_lik_bgam(f)
bayesGAM
Method for bayesGAMfit
objects. Extracts the fitted values based on a specified quantile for the posterior distribution. The median is the default.
## S4 method for signature 'bayesGAMfit' fitted(object, ...)
## S4 method for signature 'bayesGAMfit' fitted(object, ...)
object |
an object of class |
... |
additional arguments to pass to |
Numeric vector of fitted values
require(stats); require(graphics) f <- bayesGAM(weight ~ np(height), data = women, family = gaussian, iter = 500, chains = 1) plot(fitted(f), women$weight, type='o', xlab="fitted", ylab="actual")
require(stats); require(graphics) f <- bayesGAM(weight ~ np(height), data = women, family = gaussian, iter = 500, chains = 1) plot(fitted(f), women$weight, type='o', xlab="fitted", ylab="actual")
bayesGAMfit
objectContains the design matrices produced for model fitting. The fixed effects design matrix X
or random effects design matrix Z
can be specified.
getDesign(object, ...) ## S4 method for signature 'bayesGAMfit' getDesign(object, type = "X") ## S4 method for signature 'glmModel' getDesign(object, type = "X")
getDesign(object, ...) ## S4 method for signature 'bayesGAMfit' getDesign(object, type = "X") ## S4 method for signature 'glmModel' getDesign(object, type = "X")
object |
Object of type |
... |
Additional arguments for |
type |
Character for fixed effect design matrix |
Contents of stanfit
results
require(stats); require(graphics) f <- bayesGAM(weight ~ np(height), data = women, family = gaussian, iter = 500, chains = 1) getDesign(f, "Z")
require(stats); require(graphics) f <- bayesGAM(weight ~ np(height), data = women, family = gaussian, iter = 500, chains = 1) getDesign(f, "Z")
Stan
model in bayesGAM
Contains the objects and parameters passed to Stan in object of type glmModel
, contained in object type bayesGAMfit
getModelSlots(object, ...) ## S4 method for signature 'bayesGAMfit' getModelSlots(object, name = "X")
getModelSlots(object, ...) ## S4 method for signature 'bayesGAMfit' getModelSlots(object, name = "X")
object |
Object of type |
... |
Additional arguments for |
name |
Character name of slot in
|
Contents of slot in glmModel
require(stats); require(graphics) f <- bayesGAM(weight ~ np(height), data = women, family = gaussian, iter = 500, chains = 1) getModelSlots(f, "X")
require(stats); require(graphics) f <- bayesGAM(weight ~ np(height), data = women, family = gaussian, iter = 500, chains = 1) getModelSlots(f, "X")
bayesGAMfit
Returns an array of the posterior simulation from Stan
. Optionally, may return a subsample from the full MCMC simulation.
getSamples(object, ...) ## S4 method for signature 'bayesGAMfit' getSamples(object, nsamp = NULL, seednum = NULL, ...) ## S4 method for signature 'stanfit' getSamples(object, nsamp = 1000, seednum = NULL, results = NULL, ...) ## S4 method for signature 'glmModel' getSamples(object, nsamp = NULL, seednum = NULL, results = NULL, ...)
getSamples(object, ...) ## S4 method for signature 'bayesGAMfit' getSamples(object, nsamp = NULL, seednum = NULL, ...) ## S4 method for signature 'stanfit' getSamples(object, nsamp = 1000, seednum = NULL, results = NULL, ...) ## S4 method for signature 'glmModel' getSamples(object, nsamp = NULL, seednum = NULL, results = NULL, ...)
object |
model object of class |
... |
Additional parameters passed to |
nsamp |
Optional number of samples to return |
seednum |
Optional integer for seed number when selecting a random sample |
results |
Matrix of HMC posterior samples |
array of the posterior simulation, or subsample of the array
NA
require(stats); require(graphics) f <- bayesGAM(weight ~ np(height), data = women, family = gaussian, iter = 500, chains = 1) allres <- getSamples(f)
require(stats); require(graphics) f <- bayesGAM(weight ~ np(height), data = women, family = gaussian, iter = 500, chains = 1) allres <- getSamples(f)
stanfit
object generated by rstan
Contains the full content of the stanfit
object
getStanResults(object) ## S4 method for signature 'bayesGAMfit' getStanResults(object)
getStanResults(object) ## S4 method for signature 'bayesGAMfit' getStanResults(object)
object |
Object of type |
Contents of stanfit
results
require(stats); require(graphics) f <- bayesGAM(weight ~ np(height), data = women, family = gaussian, iter = 500, chains = 1) sres <- getStanResults(f) plot(sres) # rstan method
require(stats); require(graphics) f <- bayesGAM(weight ~ np(height), data = women, family = gaussian, iter = 500, chains = 1) sres <- getStanResults(f) plot(sres) # rstan method
Creates lagged variables for use with bayesGAM
, including the functionality
to create lags for each specified subject if desired. The input data must be pre-
sorted according by time, and within each subject id if specified.
L(x, k = 1, id = NULL)
L(x, k = 1, id = NULL)
x |
numeric vector |
k |
integer vector of lagged variables to create |
id |
optional identification number for each subject |
numeric vector or matrix of the lagged variable(s)
Zeileis A (2019). dynlm: Dynamic Linear Regression. R package version 0.3-6
x <- rnorm(20) id <- rep(1:4, each=5) L(x, 1:2, id) # autoregressive ar.ols(lh, demean = FALSE, intercept=TRUE, order=1) f <- bayesGAM(lh ~ L(lh), family=gaussian) coef(f)
x <- rnorm(20) id <- rep(1:4, each=5) L(x, 1:2, id) # autoregressive ar.ols(lh, demean = FALSE, intercept=TRUE, order=1) f <- bayesGAM(lh ~ L(lh), family=gaussian) coef(f)
loo
package to perform efficient approximate leave-one-out cross-validation on models fit with bayesGAM
Computes PSIS-LOO CV, efficient approximate leave-one-out (LOO) cross-validation for
Bayesian models using Pareto smoothed importance sampling (PSIS). This calls the implementation
from the loo
package of the methods described in Vehtari, Gelman, and Gabry (2017a, 2017b).
loo_bgam(object, ...) ## S4 method for signature 'bayesGAMfit' loo_bgam(object, ...) ## S4 method for signature 'array' loo_bgam(object, ...)
loo_bgam(object, ...) ## S4 method for signature 'bayesGAMfit' loo_bgam(object, ...) ## S4 method for signature 'array' loo_bgam(object, ...)
object |
Object of type |
... |
Additional parameters to pass to pass to |
a named list of class c("psis_loo", "loo")
estimates
A matrix with two columns (Estimate
, SE
) and three rows
(elpd_loo
, p_loo
, looic
). This
contains point estimates and standard errors of the expected log pointwise
predictive density (elpd_loo
), the effective number of parameters
(p_loo
) and the LOO information criterion looic
(which is
just -2 * elpd_loo
, i.e., converted to deviance scale).
pointwise
A matrix with five columns (and number of rows equal to the number of
observations) containing the pointwise contributions of the measures
(elpd_loo
, mcse_elpd_loo
, p_loo
, looic
, influence_pareto_k
).
in addition to the three measures in estimates
, we also report
pointwise values of the Monte Carlo standard error of elpd_loo
(mcse_elpd_loo
), and statistics describing the influence of
each observation on the posterior distribution (influence_pareto_k
).
These are the estimates of the shape parameter of the
generalized Pareto fit to the importance ratios for each leave-one-out
distribution. See the pareto-k-diagnostic page for details.
diagnostics
A named list containing two vectors:
pareto_k
: Importance sampling reliability diagnostics. By default,
these are equal to the influence_pareto_k
in pointwise
.
Some algorithms can improve importance sampling reliability and
modify these diagnostics. See the pareto-k-diagnostic page for details.
n_eff
: PSIS effective sample size estimates.
psis_object
This component will be NULL
unless the save_psis
argument is set to
TRUE
when calling loo()
. In that case psis_object
will be the object
of class "psis"
that is created when the loo()
function calls psis()
internally to do the PSIS procedure.
Vehtari, A., Gelman, A., and Gabry, J. (2017a). Practical Bayesian model evaluation using leave-one-out cross-validation and WAIC. Statistics and Computing. 27(5), 1413–1432. doi:10.1007/s11222-016-9696-4 (journal version, preprint arXiv:1507.04544).
Vehtari, A., Gelman, A., and Gabry, J. (2017b). Pareto smoothed importance sampling. preprint arXiv:1507.02646
Vehtari A, Gabry J, Magnusson M, Yao Y, Gelman A (2019). “loo: Efficient leave-one-out cross-validation and WAIC for Bayesian models.” R package version 2.2.0, <URL: https://mc-stan.org/loo>.
f <- bayesGAM(weight ~ np(height), data = women, family = gaussian, iter=500, chains = 1) loo_bgam(f)
f <- bayesGAM(weight ~ np(height), data = women, family = gaussian, iter=500, chains = 1) loo_bgam(f)
loo
package to compare models fit by bayesGAMfit
Compares fitted models based on ELPD, the expected log pointwise predictive density for a new dataset.
loo_compare_bgam(object, ...) ## S4 method for signature 'bayesGAMfit' loo_compare_bgam(object, ...)
loo_compare_bgam(object, ...) ## S4 method for signature 'bayesGAMfit' loo_compare_bgam(object, ...)
object |
Object of type |
... |
Additional objects of type |
a matrix with class compare.loo
that has its own print method from the loo
package
Watanabe, S. (2010). Asymptotic equivalence of Bayes cross validation and widely application information criterion in singular learning theory. Journal of Machine Learning Research 11, 3571-3594.
Vehtari, A., Gelman, A., and Gabry, J. (2017a). Practical Bayesian model evaluation using leave-one-out cross-validation and WAIC. Statistics and Computing. 27(5), 1413–1432. doi:10.1007/s11222-016-9696-4 (journal version, preprint arXiv:1507.04544).
Vehtari, A., Gelman, A., and Gabry, J. (2017b). Pareto smoothed importance sampling. preprint arXiv:1507.02646
Vehtari A, Gabry J, Magnusson M, Yao Y, Gelman A (2019). “loo: Efficient leave-one-out cross-validation and WAIC for Bayesian models.” R package version 2.2.0, <URL: https://mc-stan.org/loo>.
Gabry, J. , Simpson, D. , Vehtari, A. , Betancourt, M. and Gelman, A. (2019), Visualization in Bayesian workflow. J. R. Stat. Soc. A, 182: 389-402. doi:10.1111/rssa.12378
f1 <- bayesGAM(weight ~ height, data = women, family = gaussian, iter=500, chains = 1) f2 <- bayesGAM(weight ~ np(height), data=women, family = gaussian, iter=500, chains = 1) loo_compare_bgam(f1, f2)
f1 <- bayesGAM(weight ~ height, data = women, family = gaussian, iter=500, chains = 1) f2 <- bayesGAM(weight ~ np(height), data=women, family = gaussian, iter=500, chains = 1) loo_compare_bgam(f1, f2)
bayesplot
packagePlots of Rhat statistics, ratios of effective sample size to total sample size, and autocorrelation of MCMC draws.
mcmc_intervals(object, ...) ## S4 method for signature 'bayesGAMfit' mcmc_intervals( object, regex_pars = c("^beta", "^lambda", "^eps", "^a", "^sigma_u_correlation"), ... ) mcmc_areas(object, ...) ## S4 method for signature 'bayesGAMfit' mcmc_areas( object, regex_pars = c("^beta", "^lambda", "^eps", "^a", "^sigma_u_correlation"), ... ) mcmc_hist(object, ...) ## S4 method for signature 'bayesGAMfit' mcmc_hist( object, regex_pars = c("^beta", "^lambda", "^eps", "^a", "^sigma_u_correlation"), ... ) mcmc_hist_by_chain(object, ...) ## S4 method for signature 'bayesGAMfit' mcmc_hist_by_chain( object, regex_pars = c("^beta", "^lambda", "^eps", "^a", "^sigma_u_correlation"), ... ) mcmc_dens(object, ...) ## S4 method for signature 'bayesGAMfit' mcmc_dens( object, regex_pars = c("^beta", "^lambda", "^eps", "^a", "^sigma_u_correlation"), ... ) mcmc_scatter(object, ...) ## S4 method for signature 'bayesGAMfit' mcmc_scatter( object, regex_pars = c("^beta", "^lambda", "^eps", "^a", "^sigma_u_correlation"), ... ) mcmc_hex(object, ...) ## S4 method for signature 'bayesGAMfit' mcmc_hex( object, regex_pars = c("^beta", "^lambda", "^eps", "^a", "^sigma_u_correlation"), ... ) mcmc_pairs(object, ...) ## S4 method for signature 'bayesGAMfit' mcmc_pairs( object, regex_pars = c("^beta", "^lambda", "^eps", "^a", "^sigma_u_correlation"), ... ) mcmc_acf(object, ...) ## S4 method for signature 'bayesGAMfit' mcmc_acf( object, regex_pars = c("^beta", "^lambda", "^eps", "^a", "^sigma_u_correlation"), ... ) mcmc_acf_bar(object, ...) ## S4 method for signature 'bayesGAMfit' mcmc_acf_bar( object, regex_pars = c("^beta", "^lambda", "^eps", "^a", "^sigma_u_correlation"), ... ) mcmc_trace(object, ...) ## S4 method for signature 'bayesGAMfit' mcmc_trace( object, regex_pars = c("^beta", "^lambda", "^eps", "^a", "^sigma_u_correlation"), ... ) mcmc_rhat(object, ...) ## S4 method for signature 'bayesGAMfit' mcmc_rhat( object, regex_pars = c("^beta", "^lambda", "^eps", "^a", "^sigma_u_correlation"), ... ) mcmc_rhat_hist(object, ...) ## S4 method for signature 'bayesGAMfit' mcmc_rhat_hist( object, regex_pars = c("^beta", "^lambda", "^eps", "^a", "^sigma_u_correlation"), ... ) mcmc_rhat_data(object, ...) ## S4 method for signature 'bayesGAMfit' mcmc_rhat_data( object, regex_pars = c("^beta", "^lambda", "^eps", "^a", "^sigma_u_correlation"), ... ) mcmc_neff(object, ...) ## S4 method for signature 'bayesGAMfit' mcmc_neff( object, regex_pars = c("^beta", "^lambda", "^eps", "^a", "^sigma_u_correlation"), ... ) mcmc_neff_hist(object, ...) ## S4 method for signature 'bayesGAMfit' mcmc_neff_hist( object, regex_pars = c("^beta", "^lambda", "^eps", "^a", "^sigma_u_correlation"), ... ) mcmc_neff_data(object, ...) ## S4 method for signature 'bayesGAMfit' mcmc_neff_data( object, regex_pars = c("^beta", "^lambda", "^eps", "^a", "^sigma_u_correlation"), ... ) mcmc_violin(object, ...) ## S4 method for signature 'bayesGAMfit' mcmc_violin( object, regex_pars = c("^beta", "^lambda", "^eps", "^a", "^sigma_u_correlation"), ... )
mcmc_intervals(object, ...) ## S4 method for signature 'bayesGAMfit' mcmc_intervals( object, regex_pars = c("^beta", "^lambda", "^eps", "^a", "^sigma_u_correlation"), ... ) mcmc_areas(object, ...) ## S4 method for signature 'bayesGAMfit' mcmc_areas( object, regex_pars = c("^beta", "^lambda", "^eps", "^a", "^sigma_u_correlation"), ... ) mcmc_hist(object, ...) ## S4 method for signature 'bayesGAMfit' mcmc_hist( object, regex_pars = c("^beta", "^lambda", "^eps", "^a", "^sigma_u_correlation"), ... ) mcmc_hist_by_chain(object, ...) ## S4 method for signature 'bayesGAMfit' mcmc_hist_by_chain( object, regex_pars = c("^beta", "^lambda", "^eps", "^a", "^sigma_u_correlation"), ... ) mcmc_dens(object, ...) ## S4 method for signature 'bayesGAMfit' mcmc_dens( object, regex_pars = c("^beta", "^lambda", "^eps", "^a", "^sigma_u_correlation"), ... ) mcmc_scatter(object, ...) ## S4 method for signature 'bayesGAMfit' mcmc_scatter( object, regex_pars = c("^beta", "^lambda", "^eps", "^a", "^sigma_u_correlation"), ... ) mcmc_hex(object, ...) ## S4 method for signature 'bayesGAMfit' mcmc_hex( object, regex_pars = c("^beta", "^lambda", "^eps", "^a", "^sigma_u_correlation"), ... ) mcmc_pairs(object, ...) ## S4 method for signature 'bayesGAMfit' mcmc_pairs( object, regex_pars = c("^beta", "^lambda", "^eps", "^a", "^sigma_u_correlation"), ... ) mcmc_acf(object, ...) ## S4 method for signature 'bayesGAMfit' mcmc_acf( object, regex_pars = c("^beta", "^lambda", "^eps", "^a", "^sigma_u_correlation"), ... ) mcmc_acf_bar(object, ...) ## S4 method for signature 'bayesGAMfit' mcmc_acf_bar( object, regex_pars = c("^beta", "^lambda", "^eps", "^a", "^sigma_u_correlation"), ... ) mcmc_trace(object, ...) ## S4 method for signature 'bayesGAMfit' mcmc_trace( object, regex_pars = c("^beta", "^lambda", "^eps", "^a", "^sigma_u_correlation"), ... ) mcmc_rhat(object, ...) ## S4 method for signature 'bayesGAMfit' mcmc_rhat( object, regex_pars = c("^beta", "^lambda", "^eps", "^a", "^sigma_u_correlation"), ... ) mcmc_rhat_hist(object, ...) ## S4 method for signature 'bayesGAMfit' mcmc_rhat_hist( object, regex_pars = c("^beta", "^lambda", "^eps", "^a", "^sigma_u_correlation"), ... ) mcmc_rhat_data(object, ...) ## S4 method for signature 'bayesGAMfit' mcmc_rhat_data( object, regex_pars = c("^beta", "^lambda", "^eps", "^a", "^sigma_u_correlation"), ... ) mcmc_neff(object, ...) ## S4 method for signature 'bayesGAMfit' mcmc_neff( object, regex_pars = c("^beta", "^lambda", "^eps", "^a", "^sigma_u_correlation"), ... ) mcmc_neff_hist(object, ...) ## S4 method for signature 'bayesGAMfit' mcmc_neff_hist( object, regex_pars = c("^beta", "^lambda", "^eps", "^a", "^sigma_u_correlation"), ... ) mcmc_neff_data(object, ...) ## S4 method for signature 'bayesGAMfit' mcmc_neff_data( object, regex_pars = c("^beta", "^lambda", "^eps", "^a", "^sigma_u_correlation"), ... ) mcmc_violin(object, ...) ## S4 method for signature 'bayesGAMfit' mcmc_violin( object, regex_pars = c("^beta", "^lambda", "^eps", "^a", "^sigma_u_correlation"), ... )
object |
an object of class |
... |
optional additional arguments to pass to the |
regex_pars |
character vector of regular expressions of variable names to plot |
These functions call various plotting functions from the bayesplot
package, which returns a list including ggplot2
objects.
bayesplot
package documentationmcmc_hist(object, ...)
Default plot called by plot
function. Histograms of posterior draws with all chains merged.
mcmc_dens(object, ...)
Kernel density plots of posterior draws with all chains merged.
mcmc_hist_by_chain(object, ...)
Histograms of posterior draws with chains separated via faceting.
mcmc_dens_overlay(object, ...)
Kernel density plots of posterior draws with chains separated but
overlaid on a single plot.
mcmc_violin(object, ...)
The density estimate of each chain is plotted as a violin with
horizontal lines at notable quantiles.
mcmc_dens_chains(object, ...)
Ridgeline kernel density plots of posterior draws with chains separated
but overlaid on a single plot. In mcmc_dens_overlay()
parameters
appear in separate facets; in mcmc_dens_chains()
they appear in the
same panel and can overlap vertically.
mcmc_intervals(object, ...)
Plots of uncertainty intervals computed from posterior draws with all
chains merged.
mcmc_areas(object, ...)
Density plots computed from posterior draws with all chains merged,
with uncertainty intervals shown as shaded areas under the curves.
mcmc_scatter(object, ...)
Bivariate scatterplot of posterior draws. If using a very large number of
posterior draws then mcmc_hex()
may be preferable to avoid
overplotting.
mcmc_hex(object, ...)
Hexagonal heatmap of 2-D bin counts. This plot is useful in cases where
the posterior sample size is large enough that mcmc_scatter()
suffers
from overplotting.
mcmc_pairs(object, ...)
A square plot matrix with univariate marginal distributions along the
diagonal (as histograms or kernel density plots) and bivariate
distributions off the diagonal (as scatterplots or hex heatmaps).
For the off-diagonal plots, the default is to split the chains so that
(roughly) half are displayed above the diagonal and half are below (all
chains are always merged together for the plots along the diagonal). Other
possibilities are available by setting the condition
argument.
mcmc_rhat(object, ...)
, mcmc_rhat_hist(object, ...)
Rhat values as either points or a histogram. Values are colored using
different shades (lighter is better). The chosen thresholds are somewhat
arbitrary, but can be useful guidelines in practice.
light: below 1.05 (good)
mid: between 1.05 and 1.1 (ok)
dark: above 1.1 (too high)
mcmc_neff(object, ...)
, mcmc_neff_hist(object, ...)
Ratios of effective sample size to total sample size as either points or a
histogram. Values are colored using different shades (lighter is better).
The chosen thresholds are somewhat arbitrary, but can be useful guidelines
in practice.
light: between 0.5 and 1 (high)
mid: between 0.1 and 0.5 (good)
dark: below 0.1 (low)
mcmc_acf(object, ...)
, mcmc_acf_bar(object, ...)
Grid of autocorrelation plots by chain and parameter. The lags
argument
gives the maximum number of lags at which to calculate the autocorrelation
function. mcmc_acf()
is a line plot whereas mcmc_acf_bar()
is a
barplot.
Gabry, Jonah and Mahr, Tristan (2019). bayesplot: Plotting for Bayesian Models. https://mc-stan.org/bayesplot/
Gabry, J., Simpson, D., Vehtari, A., Betancourt, M., and Gelman, A (2019). Visualization in Bayesian Workflow. Journal of the Royal Statistical Society: Series A. Vol 182. Issue 2. p.389-402.
Gelman, A. and Rubin, D. (1992) Inference from Iterative Simulation Using Multiple Sequences. Statistical Science 7(4) 457-472.
Gelman, A., et. al. (2013) Bayesian Data Analysis. Chapman and Hall/CRC.
f <- bayesGAM(weight ~ np(height), data = women, family = gaussian, iter=1000, chains = 1) mcmc_trace(f)
f <- bayesGAM(weight ~ np(height), data = women, family = gaussian, iter=1000, chains = 1) mcmc_trace(f)
bayesGAMfit
objectsCreates a correlation plot of the multivariate responses based on corrplot
## S4 method for signature 'bayesGAMfit' mvcorrplot(object, ...)
## S4 method for signature 'bayesGAMfit' mvcorrplot(object, ...)
object |
model object of class |
... |
Additional parameters passed to |
corrplot
object
Taiyun Wei and Viliam Simko (2017). R package corrplot: Visualization of a Correlation Matrix (Version 0.84).
require(MASS) sig <- matrix(c(1, 0.5, 0.5, 1), ncol=2) set.seed(123) Y <- mvrnorm(50, mu=c(-2, 2), Sigma=sig) dat <- data.frame(id = rep(1:5, each=10), y1 = Y[, 1], y2 = Y[, 2]) f <- bayesGAM(cbind(y1, y2) ~ 1, random = ~factor(id), data=dat, a = normal(c(0, 5)), chains = 1, iter = 500) mvcorrplot(f)
require(MASS) sig <- matrix(c(1, 0.5, 0.5, 1), ncol=2) set.seed(123) Y <- mvrnorm(50, mu=c(-2, 2), Sigma=sig) dat <- data.frame(id = rep(1:5, each=10), y1 = Y[, 1], y2 = Y[, 2]) f <- bayesGAM(cbind(y1, y2) ~ 1, random = ~factor(id), data=dat, a = normal(c(0, 5)), chains = 1, iter = 500) mvcorrplot(f)
Used to specify Normal priors for bayesGAM
models
normal(param_values)
normal(param_values)
param_values |
Numeric vector of length 2 for the mean and standard deviation parameters |
For the beta
and a
parameters, the distribution is assumed to be unconstrained.
For eps
and lambda
, the priors are half-normal with a support of strictly positive numbers.
Stan Development Team. 2018. Stan Modeling Language Users Guide and Reference Manual, Version 2.18.0
require(stats); require(graphics) normal(c(0, 10))
require(stats); require(graphics) normal(c(0, 10))
np
accepts one or two numeric vectors of equal length as inputs. From these inputs, univariate or bivariate smoothing design matrices are produced. Currently available basis functions are truncated polynomials and thin plate splines.
When bivariate smoothing is selected, np
calls create_bivariate_design
.
np(x1, x2 = NULL, num_knots = NULL, knots = NULL, basis = "tps", degree = 3)
np(x1, x2 = NULL, num_knots = NULL, knots = NULL, basis = "tps", degree = 3)
x1 |
numeric vector |
x2 |
optional vector for bivariate non-parametric function |
num_knots |
optional number of knots |
knots |
optional numeric vector of knots |
basis |
character vector for basis function. |
degree |
for truncated polynomial basis function |
list with the following elements:
X
parametric design matrix
Z
non-parametric design matrix
knots
numeric vector of knots for the model
Xnms
names of parameters passed to np
basis
selected basis function
degree
degree for truncated polynomial basis function
Ruppert, David, Matt P. Wand, and Raymond J. Carroll. Semiparametric Regression. No. 12. Cambridge university press, 2003. Section 5.6.
Matt Wand (2018). SemiPar: Semiparametric Regression. R package version 1.0-4.2.
x1 <- rnorm(100) res <- np(x1, num_knots=10, basis="trunc.poly", degree=2) res
x1 <- rnorm(100) res <- np(x1, num_knots=10, basis="trunc.poly", degree=2) res
Marginal response smooth plot functions for parametric and nonparametric associations.
## S4 method for signature 'bayesGAMfit,missing' plot(x, y, applylink = TRUE, ...) ## S4 method for signature 'predictPlotObject,missing' plot(x, y, ...) ## S4 method for signature 'posteriorPredictObject,missing' plot(x, y, ...)
## S4 method for signature 'bayesGAMfit,missing' plot(x, y, applylink = TRUE, ...) ## S4 method for signature 'predictPlotObject,missing' plot(x, y, ...) ## S4 method for signature 'posteriorPredictObject,missing' plot(x, y, ...)
x |
an object of class |
y |
unused |
applylink |
logical to indicate whether the inverse link function should be applied to the plots |
... |
optional additional arguments to pass to the |
A list of univariate and bivariate plots generated by plot functions based on ggplot2
H. Wickham. ggplot2: Elegant Graphics for Data Analysis. Springer-Verlag New York, 2016.
f <- bayesGAM(weight ~ np(height), data = women, family = gaussian, iter=500, chains = 1) plot(f)
f <- bayesGAM(weight ~ np(height), data = women, family = gaussian, iter=500, chains = 1) plot(f)
bayesGAM
Draw from the posterior predictive distribution
posterior_predict(object, ...) ## S4 method for signature 'bayesGAMfit' posterior_predict(object, draws = NULL, ...) ## S4 method for signature 'glmModel' posterior_predict(object, draws = NULL, results = NULL, ...)
posterior_predict(object, ...) ## S4 method for signature 'bayesGAMfit' posterior_predict(object, draws = NULL, ...) ## S4 method for signature 'glmModel' posterior_predict(object, draws = NULL, results = NULL, ...)
object |
Object of type |
... |
Additional arguments for |
draws |
An integer indicating the number of draws to return. The default and maximum number of draws is the size of the posterior sample. |
results |
Matrix of HMC posterior samples |
a list of D by N matrices, where D is the number of draws from the posterior predictive distribution and N is the number of data points being predicted per draw.
Goodrich B, Gabry J, Ali I & Brilleman S. (2020). rstanarm: Bayesian applied regression modeling via Stan. R package version 2.19.3 https://mc-stan.org/rstanarm.
Jonah Gabry, Ben Goodrich and Martin Lysy (2020). rstantools: Tools for Developing R Packages Interfacing with 'Stan'. https://mc-stan.org/rstantools/, https://discourse.mc-stan.org/.
f <- bayesGAM(weight ~ np(height), data = women, family = gaussian, iter=1000, chains = 1) res <- posterior_predict(f, draws=100)
f <- bayesGAM(weight ~ np(height), data = women, family = gaussian, iter=1000, chains = 1) res <- posterior_predict(f, draws=100)
bayesplot
packagePlots of Rhat statistics, ratios of effective sample size to total sample size, and autocorrelation of MCMC draws.
ppc_dens(object, ...) ## S4 method for signature 'bayesGAMfit' ppc_dens(object, draws = NULL, ...) ## S4 method for signature 'posteriorPredictObject' ppc_dens(object, ...) ppc_dens_overlay(object, ...) ## S4 method for signature 'bayesGAMfit' ppc_dens_overlay(object, draws = NULL, ...) ## S4 method for signature 'posteriorPredictObject' ppc_dens_overlay(object, ...) ppc_hist(object, ...) ## S4 method for signature 'bayesGAMfit' ppc_hist(object, draws = NULL, ...) ## S4 method for signature 'posteriorPredictObject' ppc_hist(object, ...) ppc_boxplot(object, ...) ## S4 method for signature 'bayesGAMfit' ppc_boxplot(object, draws = NULL, ...) ## S4 method for signature 'posteriorPredictObject' ppc_boxplot(object, ...) ppc_freqpoly(object, ...) ## S4 method for signature 'bayesGAMfit' ppc_freqpoly(object, draws = NULL, ...) ## S4 method for signature 'posteriorPredictObject' ppc_freqpoly(object, ...) ppc_ecdf_overlay(object, ...) ## S4 method for signature 'bayesGAMfit' ppc_ecdf_overlay(object, draws = NULL, ...) ## S4 method for signature 'posteriorPredictObject' ppc_ecdf_overlay(object, ...)
ppc_dens(object, ...) ## S4 method for signature 'bayesGAMfit' ppc_dens(object, draws = NULL, ...) ## S4 method for signature 'posteriorPredictObject' ppc_dens(object, ...) ppc_dens_overlay(object, ...) ## S4 method for signature 'bayesGAMfit' ppc_dens_overlay(object, draws = NULL, ...) ## S4 method for signature 'posteriorPredictObject' ppc_dens_overlay(object, ...) ppc_hist(object, ...) ## S4 method for signature 'bayesGAMfit' ppc_hist(object, draws = NULL, ...) ## S4 method for signature 'posteriorPredictObject' ppc_hist(object, ...) ppc_boxplot(object, ...) ## S4 method for signature 'bayesGAMfit' ppc_boxplot(object, draws = NULL, ...) ## S4 method for signature 'posteriorPredictObject' ppc_boxplot(object, ...) ppc_freqpoly(object, ...) ## S4 method for signature 'bayesGAMfit' ppc_freqpoly(object, draws = NULL, ...) ## S4 method for signature 'posteriorPredictObject' ppc_freqpoly(object, ...) ppc_ecdf_overlay(object, ...) ## S4 method for signature 'bayesGAMfit' ppc_ecdf_overlay(object, draws = NULL, ...) ## S4 method for signature 'posteriorPredictObject' ppc_ecdf_overlay(object, ...)
object |
an object of class |
... |
optional additional arguments to pass to the |
draws |
An integer indicating the number of draws to return. The default and maximum number of draws is the size of the posterior sample. |
These functions call various plotting functions from the bayesplot
package, which returns a list including ggplot2
objects.
bayesplot
package documentationppc_hist(object, draws=NULL, ...)
A separate histogram estimate is displayed for y and each dataset (row) in yrep. For these plots yrep should therefore contain only a small number of rows.
ppc_boxplot(object, draws=NULL, ...)
A separate box and whiskers plot is displayed for y and each dataset (row) in yrep. For these plots yrep should therefore contain only a small number of rows.
ppc_freqpoly(object, draws=NULL, ...)
A separate shaded frequency polygon is displayed for y and each dataset (row) in yrep. For these plots yrep should therefore contain only a small number of rows.
ppc_dens(object, draws=NULL, ...)
A separate smoothed kernel density estimate is displayed for y and each dataset (row) in yrep. For these plots yrep should therefore contain only a small number of rows.
ppc_dens_overlay(object, draws=NULL, ...)
Kernel density estimates of each dataset (row) in yrep
are overlaid, with the distribution of y
itself on top (and in a darker shade).
ppc_ecdf_overlay(object, draws=NULL, ...)
Empirical CDF estimates of each dataset (row) in yrep
are overlaid, with the distribution of y
itself on top (and in a darker shade).
Gabry, Jonah and Mahr, Tristan (2019). bayesplot: Plotting for Bayesian Models. https://mc-stan.org/bayesplot/
Gabry, J., Simpson, D., Vehtari, A., Betancourt, M., and Gelman, A (2019). Visualization in Bayesian Workflow. Journal of the Royal Statistical Society: Series A. Vol 182. Issue 2. p.389-402.
Gelman, A. and Rubin, D. (1992) Inference from Iterative Simulation Using Multiple Sequences. Statistical Science 7(4) 457-472.
Gelman, A., et. al. (2013) Bayesian Data Analysis. Chapman and Hall/CRC.
Gabry, J. , Simpson, D. , Vehtari, A. , Betancourt, M. and Gelman, A. (2019), Visualization in Bayesian workflow. J. R. Stat. Soc. A, 182: 389-402. doi:10.1111/rssa.12378.
f <- bayesGAM(weight ~ np(height), data = women, family = gaussian, iter=500, chains = 1) ppc_dens(f, draws=2)
f <- bayesGAM(weight ~ np(height), data = women, family = gaussian, iter=500, chains = 1) ppc_dens(f, draws=2)
bayesGAM
, but with new dataDraw from the posterior predictive distribution applied to new data
## S4 method for signature 'bayesGAMfit' predict(object, newdata, draws = NULL, ...)
## S4 method for signature 'bayesGAMfit' predict(object, newdata, draws = NULL, ...)
object |
Object of type |
newdata |
A data frame with new data applied to the |
draws |
An integer indicating the number of draws to return. The default and maximum number of draws is the size of the posterior sample. |
... |
Additional arguments for |
a list of D by N matrices, where D is the number of draws from the posterior predictive distribution and N is the number of data points being predicted per draw.
Goodrich B, Gabry J, Ali I & Brilleman S. (2020). rstanarm: Bayesian applied regression modeling via Stan. R package version 2.19.3 https://mc-stan.org/rstanarm.
Jonah Gabry, Ben Goodrich and Martin Lysy (2020). rstantools: Tools for Developing R Packages Interfacing with 'Stan'. https://mc-stan.org/rstantools/, https://discourse.mc-stan.org/.
set.seed(432) f <- bayesGAM(weight ~ np(height), data = women, family = gaussian, iter=500, chains = 1) newheights <- with(women, rnorm(10, mean = mean(height)), sd=sd(height)) women2 <- data.frame(height=newheights) pred <- predict(f, women2, draws=100)
set.seed(432) f <- bayesGAM(weight ~ np(height), data = women, family = gaussian, iter=500, chains = 1) newheights <- with(women, rnorm(10, mean = mean(height)), sd=sd(height)) women2 <- data.frame(height=newheights) pred <- predict(f, women2, draws=100)
Data from 68 subjects
reef
reef
A data frame with 269 rows and 14 variables:
Management zone
Name of the habitat site
habitat benthic complexity
a measurement related to terrain complexity
cover of low complexity
cover of high complexity
PCA score 1 from Wilson, Graham, Polunin
PCA score 2 from Wilson, Graham, Polunin
indicator of race white
fish species
fish abundance
fish biomass
Data from supplementary material provided for Fisher, R., Wilson, S. K., Sin, T. M., Lee, A. C., and Langlois, T. J. (2018). A simple function for full-subsets multiple regression in ecology with R. Ecology and evolution, 8(12), 6104-6113.
Wilson, S. K., Graham, N. A. J., and Polunin, N. V. (2007). Appraisal of visual assessments of habitat complexity and benthic composition on coral reefs. Marine Biology, 151(3), 1069-1076.
bayesGAM
Prints a list of priors for ,
,
, and
, where applicable.
showPrior(object, ...) ## S4 method for signature 'bayesGAMfit' showPrior(object, params = "all")
showPrior(object, ...) ## S4 method for signature 'bayesGAMfit' showPrior(object, params = "all")
object |
Object of type |
... |
Additional arguments for |
params |
character vector of the names of parameters to return
|
none
require(stats); require(graphics) f <- bayesGAM(weight ~ np(height), data = women, family = gaussian, iter = 500, chains = 1) showPrior(f)
require(stats); require(graphics) f <- bayesGAM(weight ~ np(height), data = women, family = gaussian, iter = 500, chains = 1) showPrior(f)
Used to specify student-t priors for bayesGAM
models
st(param_values)
st(param_values)
param_values |
Numeric vector of length 3 for the degrees of freedom, location, and scale parameter. |
For the beta
and a
parameters, the distribution is assumed to be unconstrained.
For eps
and lambda
, the priors are half-normal with a support of strictly positive numbers.
Stan Development Team. 2018. Stan Modeling Language Users Guide and Reference Manual, Version 2.18.0
require(stats); require(graphics) st(c(3,0,1))
require(stats); require(graphics) st(c(3,0,1))
bayesGAM
summary method for class bayesGAMfit
## S4 method for signature 'bayesGAMfit' summary(object)
## S4 method for signature 'bayesGAMfit' summary(object)
object |
an object of class |
Returns a matrix with posterior quantiles and the posterior scale reduction factor statistic for each parameter.
Stan Development Team (2020). RStan: the R interface to Stan. R package version 2.21.1.
f <- bayesGAM(weight ~ np(height), data = women, family = gaussian, iter=500, chains = 1) summary(f)
f <- bayesGAM(weight ~ np(height), data = women, family = gaussian, iter=500, chains = 1) summary(f)
loo
package to calculate the widely applicable information criterion (WAIC)Computes WAIC by calling the appropriate function from the loo
package
waic_bgam(object, ...) ## S4 method for signature 'bayesGAMfit' waic_bgam(object, ...) ## S4 method for signature 'array' waic_bgam(object, ...)
waic_bgam(object, ...) ## S4 method for signature 'bayesGAMfit' waic_bgam(object, ...) ## S4 method for signature 'array' waic_bgam(object, ...)
object |
Object of type |
... |
Additional parameters to pass to pass to |
a named list of class c("waic", "loo")
estimates
A matrix with two columns ("Estimate"
, "SE"
) and three
rows ("elpd_waic"
, "p_waic"
, "waic"
). This contains
point estimates and standard errors of the expected log pointwise predictive
density (elpd_waic
), the effective number of parameters
(p_waic
) and the information criterion waic
(which is just
-2 * elpd_waic
, i.e., converted to deviance scale).
pointwise
A matrix with three columns (and number of rows equal to the number of
observations) containing the pointwise contributions of each of the above
measures (elpd_waic
, p_waic
, waic
).
Watanabe, S. (2010). Asymptotic equivalence of Bayes cross validation and widely application information criterion in singular learning theory. Journal of Machine Learning Research 11, 3571-3594.
Vehtari, A., Gelman, A., and Gabry, J. (2017a). Practical Bayesian model evaluation using leave-one-out cross-validation and WAIC. Statistics and Computing. 27(5), 1413–1432. doi:10.1007/s11222-016-9696-4 (journal version, preprint arXiv:1507.04544).
Vehtari, A., Gelman, A., and Gabry, J. (2017b). Pareto smoothed importance sampling. preprint arXiv:1507.02646
Vehtari A, Gabry J, Magnusson M, Yao Y, Gelman A (2019). “loo: Efficient leave-one-out cross-validation and WAIC for Bayesian models.” R package version 2.2.0, <URL: https://mc-stan.org/loo>.
f <- bayesGAM(weight ~ np(height), data = women, family = gaussian, iter=500, chains = 1) waic_bgam(f)
f <- bayesGAM(weight ~ np(height), data = women, family = gaussian, iter=500, chains = 1) waic_bgam(f)