Skip to content

Commit e0ec7e8

Browse files
Merge pull request paul-buerkner#245 from paul-buerkner/feature-issue-240
Feature issue 240
2 parents a5df805 + 3d989b8 commit e0ec7e8

30 files changed

+1247
-509
lines changed

DESCRIPTION

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Package: brms
22
Encoding: UTF-8
33
Type: Package
44
Title: Bayesian Regression Models using Stan
5-
Version: 1.8.0
5+
Version: 1.8.0.1
66
Date: 2017-07-19
77
Authors@R: person("Paul-Christian", "Bürkner", email = "[email protected]",
88
role = c("aut", "cre"))
@@ -19,6 +19,7 @@ Imports:
1919
rstantools (>= 1.2.0),
2020
bayesplot (>= 1.2.0),
2121
matrixStats,
22+
bridgesampling,
2223
nlme,
2324
coda,
2425
abind,

NAMESPACE

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ S3method(as.mcmc,brmsfit)
1414
S3method(auxpar_family,default)
1515
S3method(auxpar_family,mixfamily)
1616
S3method(bayes_R2,brmsfit)
17+
S3method(bayes_factor,brmsfit)
18+
S3method(bridge_sampler,brmsfit)
1719
S3method(c,brmsprior)
1820
S3method(change_effects,btl)
1921
S3method(check_prior_special,brmsterms)
@@ -74,6 +76,7 @@ S3method(parnames,default)
7476
S3method(plot,brmsMarginalEffects)
7577
S3method(plot,brmsfit)
7678
S3method(plot,brmshypothesis)
79+
S3method(post_prob,brmsfit)
7780
S3method(posterior_predict,brmsfit)
7881
S3method(posterior_samples,brmsfit)
7982
S3method(posterior_samples,default)
@@ -123,6 +126,7 @@ S3method(valid_auxpars,default)
123126
S3method(valid_auxpars,mixfamily)
124127
S3method(vcov,brmsfit)
125128
S3method(waic,brmsfit)
129+
export("add_ic<-")
126130
export(Beta)
127131
export(LOO)
128132
export(VarCorr)
@@ -134,8 +138,10 @@ export(add_waic)
134138
export(as.mcmc)
135139
export(asym_laplace)
136140
export(bayes_R2)
141+
export(bayes_factor)
137142
export(bernoulli)
138143
export(bf)
144+
export(bridge_sampler)
139145
export(brm)
140146
export(brmdata)
141147
export(brmsfamily)
@@ -235,6 +241,7 @@ export(pexgaussian)
235241
export(pfrechet)
236242
export(pgen_extreme_value)
237243
export(pinv_gaussian)
244+
export(post_prob)
238245
export(posterior.samples)
239246
export(posterior_predict)
240247
export(posterior_samples)
@@ -304,6 +311,8 @@ importFrom(bayesplot,neff_ratio)
304311
importFrom(bayesplot,nuts_params)
305312
importFrom(bayesplot,pp_check)
306313
importFrom(bayesplot,rhat)
314+
importFrom(bridgesampling,bridge_sampler)
315+
importFrom(bridgesampling,post_prob)
307316
importFrom(coda,as.mcmc)
308317
importFrom(grDevices,devAskNewPage)
309318
importFrom(loo,loo)

R/brm.R

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,11 @@
8989
#' \code{predict} with the noise-free variables but
9090
#' leads to very large \R objects even for models
9191
#' of moderate size and complexity.
92+
#' @param save_all_pars A flag to indicate if samples from
93+
#' all variables defined in Stan's \code{parameters} block
94+
#' should be saved (default is \code{FALSE}). Saving these samples
95+
#' is required in order to apply the methods \code{bridge_sampler},
96+
#' \code{bayes_factor}, and \code{post_prob}.
9297
#' @param sample_prior Indicate if samples from all specified
9398
#' proper priors should be drawn additionally to the posterior samples
9499
#' (defaults to \code{"no"}). Among others, these samples can be used
@@ -342,11 +347,12 @@
342347
brm <- function(formula, data, family = gaussian(), prior = NULL,
343348
autocor = NULL, nonlinear = NULL,
344349
threshold = c("flexible", "equidistant"),
345-
cov_ranef = NULL, save_ranef = TRUE, save_mevars = FALSE,
346-
sparse = FALSE, sample_prior = c("no", "yes", "only"),
347-
knots = NULL, stan_funs = NULL, fit = NA, inits = "random",
348-
chains = 4, iter = 2000, warmup = floor(iter / 2),
349-
thin = 1, cores = getOption("mc.cores", 1L), control = NULL,
350+
cov_ranef = NULL, sample_prior = c("no", "yes", "only"),
351+
sparse = FALSE, knots = NULL, stan_funs = NULL,
352+
fit = NA, save_ranef = TRUE, save_mevars = FALSE,
353+
save_all_pars = FALSE, inits = "random", chains = 4,
354+
iter = 2000, warmup = floor(iter / 2), thin = 1,
355+
cores = getOption("mc.cores", 1L), control = NULL,
350356
algorithm = c("sampling", "meanfield", "fullrank"),
351357
future = getOption("future", FALSE), silent = TRUE,
352358
seed = 12345, save_model = NULL, save_dso = TRUE, ...) {
@@ -410,7 +416,8 @@ brm <- function(formula, data, family = gaussian(), prior = NULL,
410416
x$ranef <- tidy_ranef(bterms, data = x$data)
411417
x$exclude <- exclude_pars(
412418
bterms, data = x$data, ranef = x$ranef,
413-
save_ranef = save_ranef, save_mevars = save_mevars
419+
save_ranef = save_ranef, save_mevars = save_mevars,
420+
save_all_pars = save_all_pars
414421
)
415422
x$model <- make_stancode(
416423
formula = formula, data = data, family = family,

R/brmsfit-helpers.R

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,17 @@ restructure <- function(x, rstr_summary = FALSE) {
126126
x$ranef$type[x$ranef$type == "mono"] <- "mo"
127127
x$ranef$type[x$ranef$type == "cse"] <- "cs"
128128
}
129+
if (version <= "1.8.0") {
130+
att <- attributes(object$exclude)
131+
if (is.null(att$save_ranef)) {
132+
attr(object$exclude, "save_ranef") <-
133+
any(grepl("^r_", parnames(object))) || !nrow(object$ranef)
134+
}
135+
if (is.null(att$save_mevars)) {
136+
attr(object$exclude, "save_mevars") <-
137+
any(grepl("^Xme_", parnames(object)))
138+
}
139+
}
129140
stan_env <- attributes(x$fit)$.MISC
130141
if (rstr_summary && exists("summary", stan_env)) {
131142
stan_summary <- get("summary", stan_env)

0 commit comments

Comments
 (0)