File: miscEx.rmd

package info (click to toggle)
r-cran-glmmtmb 1.1.5%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 5,504 kB
  • sloc: cpp: 1,018; sh: 16; makefile: 9
file content (47 lines) | stat: -rw-r--r-- 909 bytes parent folder | download | duplicates (4)
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
---
title: "Miscellaneous examples"
date: "`r Sys.Date()`"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{Miscellaneous examples}
  %\VignetteEngine{knitr::rmarkdown}
  \usepackage[utf8]{inputenc}
---

```{r echo=FALSE}
library(glmmTMB)
```

## Beta dispersion model

```{r simbeta1}
set.seed(1001)
N <- 1000
mean_pars <- c(1,2)
disp_pars <- c(1,2)
dd <- data.frame(x=rnorm(N))
m <- plogis(mean_pars[1]+mean_pars[2]*dd$x)
d <- exp(disp_pars[1]+disp_pars[2]*dd$x)
dd$y <- rbeta(N,shape1=m*d,shape2=(1-m)*d)
```

Fit models:

```{r modbeta1}
## location only
m1 <- glmmTMB(y~x,
              family=beta_family(),
              data=dd)
## add model for dispersion
m2 <- update(m1,dispformula=~x)
```

Fixed effects look close to theoretical values:
```{r coefbeta1}
fixef(m2)
```

AIC is insanely much better for the model with dispersion varying:
```{r AICbeta1}
bbmle::AICtab(m1,m2)
```