-
Notifications
You must be signed in to change notification settings - Fork 0
/
marginal_smooths.brmsfit.Rmd
70 lines (60 loc) · 3.45 KB
/
marginal_smooths.brmsfit.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
---
title: "``brms::marginal_smooths.brmsfit``"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(brms)
```
Display Smooth Terms
#### Description
Display smooth s and t2 terms of models fitted with brms.
#### Usage
<pre><code>
## S3 method for class 'brmsfit'
marginal_smooths(x, smooths = NULL,
int_conditions = NULL, probs = c(0.025, 0.975), spaghetti = FALSE,
resolution = 100, too_far = 0, subset = NULL, nsamples = NULL, ...)
marginal_smooths(x, ...)
</code></pre>
#### Arguments
* x An R object usually of class brmsfit.
* smooths Optional character vector of smooth terms to display. If NULL (the default) all
smooth terms are shown.
* int_conditions An optional named list whose elements are numeric vectors of values of the second variables in two-way interactions. At these values, predictions are evaluated.
The names of int_conditions have to match the variable names exactly.
Additionally, the elements of the numeric vectors may be named themselves, in which case their names appear as labels for the conditions in the plots. Instead
of vectors, functions returning vectors may be passed and are applied on the original values of the corresponding variable. If NULL (the default), predictions are evaluated at the mean and at mean + = sd.
* probs The quantiles to be used in the computation of credible intervals (defaults to 2.5 and 97.5 percent quantiles)
* spaghetti Logical. Indicates if predictions should be visualized via spaghetti plots. Only applied for numeric predictors. If TRUE, it is recommended to set argument
* nsamples to a relatively small value (e.g. 100) in order to reduce computation time.
* resolution Number of support points used to generate the plots. Higher resolution leads to smoother plots. Defaults to 100. If surface is TRUE, this implies 10000 support points for interaction terms, so it might be necessary to reduce resolution when only few RAM is available.
* too_far Positive number. For surface plots only: Grid points that are too far away from the actual data points can be excluded from the plot. too_far determines what is too far. The grid is scaled into the unit square and then grid points more than
* too_far from the predictor variables are excluded. By default, all grid points are used. Ignored for non-surface plots.
subset A numeric vector specifying the posterior samples to be used. If NULL (the default), all samples are used.
* nsamples Positive integer indicating how many posterior samples should be used. If NULL (the default) all samples are used. Ignored if subset is not NULL.
* ... Currently ignored.
#### Examples
```{r}`
## Not run:
set.seed(0)
dat <- mgcv::gamSim(1, n = 200, scale = 2)
fit <- brm(y ~ s(x0) + s(x1) + s(x2) + s(x3), data = dat)
# show all smooth terms
plot(marginal_smooths(fit), rug = TRUE, ask = FALSE)
# show only the smooth term s(x2)
plot(marginal_smooths(fit, smooths = "s(x2)"), ask = FALSE)
```
```{r}
# fit and plot a two-dimensional smooth term
fit2 <- brm(y ~ t2(x0, x2), data = dat)
ms <- marginal_smooths(fit2)
plot(ms, stype = "contour")
plot(ms, stype = "raster")
## End(Not run)
```
#### Details
Two-dimensional smooth terms will be visualized using either contour or raster plots.
#### Value
For the brmsfit method, an object of class brmsMarginalEffects. See marginal_effects for more details and documentation of the related plotting function.
me