brms (version 1.4.0)

hypothesis.brmsfit: Non-linear hypothesis testing

Description

Perform non-linear hypothesis testing for all model parameters.

Usage

"hypothesis"(x, hypothesis, class = "b", group = "", alpha = 0.05, seed = 1234, ...)
hypothesis(x, hypothesis, ...)
"print"(x, digits = 2, chars = 20, ...)
"plot"(x, N = 5, ignore_prior = FALSE, chars = 40, colors = NULL, theme = bayesplot::theme_default(), ask = TRUE, plot = TRUE, ...)

Arguments

x
An R object typically of class brmsfit.
hypothesis
A character vector specifying one or more non-linear hypothesis concerning parameters of the model.
class
A string specifying the class of parameters being tested. Default is "b" for population-level effects. Other typical options are "sd" or "cor". If class = NULL, all parameters can be tested against each other, but have to be specified with their full name (see also parnames)
group
Name of a grouping factor to evaluate only group-level effects parameters related to this grouping factor. Ignored if class is not "sd" or "cor".
alpha
The alpha-level of the tests (default is 0.05; see 'Details' for more information).
seed
A single numeric value passed to set.seed to make results reproducible.
...
Currently ignored.
digits
Minimal number of significant digits, see print.default.
chars
Maximum number of characters of each hypothesis to print or plot. If NULL, print the full hypotheses. Defaults to 20.
N
The number of parameters plotted per page.
ignore_prior
A flag indicating if prior distributions should also be plotted. Only used if priors were specified on the relevant parameters.
colors
Two values specifying the colors of the posterior and prior density respectively. If NULL (the default) colors are taken from the current color scheme of the bayesplot package.
theme
A theme object modifying the appearance of the plots. For some basic themes see ggtheme and theme_default.
ask
logical; indicates if the user is prompted before a new page is plotted. Only used if plot is TRUE.
plot
logical; indicates if plots should be plotted directly in the active graphic device. Defaults to TRUE.

Value

Summary statistics of the posterior distributions related to the hypotheses.

Details

Among others, hypothesis computes an evidence ratio (Evid.Ratio) for each hypothesis. For a directed hypothesis, this is just the posterior probability under the hypothesis against its alternative. That is, when the hypothesis if of the form a > b, the evidence ratio is the ratio of the posterior probability of a > b and the posterior probability of a < b. In this example, values greater than one indicate that the evidence in favour of a > b is larger than evidence in favour of a < b. For an undirected (point) hypothesis, the evidence ratio is a Bayes factor between the hypothesis and its alternative computed via the Savage-Dickey density ratio method. That is the posterior density at the point of interest divided by the prior density at that point. Values greater than one indicate that evidence in favour of the point hypothesis has increased after seeing the data. In order to calculate this Bayes factor, all parameters related to the hypothesis must have proper priors and argument sample_prior of function brm must be set to TRUE. When interpreting Bayes factors, make sure that your priors are reasonable and carefully chosen, as the result will depend heavily on the priors. It particular, avoid using default priors. The argument alpha specifies the size of the credible interval (i.e., Bayesian confidence interval). For instance, if alpha = 0.05 (5%), the credible interval will contain 1 - alpha = 0.95 (95%) of the posterior values. Hence, alpha * 100% of the posterior values will lie outside of the credible interval. Although this allows testing of hypotheses in a similar manner as in the frequentist null-hypothesis testing framework, we strongly argue against using arbitrary cutoffs (e.g., p < .05) to determine the 'existence' of an effect.

Examples

Run this code
## Not run: 
# ## define priors
# prior <- c(set_prior("normal(0,2)", class = "b"),
#            set_prior("student_t(10,0,1)", class = "sigma"),
#            set_prior("student_t(10,0,1)", class = "sd"))
# 
# ## fit a linear mixed effects models
# fit <- brm(time ~ age + sex + disease + (1 + age|patient),
#            data = kidney, family = lognormal(),
#            prior = prior, sample_prior = TRUE, 
#            control = list(adapt_delta = 0.95))
# 
# ## perform two-sided hypothesis testing
# (hyp1 <- hypothesis(fit, "sexfemale = age + diseasePKD"))
# plot(hyp1)
# hypothesis(fit, "exp(age) - 3 = 0", alpha = 0.01)
# 
# ## perform one-sided hypothesis testing
# hypothesis(fit, "diseasePKD + diseaseGN - 3 < 0")
# 
# hypothesis(fit, "age < Intercept", 
#            class = "sd", group  = "patient")
# 
# ## test the amount of random intercept variance on all variance
# h <- paste("sd_patient_Intercept^2 / (sd_patient_Intercept^2 +",
#            "sd_patient_age^2 + sigma^2) = 0")
# (hyp2 <- hypothesis(fit, h, class = NULL))
# plot(hyp2)
# 
# ## test more than one hypothesis at once
# (hyp3 <- hypothesis(fit, c("diseaseGN = diseaseAN", 
#                            "2 * diseaseGN - diseasePKD = 0")))
# plot(hyp3, ignore_prior = TRUE)
# ## End(Not run)

Run the code above in your browser using DataLab