File: tab_bayes.Rmd

package info (click to toggle)
r-cran-sjplot 2.8.17%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,596 kB
  • sloc: sh: 13; makefile: 2
file content (102 lines) | stat: -rw-r--r-- 3,169 bytes parent folder | download | duplicates (2)
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
---
title: "Summary of Bayesian Models as HTML Table"
author: "Daniel Lüdecke"
date: "`r Sys.Date()`"
output: rmarkdown::html_vignette
params:
    EVAL: !r identical(Sys.getenv("NOT_CRAN"), "true")
---

<!--
vignette: >
  %\VignetteIndexEntry{Summary of Bayesian Models as HTML Table}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
-->

```{r echo = FALSE}
knitr::opts_chunk$set(
  collapse = TRUE, 
  comment = "#>", 
  message = FALSE
)

m1 <- m2 <- NULL

if (!requireNamespace("insight", quietly = TRUE) ||
    !requireNamespace("httr", quietly = TRUE) ||
    !requireNamespace("brms", quietly = TRUE)) {
  knitr::opts_chunk$set(eval = FALSE)
} else {
  knitr::opts_chunk$set(eval = TRUE)
  library(insight)
  library(httr)
  library(sjPlot)
  library(brms)
  m1 <- tryCatch(insight::download_model("brms_zi_2"), error = function(e) NULL)
  m2 <- tryCatch(insight::download_model("brms_mv_3"), error = function(e) NULL)
}

if (is.null(m1) || is.null(m2)) {
  knitr::opts_chunk$set(eval = FALSE)
}
```

This vignette shows examples for using `tab_model()` to create HTML tables for mixed models. Basically, `tab_model()` behaves in a very similar way for mixed models as for other, simple regression models, as shown [in this vignette](tab_model_estimates.html).

```{r, results='hide', message=FALSE, warning=FALSE, eval=FALSE}
# load required packages
library(sjPlot)
library(brms)

# sample models
zinb <- read.csv("http://stats.idre.ucla.edu/stat/data/fish.csv")
set.seed(123)
m1 <- brm(bf(
    count ~ persons + child + camper + (1 | persons),
    zi ~ child + camper + (1 | persons)
  ),
  data = zinb,
  family = zero_inflated_poisson()
)

data(epilepsy)
set.seed(123)
epilepsy$visit <- as.numeric(epilepsy$visit)
epilepsy$Base2 <- sample(epilepsy$Base, nrow(epilepsy), replace = TRUE)
f1 <- bf(Base ~ zAge + count + (1 |ID| patient))
f2 <- bf(Base2 ~ zAge + Trt + (1 |ID| patient))
m2 <- brm(f1 + f2 + set_rescor(FALSE), data = epilepsy)
```

## Bayesian models summaries as HTML table

For Bayesian regression models, some of the differences to the table output from [simple models](tab_model_estimates.html) or [mixed models](tab_mixed.html) of `tab_models()` are the use of _Highest Density Intervals_ instead of confidence intervals, the Bayes-R-squared values, and a different "point estimate" (which is, by default, the median from the posterior draws).

```{r}
tab_model(m1)
``` 

## Multivariate response models

For multivariate response models, like mediator-analysis-models, it is recommended to print just one model in the table, as each regression is displayed as own "model" in the output.

```{r}
tab_model(m2)
``` 

## Show two Credible Interval-column

To show a second CI-column, use `show.ci50 = TRUE`.

```{r}
tab_model(m2, show.ci50 = TRUE)
``` 

## Mixing multivariate and univariate response models

When both multivariate and univariate response models are displayed in one table, a column _Response_ is added for the multivariate response model, to indicate the different outcomes.

```{r}
tab_model(m1, m2)
```